-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
msvc: handle flags that come from native-static-libs #511
Merged
jschwe
merged 3 commits into
corrosion-rs:master
from
russelltg:allow_flags_in_native_link
Apr 26, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,7 +133,7 @@ function(_corrosion_parse_target_triple target_triple out_arch out_vendor out_os | |
set("${out_env}" "${CMAKE_MATCH_6}" PARENT_SCOPE) | ||
endfunction() | ||
|
||
function(_corrosion_determine_libs_new target_triple out_libs) | ||
function(_corrosion_determine_libs_new target_triple out_libs out_flags) | ||
set(package_dir "${CMAKE_BINARY_DIR}/corrosion/required_libs") | ||
# Cleanup on reconfigure to get a cleans state (in case we change something in the future) | ||
file(REMOVE_RECURSE "${package_dir}") | ||
|
@@ -162,6 +162,7 @@ function(_corrosion_determine_libs_new target_triple out_libs) | |
if(cargo_build_error_message MATCHES "native-static-libs: ([^\r\n]+)\r?\n") | ||
string(REPLACE " " ";" "libs_list" "${CMAKE_MATCH_1}") | ||
set(stripped_lib_list "") | ||
set(flag_list "") | ||
|
||
set(was_last_framework OFF) | ||
foreach(lib ${libs_list}) | ||
|
@@ -175,10 +176,16 @@ function(_corrosion_determine_libs_new target_triple out_libs) | |
set(was_last_framework OFF) | ||
continue() | ||
endif() | ||
# Strip leading `-l` (unix) and potential .lib suffix (windows) | ||
string(REGEX REPLACE "^-l" "" "stripped_lib" "${lib}") | ||
string(REGEX REPLACE "\.lib$" "" "stripped_lib" "${stripped_lib}") | ||
list(APPEND stripped_lib_list "${stripped_lib}") | ||
|
||
# Flags start with / for MSVC | ||
if (lib MATCHES "^/" AND ${target_triple} MATCHES "msvc$") | ||
list(APPEND flag_list "${lib}") | ||
else() | ||
# Strip leading `-l` (unix) and potential .lib suffix (windows) | ||
string(REGEX REPLACE "^-l" "" "stripped_lib" "${lib}") | ||
string(REGEX REPLACE "\.lib$" "" "stripped_lib" "${stripped_lib}") | ||
list(APPEND stripped_lib_list "${stripped_lib}") | ||
endif() | ||
endforeach() | ||
set(libs_list "${stripped_lib_list}") | ||
# Special case `msvcrt` to link with the debug version in Debug mode. | ||
|
@@ -190,6 +197,7 @@ function(_corrosion_determine_libs_new target_triple out_libs) | |
endif() | ||
endif() | ||
set("${out_libs}" "${libs_list}" PARENT_SCOPE) | ||
set("${out_flags}" "${flag_list}" PARENT_SCOPE) | ||
endfunction() | ||
|
||
if (NOT "${Rust_TOOLCHAIN}" STREQUAL "$CACHE{Rust_TOOLCHAIN}") | ||
|
@@ -762,28 +770,35 @@ set(Rust_CARGO_HOST_ENV "${rust_host_env}" CACHE INTERNAL "Host environment") | |
if(NOT DEFINED CACHE{Rust_CARGO_TARGET_LINK_NATIVE_LIBS}) | ||
message(STATUS "Determining required link libraries for target ${Rust_CARGO_TARGET_CACHED}") | ||
unset(required_native_libs) | ||
_corrosion_determine_libs_new("${Rust_CARGO_TARGET_CACHED}" required_native_libs) | ||
_corrosion_determine_libs_new("${Rust_CARGO_TARGET_CACHED}" required_native_libs required_link_flags) | ||
if(DEFINED required_native_libs) | ||
message(STATUS "Required static libs for target ${Rust_CARGO_TARGET_CACHED}: ${required_native_libs}" ) | ||
endif() | ||
if(DEFINED required_link_flags) | ||
message(STATUS "Required link flags for target ${Rust_CARGO_TARGET_CACHED}: ${required_link_flags}" ) | ||
endif() | ||
# In very recent corrosion versions it is possible to override the rust compiler version | ||
# per target, so to be totally correct we would need to determine the libraries for | ||
# every installed Rust version, that the user could choose from. | ||
# In practice there aren't likely going to be any major differences, so we just do it once | ||
# for the target and once for the host target (if cross-compiling). | ||
set(Rust_CARGO_TARGET_LINK_NATIVE_LIBS "${required_native_libs}" CACHE INTERNAL | ||
"Required native libraries when linking Rust static libraries") | ||
set(Rust_CARGO_TARGET_LINK_OPTIONS "${required_link_flags}" CACHE INTERNAL | ||
"Required link flags when linking Rust static libraries") | ||
endif() | ||
|
||
if(Rust_CROSSCOMPILING AND NOT DEFINED CACHE{Rust_CARGO_HOST_TARGET_LINK_NATIVE_LIBS}) | ||
message(STATUS "Determining required link libraries for target ${Rust_CARGO_HOST_TARGET_CACHED}") | ||
unset(host_libs) | ||
_corrosion_determine_libs_new("${Rust_CARGO_HOST_TARGET_CACHED}" host_libs) | ||
_corrosion_determine_libs_new("${Rust_CARGO_HOST_TARGET_CACHED}" host_libs host_flags) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that we should add the following message after line 797, similar to lines 777-779 above:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add |
||
if(DEFINED host_libs) | ||
message(STATUS "Required static libs for host target ${Rust_CARGO_HOST_TARGET_CACHED}: ${host_libs}" ) | ||
endif() | ||
set(Rust_CARGO_HOST_TARGET_LINK_NATIVE_LIBS "${host_libs}" CACHE INTERNAL | ||
"Required native libraries when linking Rust static libraries for the host target") | ||
set(Rust_CARGO_HOST_TARGET_LINK_OPTIONS "${host_flags}" CACHE INTERNAL | ||
"Required linker flags when linking Rust static libraries for the host target") | ||
endif() | ||
|
||
# Set the input variables as non-cache variables so that the variables are available after | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add
unset(required_link_flags)
before this line?