Skip to content
Open
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
13 changes: 10 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ fn main() {
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_USE_LIBC");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_RUSTC_DEP_OF_STD");
println!("cargo:rerun-if-env-changed=CARGO_CFG_MIRI");

// Remove the can_compile() probe artifact so OUT_DIR ends up empty.
// The emitted metadata is not byte-reproducible, and a nondeterministic
// OUT_DIR destabilizes the cache keys of some build systems like Bazel.
let _ = std::fs::remove_file(probe_file());
}

fn use_static_assertions() -> bool {
Expand Down Expand Up @@ -231,6 +236,10 @@ fn has_feature(feature: &str) -> bool {
))
}

fn probe_file() -> PathBuf {
PathBuf::from(var("OUT_DIR").unwrap()).join("rustix_test_can_compile")
}

/// Test whether the rustc at `var("RUSTC")` can compile the given code.
fn can_compile<T: AsRef<str>>(test: T) -> bool {
use std::process::Stdio;
Expand All @@ -254,14 +263,12 @@ fn can_compile<T: AsRef<str>>(test: T) -> bool {
std::process::Command::new(rustc)
};

let out_dir = var("OUT_DIR").unwrap();
let out_file = PathBuf::from(out_dir).join("rustix_test_can_compile");
cmd.arg("--crate-type=rlib") // Don't require `main`.
.arg("--emit=metadata") // Do as little as possible but still parse.
.arg("--target")
.arg(target)
.arg("-o")
.arg(out_file)
.arg(probe_file())
.stdout(Stdio::null()); // We don't care about the output (only whether it builds or not)

// If Cargo wants to set RUSTFLAGS, use that.
Expand Down
Loading