Navigation Menu

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

Move crt-static and linking to build script on windows #1227

Closed

Conversation

CarePackage17
Copy link

Seems to fix #1203.

I've tested with a local cdylib depending on libc in both std and no_std mode. Not quite sure about the crt-static case, although libc itself did compile when passing RUSTFLAGS='-C target-feature=+crt-static'.

I'd appreciate someone else testing this to avoid "works on my machine"-issues.

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton
Copy link
Member

Thanks for this! We'll actually need to keep the current #[link] directives for the standard library, but the build script can be used when this is built from crates.io. Otherwise though this looks fine to me

build.rs Outdated Show resolved Hide resolved
build.rs Outdated
@@ -10,6 +10,18 @@ fn main() {
if rustc_minor_version().expect("Failed to get rustc version") >= 30 {
println!("cargo:rustc-cfg=core_cvoid");
}

if cfg!(target_env = "msvc") {
Copy link
Member

@retep998 retep998 Jan 23, 2019

Choose a reason for hiding this comment

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

Doing this based on cfgs is actually wrong because this is for the host triple, while the decision of what to link should be based on the target triple. You'd need to analyze the TARGET environment variable.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I wasn't aware of that. I'll follow up with another commit soon.
What about the cfg below for crt-static, is that ok?
Nvm, just found it at the bottom of this doc.

build.rs Outdated Show resolved Hide resolved
@alexcrichton
Copy link
Member

Looks good to me! r=me with green CI

Copy link
Contributor

@gnzlbg gnzlbg left a comment

Choose a reason for hiding this comment

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

@ArmsOfSorrow I think we should add some tests to the .appveyor.yml to prevent this from breaking in the future. Or is that not easily possible?

@CarePackage17
Copy link
Author

Of course, though I'm not familiar with appveyor and would appreciate some guidance.

@gnzlbg
Copy link
Contributor

gnzlbg commented Mar 5, 2019

@ArmsOfSorrow basically I think we should add a "test-crate" that is #[no_std] and that we attempt to compile and link against lib in #[no_std] mode. I suppose that without this PR that should error on windows, just running that exact same test on appveyor should also reproduce the issue.

That would be just adding a - cargo test -p our-test-crate/Cargo.toml line to the .appveyor.yml, but the hard part is coming up with a way to test that without this PR things break, and with it things work.

@JohnTitor
Copy link
Member

Hey @ArmsOfSorrow, I've tested the code from https://users.rust-lang.org/t/linker-error-when-building-no-std-windows-dll-that-uses-libc/23976 without this PR but I cannot reproduce the linker error. Could you check if it's still an issue? If so, it'd be great if you could provide your environment information and test code.

@CarePackage17
Copy link
Author

Oof, that's quite an old issue. I don't think I got the test code for it anymore.

The goal behind this was to get UWP support IIRC, but that's already been done a few releases ago. I'm not sure if this PR is still relevant.

@JohnTitor
Copy link
Member

Then I'm going to just clone this and the issue as the fix seems unnecessary now. Feel free to reach out if it becomes an issue again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows CRT linking behavior in no_std build
6 participants