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

msvc: handle flags that come from native-static-libs #511

Merged
merged 3 commits into from
Apr 26, 2024

Conversation

russelltg
Copy link
Contributor

@russelltg russelltg commented Apr 26, 2024

As of rust-lang/rust#122268, rust emits /defaultlib:msvcrt in native-static-libs

This ends up in INTERFACE_LINK_LIBRARIES, and then ninja thinks it's a file:

ninja: error: '/defaultlib:msvcrt', needed by 'cpp-exe.exe', missing and no known rule to make it

This check to see if libraries start with a slash, and then assuming that they are a flag, and putting those in INTERFACE_LINK_OPTIONS instead. If there is some better way to detect flags, I'm all for it. We could also have it have anything that starts with - but not start with -l be detected as a flag, but that seems a bit more likely to be disruptive.

I checked commandlines and it does indeed get propaged properly to the commandline.

As of https://github.com/rust-lang/rust/pull/122268/files, rust emits /defaultlib:msvcrt in native-static-libs

This ends up in INTERFACE_LINK_LIBRARIES, and then ninja thinks it's a file:

ninja: error: '/defaultlib:msvcrt', needed by 'cpp-exe.exe', missing and no known rule to make it

This check to see if libraries start with a slash, and then assuming that they are a flag, and putting those in INTERFACE_LINK_OPTIONS instead. If there is some better way to detect flags, I'm all for it. We could also have it have anything that starts with `-` but not start with `-l` be detected as a flag, but that seems a bit more likely to be disruptive.

I checked commandlines and it does indeed get propaged properly to the commandline.
cmake/FindRust.cmake Outdated Show resolved Hide resolved
@jschwe
Copy link
Collaborator

jschwe commented Apr 26, 2024

Could you also add an entry to the changelog in RELEASES.md?

@jschwe jschwe merged commit fce4fe5 into corrosion-rs:master Apr 26, 2024
36 checks passed
@jschwe
Copy link
Collaborator

jschwe commented Apr 26, 2024

thanks!

jschwe pushed a commit to jschwe/corrosion that referenced this pull request May 10, 2024
* msvc: handle flags that come from native-static-libs

As of https://github.com/rust-lang/rust/pull/122268/files, rust emits /defaultlib:msvcrt in native-static-libs

This ends up in INTERFACE_LINK_LIBRARIES, and then ninja thinks it's a file:

ninja: error: '/defaultlib:msvcrt', needed by 'cpp-exe.exe', missing and no known rule to make it

This check to see if libraries start with a slash, and then assuming that they are a flag, and putting those in INTERFACE_LINK_OPTIONS instead.

(cherry picked from commit fce4fe5)
jschwe pushed a commit to jschwe/corrosion that referenced this pull request May 10, 2024
* msvc: handle flags that come from native-static-libs

As of https://github.com/rust-lang/rust/pull/122268/files, rust emits /defaultlib:msvcrt in native-static-libs

This ends up in INTERFACE_LINK_LIBRARIES, and then ninja thinks it's a file:

ninja: error: '/defaultlib:msvcrt', needed by 'cpp-exe.exe', missing and no known rule to make it

This check to see if libraries start with a slash, and then assuming that they are a flag, and putting those in INTERFACE_LINK_OPTIONS instead.

(cherry picked from commit fce4fe5)
jschwe pushed a commit to jschwe/corrosion that referenced this pull request May 11, 2024
* msvc: handle flags that come from native-static-libs

As of https://github.com/rust-lang/rust/pull/122268/files, rust emits /defaultlib:msvcrt in native-static-libs

This ends up in INTERFACE_LINK_LIBRARIES, and then ninja thinks it's a file:

ninja: error: '/defaultlib:msvcrt', needed by 'cpp-exe.exe', missing and no known rule to make it

This check to see if libraries start with a slash, and then assuming that they are a flag, and putting those in INTERFACE_LINK_OPTIONS instead.

(cherry picked from commit fce4fe5)
jschwe pushed a commit that referenced this pull request May 11, 2024
* msvc: handle flags that come from native-static-libs

As of https://github.com/rust-lang/rust/pull/122268/files, rust emits /defaultlib:msvcrt in native-static-libs

This ends up in INTERFACE_LINK_LIBRARIES, and then ninja thinks it's a file:

ninja: error: '/defaultlib:msvcrt', needed by 'cpp-exe.exe', missing and no known rule to make it

This check to see if libraries start with a slash, and then assuming that they are a flag, and putting those in INTERFACE_LINK_OPTIONS instead.

(cherry picked from commit fce4fe5)
wantehchang added a commit to wantehchang/libavif that referenced this pull request Jun 21, 2024
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)

Choose a reason for hiding this comment

The 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:

    if(DEFINED host_flags)
        message(STATUS "Required link flags for host target ${Rust_CARGO_HOST_TARGET_CACHED}: ${host_flags}" )
    endif()

@@ -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)

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?

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add unset(ost_flags) before this line?

wantehchang added a commit to AOMediaCodec/libavif that referenced this pull request Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants