vcpkg icon indicating copy to clipboard operation
vcpkg copied to clipboard

[community triplet] adds triplets for building with clang/LLVM for Windows

Open walbourn opened this issue 2 years ago • 20 comments

This adds ten (10) new community triplets for building with the clang/LLVM for Windows toolset which is an optional component available in Visual Studio. While MSVC and clang/LLVM for Windows are in general link compatible, some developers would prefer to avoid relying on the MSVC compiler.

These four triplets are for building Windows platform targets:

arm64-clangcl-dynamic
arm64-clangcl-static
x64-clangcl-dynamic
x64-clangcl-static

These four triplets are for building Xbox platform targets:

x64-clangcl-scarlett-static
x64-clangcl-scarlett
x64-clangcl-xboxone-static
x64-clangcl-xboxone

These two triplets are for building UWP platform targets:

x64-clangcl-uwp
arm64-clangcl-uwp

Note that clang-cl does not support the (now deprecated) C++/CX language extensions (/ZW, /FU, /AI, /WINMD). This toolset is fully supported by the new C++/WinRT language projections.

These triplets should also improve the conformance testing for libraries in VCPKG.

walbourn avatar Apr 21 '23 18:04 walbourn

https://github.com/microsoft/vcpkg/pull/29034#issuecomment-1405686024

(try building python3 with these triplets)

Neumann-A avatar Apr 21 '23 18:04 Neumann-A

(try building python3 with these triplets)

I'm currently building ALL ports with the x64-clangcl-dynamic triplet. I'll post the results back when its done.

walbourn avatar Apr 21 '23 19:04 walbourn

https://github.com/microsoft/vcpkg/pull/25897

waiting for #28773 and #27694

Neumann-A avatar Apr 21 '23 19:04 Neumann-A

#25897

waiting for #28773 and #27694

My proposal here is to only support clang/LLVM for Windows using the MSVC-like clang-cl.exe front end. The numerous patches you have applied in that PR look like they are for using clang.exe directly which is not as well supported a scenario from the Visual Studio experience.

The 'pure LLVM' implementation looks a lot more complicated. Why all the overrides when CMake already supports this scenario pretty well?

walbourn avatar Apr 21 '23 19:04 walbourn

My proposal here is to only support clang/LLVM for Windows using the MSVC-like clang-cl.exe front end.

The true home of that triplet is https://github.com/Neumann-A/my-vcpkg-triplets/blob/master/x64-win-llvm.cmake

The numerous patches you have applied in that PR

No that is clang-cl and most of the patches have been merged. (as said i am waiting for two prs to be merged before updating that PR.)

Why all the overrides when CMake already supports this scenario pretty well?

The problem are library authors not correctly supporting it. Checking e.g. CMAKE_<LANG>_COMPILER_ID for msvc or clang and not thinking about clang-cl.

Neumann-A avatar Apr 21 '23 19:04 Neumann-A

Trying 2130 ports, 1445 successfully built without changes using the new x64-clangcl-dynamic triplet. I'll look into the 685 failures more tomorrow (although about a 100 of them fail because they don't support windows).

walbourn avatar Apr 23 '23 08:04 walbourn

Looking into the failures, there's a few cases here:

  • Obvious conformance issues as found by @Neumann-A in their testing work.
  • Upstream CMakes that failed to check for "MSVC-Like" when using Clang
  • Reliance on 'over-inclusion' in headers in some cases that can be fixed with additional header includes.
  • For boost, there's an issue where CMAKE_AR is being used without quotes when invoked which fails because the llvm-lib tool path is under `C:\Program Files``.

walbourn avatar Apr 23 '23 19:04 walbourn

The boost failures are due to a 'b2' bug filed here.

walbourn avatar Apr 23 '23 19:04 walbourn

About 290 of the 685 port failures are directly related to the boost problem which is a bug in b2 build.

With the additional changes from code review, I'm able to build 30 additional ports out of the 685.

walbourn avatar Apr 25 '23 01:04 walbourn

Tried another full pass of all current ports with the latest version of the triplet.

1424 out of 2194 ports build ok. That leaves 770 failures (with ~100 being non-Windows ports).

