Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang,windows: fix passing link flags when using clang in GNU frontend mode on windows #566

Merged
merged 8 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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