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
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
19 changes: 19 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ fn main() {
if rustc_minor_version().expect("Failed to get rustc version") >= 30 {
println!("cargo:rustc-cfg=core_cvoid");
}

let dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD");

// Windows-specific:
// When this crate is not built as part of std, we explicitly
// need to tell the compiler to link the CRT. This enables
// usage in no_std scenarios.
if dep_of_std.is_err() {
let target = env::var("TARGET").unwrap();
let linkage = env::var("CARGO_CFG_TARGET_FEATURE").unwrap();

if target.contains("msvc") {
if linkage.contains("crt-static") {
println!("cargo:rustc-link-lib=dylib=libcmt");
} else {
println!("cargo:rustc-link-lib=dylib=msvcrt");
}
}
}
}

fn rustc_minor_version() -> Option<u32> {
Expand Down