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
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

@CarePackage17 CarePackage17 Jan 25, 2019

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.

if cfg!(target_feature = "crt-static") {
//weirdly enough, this doesn't work
// println!("cargo:rustc-link-lib=static=libcmt");

//but this does. maybe I'm misunderstanding something with static vs dynamic linking.
gnzlbg marked this conversation as resolved.
Show resolved Hide resolved
println!("cargo:rustc-link-lib=dylib=libcmt");
} else {
println!("cargo:rustc-link-lib=dylib=msvcrt");
}
}
}

fn rustc_minor_version() -> Option<u32> {
Expand Down
6 changes: 3 additions & 3 deletions src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ pub const NSIG: ::c_int = 23;
pub const SIG_ERR: ::c_int = -1;

// inline comment below appeases style checker
#[cfg(all(target_env = "msvc", feature = "rustc-dep-of-std"))] // " if "
#[link(name = "msvcrt", cfg(not(target_feature = "crt-static")))]
#[link(name = "libcmt", cfg(target_feature = "crt-static"))]
//#[cfg(all(target_env = "msvc", feature = "rustc-dep-of-std"))] // " if "
//#[link(name = "msvcrt", cfg(not(target_feature = "crt-static")))]
//#[link(name = "libcmt", cfg(target_feature = "crt-static"))]
extern {}

pub enum FILE {}
Expand Down