From 746523c2b7719c151773644488c0cf68516d1f70 Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Thu, 28 May 2026 23:22:24 -0400 Subject: [PATCH] build: Remove OUT_DIR probe artifact --- build.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/build.rs b/build.rs index 1677ece45..23d9177aa 100644 --- a/build.rs +++ b/build.rs @@ -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 { @@ -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>(test: T) -> bool { use std::process::Stdio; @@ -254,14 +263,12 @@ fn can_compile>(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.