serge-sans-paille / pythran

Ahead of Time compiler for numeric kernels
https://pythran.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.99k stars 192 forks source link

Change default linker to use in pythran.cfg / pythran-win32.cfg on Windows 10... #1972

Open mattslezak-shell opened 2 years ago

mattslezak-shell commented 2 years ago

I posted some updated instructions for Windows 10 users not too long ago, which are in a pull request.

One of the items was changing the default linker, which was quite hacky (modifying setuptools/_distutils/_msvccompiler.py)

Now someone has brought it to my attention that using either cl.exe or link.exe on Windows makes the resulting modules follow the Microsoft licenses, so it requires a Visual Studio commercial license if the Pythran module is used in a commercial application. Now by changing everything to LLVM clang-cl.exe and lld-link.exe you instead have modules built under the Apache 2.0 License, which is allowed in commercial applications.

I don't need this functionality myself since everything I build is for internal use at my current company, but it's something to consider. Whenever you can go from "big corporation licenses" to "open source" well that's never a bad thing, in my opinion. Besides, they make their licenses so hard to follow I could be violating them just by using link.exe at my current company. I'm not an attorney, but I'd rather be safe. So if changing the default linker in the pythran-win32.cfg is easy enough to implement, why not. If it's something I can help with, please point me in the right direction :)

serge-sans-paille commented 2 years ago

is lld-link.exe installed whenever clang-cl.exe is ?

mattslezak-shell commented 2 years ago

If you install LLVM for amd64 it installs both clang-cl.exe and lld-link.exe. Also if you use Microsoft Build Tools to install Clang it comes with both. BUT the way the package dependencies are setup for Pythran on conda-forge, it doesn't include lld so that would have to be added as a dependency if someone wants to use lld-link.exe - I tested it out BTW, and that works too. I.e. conda install lld picks the right linker.

serge-sans-paille commented 2 years ago

Can you share a link to the licensing issue you're mentionning? I'm always a bit reluctant to touch the windows part of clang ;-)

mattslezak-shell commented 2 years ago

It's quite ugly for MSVC but if you use any Visual Studio Tools you're under their license agreement, theoretically. The Build Tools say they are a component of Visual Studio and therefore you must adhere to the normal Visual Studio license requirements. Which means an organization >5 users must buy a Visual Studio license to use the tools if they want to distribute them: https://visualstudio.microsoft.com/license-terms/mt644918/ or here on their forums: https://social.msdn.microsoft.com/Forums/en-US/08d62115-0b51-484f-afda-229989be9263/license-for-visual-c-2017-build-tools?forum=visualstudiogeneral.

If you make it an OPTION to select lld-link.exe then I don't see where you can go wrong. If someone wants to use the lld package from conda, they can point to the installation location and use it instead. Which on an Anaconda installation it just sits in C:\Users\[user_name]\Anaconda3\Library\bin where clang-cl.exe also resides. That's all you have to do to download lld-link.exe. I don't see as easy as a way for someone using pip to install the package, as it looks to be a conda package only. A user can always install the entire LLVM package instead to get everything: https://releases.llvm.org/

OpenMP from Intel (MKL) under the OneAPI license without any support is much friendlier and allows distribution and commercial use. https://www.intel.com/content/www/us/en/developer/articles/license/end-user-license-agreement.html Which the Visual Studio Build Tools do not allow.

Why not just make it easy, if it is easy, to add as a command line option or part of the config file? I suppose a user will know if they have installed lld-link.exe or not.

Again the current "hacking" method is to modify C:\Users\[user_name]\Anaconda3\distutils\_msvccompiler.py and change "link.exe" to "lld-link.exe" then modify the ldflags to exclude LTCG like so: #, '/LTCG' since lld-link.exe does not have that option. I was able to build a project entirely with clang-cl and lld-link without using link.exe or cl.exe. I just installed the lld package - here is the log not touching MSVC (except the required includes), and without running vsvarsall.bat that MSVC requires. The project runs the same as an MSVC compiled one on Windows 10, but no license requirements to watch out for: build_LLVM_windows.txt

mrslezak commented 2 years ago

BTW - not related - but there's no need to install Intel OneAPI MKL on Windows for compatibility with Anaconda Python. It just needs 1 file, uploaded here. libiomp5md.lib - not sure why others haven't posted it, but it's a lot easier to just download one lib file than installing the ~6GB distribution. It just adds Intel OpenMP support... should probably upload to a conda or pip pypi channel. libiomp5md.zip but then again, maybe it all needs to be bundled together per the license... That's why I'd prefer to just config file set lld-link instead of link to avoid MSVC licenses. Which is an easy hack per the above tried again on another laptop and it works just fine... this time my home laptop vs my corporate one... but nonetheless, it works.