meson
meson copied to clipboard
_guess_win_linker fails for clang-cl if lld-link isn't in the path even if explicit linker path provided
Hello
Moving here from #8163...
I've been trying to use msys2's clang-cl with explicit environment variables pointing at my binaries; e.g.:
CC=/c/tools/msys64/mingw64/bin/clang-cl.exe
CXX=/c/tools/msys64/mingw64/bin/clang-cl.exe
C_LD=/c/tools/msys64/mingw64/bin/lld-link.exe
CXX_LD=/c/tools/msys64/mingw64/bin/lld-link.exe
#8105 is required to get the compiler detected correctly; that's fine.
If I don't have either c:/tools/msys64/mingw64/bin/or Visual Studio's clang binaries in the path, then linker detection fails because there is no exception handling in the initial Popen_safe() check (for lld-link.exe) in _guess_win_linker() - the second Popen_safe() using my explicit linker path is never run.
I did a quick workaround lukester1975/meson@cf34d1761608c2d03cdebadce7e6f9cd5c8e5bfe, which just puts a try around that first Popen_safe(). Seems like it should be a pretty safe change, since if the linker isn't overriden the second Popen_safe() will be called with the same args and then throw, but I've only spent a little time looking at it.
Regards
I cannot reproduce this with MSVC 2022 Preview and the Clang/CL binary specified as follows. lld-link is detected on the spot.
$env:CC="C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\Llvm\\x64\\bin\\clang-cl.exe"
Are both this and #8105 still needed?
What's in your PATH though (are you running from a VS environment)? From a non-VS enabled environment with explicit CC/CXX/C_LD/CXX_LD it doesn't work for me - both this and #8105.
Without the #8105 change:
File "C:\Users\luke\AppData\Roaming\Python\Python311\site-packages\mesonbuild\compilers\detect.py", line 533, in _detect_c_or_cpp_compiler
linker = guess_win_linker(env, ['lld-link'], cls, version, for_machine)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\luke\AppData\Roaming\Python\Python311\site-packages\mesonbuild\linkers\detect.py", line 100, in guess_win_linker
p, o, e = Popen_safe(compiler + check_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\luke\AppData\Roaming\Python\Python311\site-packages\mesonbuild\mesonlib\universal.py", line 1409, in Popen_safe
p, o, e = Popen_safe_legacy(args, write=write, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
With #8105 (or an updated version that will apply):
meson.build:1:0: ERROR: Unsupported linker, only bfd, gold, and lld are supported, not C:/tools/msys64/mingw64/bin/lld-link.exe.
The #8105 change seems to be stalled on adding tests. I'd like to help but as a non-python person I can't really, I'm afraid...
What's in your PATH though (are you running from a VS environment)? From a non-VS enabled environment with explicit CC/CXX/C_LD/CXX_LD it doesn't work for me - both this and https://github.com/mesonbuild/meson/pull/8105.
It does is enabling VS Preview environment by default, yes.
Actually I take some of that back, #9361 was a dupe of #8105.
Explicit linker path still broken for me, though.