Skip to content

Commit

Permalink
clang,windows: fix passing link flags when using clang in GNU fronten…
Browse files Browse the repository at this point in the history
…d mode on windows (#566)

* clang,windows: fix passing link flags when using clang in GNU frontend mode on windows
* Add a CI job for clang with GNU frontend and msvc ABI.
  • Loading branch information
russelltg authored Oct 8, 2024
1 parent 99304ec commit 3ec73d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
compiler:
- cl
- clang-cl
- clang
include:
- os: windows-2022
vs_version: vs-2022
Expand All @@ -79,6 +80,10 @@ jobs:
arch: i686
- compiler: clang-cl
arch: aarch64
- compiler: clang
arch: i686
- compiler: clang
arch: aarch64

steps:
- uses: actions/checkout@v4
Expand Down
12 changes: 12 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@
"name": "ninja-x86_64-pc-windows-msvc-clang-cl",
"inherits": ["ninja", "x86_64-pc-windows-msvc", "clang-cl"]
},
{
"name": "ninja-x86_64-pc-windows-msvc-clang",
"inherits": ["ninja", "x86_64-pc-windows-msvc", "clang"]
},
{
"name": "ninja-i686-pc-windows-msvc-cl",
"inherits": ["ninja", "i686-pc-windows-msvc", "cl", "windows-10-cross"]
Expand All @@ -208,6 +212,10 @@
"name": "ninja-i686-pc-windows-msvc-clang-cl",
"inherits": ["ninja", "i686-pc-windows-msvc", "clang-cl", "windows-10-cross"]
},
{
"name": "ninja-i686-pc-windows-msvc-clang",
"inherits": ["ninja", "i686-pc-windows-msvc", "clang", "windows-10-cross"]
},
{
"name": "ninja-aarch64-pc-windows-msvc-cl",
"inherits": ["ninja", "aarch64-pc-windows-msvc", "cl", "windows-10-cross"]
Expand All @@ -216,6 +224,10 @@
"name": "ninja-aarch64-pc-windows-msvc-clang-cl",
"inherits": ["ninja", "aarch64-pc-windows-msvc", "clang-cl", "windows-10-cross"]
},
{
"name": "ninja-aarch64-pc-windows-msvc-clang",
"inherits": ["ninja", "aarch64-pc-windows-msvc", "clang", "windows-10-cross"]
},
{
"name": "ninja-x86_64-pc-windows-gnullvm",
"inherits": ["ninja", "windows-only", "clang"],
Expand Down
10 changes: 8 additions & 2 deletions cmake/FindRust.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ function(_corrosion_determine_libs_new target_triple out_libs out_flags)

# Flags start with / for MSVC
if (lib MATCHES "^/" AND ${target_triple} MATCHES "msvc$")
list(APPEND flag_list "${lib}")
# Windows GNU uses the compiler to invoke the linker, so -Wl, prefix is needed
# https://gitlab.kitware.com/cmake/cmake/-/blob/9bed4f4d817f139f0c2e050d7420e1e247949fe4/Modules/Platform/Windows-GNU.cmake#L156
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
list(APPEND flag_list "-Wl,${lib}")
else()
list(APPEND flag_list "${lib}")
endif()
else()
# Strip leading `-l` (unix) and potential .lib suffix (windows)
string(REGEX REPLACE "^-l" "" "stripped_lib" "${lib}")
Expand All @@ -196,7 +202,7 @@ function(_corrosion_determine_libs_new target_triple out_libs out_flags)
# We leave it up to the C/C++ executable that links in the Rust static-library
# to determine which version of the msvc runtime library it should select.
list(FILTER libs_list EXCLUDE REGEX "^msvcrtd?")
list(FILTER flag_list EXCLUDE REGEX "^/defaultlib:msvcrtd?")
list(FILTER flag_list EXCLUDE REGEX "^(-Wl,)?/defaultlib:msvcrtd?")
else()
message(DEBUG "Determining required native libraries - failed: Regex match failure.")
message(DEBUG "`native-static-libs` not found in: `${cargo_build_error_message}`")
Expand Down

0 comments on commit 3ec73d8

Please sign in to comment.