21 additional ports will build with a workaround for the 'spaces in path name' for the CMAKE_AR library tool variable. There's no good way to do this directly in the vcpkg toolchains at the moment, so I'm leaving this workaround out for now. Hopefully we can get it fixed directly in b2, or we can find a robust way to do GetShortPathName with CMake directly in future.

walbourn avatar Apr 26 '23 03:04 walbourn

Draft documentation https://github.com/microsoft/vcpkg-docs/pull/76

walbourn avatar Apr 28 '23 06:04 walbourn

I cannot reproduce the x64-windows or x86-windows failure with gz-math7 locally. I've tried rebasing a few times and it doesn't seem to change anything.

LINK : fatal error LNK1104: cannot open file 'python310.lib'

Any idea what's different here?

walbourn avatar May 06 '23 18:05 walbourn

LINK : fatal error LNK1104: cannot open file 'python310.lib'

if this is in a debug build somebody is doing a #undef _DEBUG

Neumann-A avatar May 06 '23 18:05 Neumann-A

I cannot reproduce the x64-windows or x86-windows failure with gz-math7 locally.

gz-math7 picks undeclared dependencies, causing baseline regressions. #31277.

dg0yt avatar May 07 '23 16:05 dg0yt

I cannot reproduce the x64-windows or x86-windows failure with gz-math7 locally.

gz-math7 picks undeclared dependencies, causing baseline regressions. #31277.

Thanks. Rebased with this fix.

walbourn avatar May 09 '23 23:05 walbourn

Split the toolchain edits out to individual PRs, so this PR is now on hold.

walbourn avatar May 13 '23 18:05 walbourn

related https://github.com/llvm/llvm-project/issues/53520

Neumann-A avatar Jun 24 '23 10:06 Neumann-A

@walbourn , Could you help to test install boost-filesystem I encountered an error when build with x64-clangcl-static:

error: Unable to find file or target named
error:     '/boost//C:/Users/xxx/debug/lib/boost_atomicd.lib'
error: referred to from project at
error:

I have tried to build boost from source and I found boost renamed the lib like below:

$ ls stage/lib/ | grep atomi
libboost_atomic-clangw17-mt-gd-x32-1_83.lib
libboost_atomic-clangw17-mt-gd-x64-1_83.lib

haydenzhourepo avatar Jan 17 '24 04:01 haydenzhourepo

after investigating, i found a solution: image

add this patch will resolve the boost build failed problem.

haydenzhourepo avatar Jan 22 '24 03:01 haydenzhourepo

So much work here, it is impressive! Good luck with everything 👍

abique avatar Jan 30 '24 14:01 abique

After merging the latest changes, the try-compile tests for these new triplets pass:

.\vcpkg.exe install try-compile:arm64-clangcl-dynamic --overlay-ports scripts\test_ports --enforce-port-checks
.\vcpkg.exe install try-compile:arm64-clangcl-static --overlay-ports scripts\test_ports --enforce-port-checks
.\vcpkg.exe install try-compile:x64-clangcl-dynamic --overlay-ports scripts\test_ports --enforce-port-checks
.\vcpkg.exe install try-compile:x64-clangcl-static --overlay-ports scripts\test_ports --enforce-port-checks

.\vcpkg.exe install try-compile:x64-clangcl-scarlett-static --overlay-ports scripts\test_ports --enforce-port-checks
.\vcpkg.exe install try-compile:x64-clangcl-scarlett --overlay-ports scripts\test_ports --enforce-port-checks
.\vcpkg.exe install try-compile:x64-clangcl-xboxone-static --overlay-ports scripts\test_ports --enforce-port-checks
.\vcpkg.exe install try-compile:x64-clangcl-xboxone --overlay-ports scripts\test_ports --enforce-port-checks

 .\vcpkg.exe install try-compile:arm64-clangcl-uwp --overlay-ports scripts\test_ports --enforce-port-checks
 .\vcpkg.exe install try-compile:x64-clangcl-uwp --overlay-ports scripts\test_ports --enforce-port-checks

walbourn avatar Jul 11 '24 21:07 walbourn