From 0e55fc847224e7581fef6c5234fc8b5f88a8b5f9 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 21 Nov 2024 16:48:39 -0800 Subject: [PATCH] Don't store build check rmeta This ensures the `.rmeta` files generated by `can_compile` are not written to the build output. Those metadata files can create determinism and cache invalidation issues in some build systems. Instead the output -- since it is never actually read -- is written to `/dev/null`. This is a port of bytecodealliance/rustix#1200 to cap-std. --- build.rs | 6 +++--- cap-async-std/build.rs | 6 +++--- cap-fs-ext/build.rs | 6 +++--- cap-primitives/build.rs | 6 +++--- cap-std/build.rs | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/build.rs b/build.rs index 1e6e41c5..65ce304d 100644 --- a/build.rs +++ b/build.rs @@ -48,7 +48,6 @@ fn has_feature(feature: &str) -> bool { fn can_compile>(test: T) -> bool { use std::process::Stdio; - let out_dir = var("OUT_DIR").unwrap(); let rustc = var("RUSTC").unwrap(); let target = var("TARGET").unwrap(); @@ -72,8 +71,9 @@ fn can_compile>(test: T) -> bool { .arg("--emit=metadata") // Do as little as possible but still parse. .arg("--target") .arg(target) - .arg("--out-dir") - .arg(out_dir); // Put the output somewhere inconsequential. + .arg("-o") + .arg("-") + .stdout(Stdio::null()); // We don't care about the output (only whether it builds or not) // If Cargo wants to set RUSTFLAGS, use that. if let Ok(rustflags) = var("CARGO_ENCODED_RUSTFLAGS") { diff --git a/cap-async-std/build.rs b/cap-async-std/build.rs index 3706ce13..434559ec 100644 --- a/cap-async-std/build.rs +++ b/cap-async-std/build.rs @@ -35,7 +35,6 @@ fn has_feature(feature: &str) -> bool { fn can_compile>(test: T) -> bool { use std::process::Stdio; - let out_dir = var("OUT_DIR").unwrap(); let rustc = var("RUSTC").unwrap(); let target = var("TARGET").unwrap(); @@ -59,8 +58,9 @@ fn can_compile>(test: T) -> bool { .arg("--emit=metadata") // Do as little as possible but still parse. .arg("--target") .arg(target) - .arg("--out-dir") - .arg(out_dir); // Put the output somewhere inconsequential. + .arg("-o") + .arg("-") + .stdout(Stdio::null()); // We don't care about the output (only whether it builds or not) // If Cargo wants to set RUSTFLAGS, use that. if let Ok(rustflags) = var("CARGO_ENCODED_RUSTFLAGS") { diff --git a/cap-fs-ext/build.rs b/cap-fs-ext/build.rs index b8ccb4dd..1716d753 100644 --- a/cap-fs-ext/build.rs +++ b/cap-fs-ext/build.rs @@ -32,7 +32,6 @@ fn has_feature(feature: &str) -> bool { fn can_compile>(test: T) -> bool { use std::process::Stdio; - let out_dir = var("OUT_DIR").unwrap(); let rustc = var("RUSTC").unwrap(); let target = var("TARGET").unwrap(); @@ -56,8 +55,9 @@ fn can_compile>(test: T) -> bool { .arg("--emit=metadata") // Do as little as possible but still parse. .arg("--target") .arg(target) - .arg("--out-dir") - .arg(out_dir); // Put the output somewhere inconsequential. + .arg("-o") + .arg("-") + .stdout(Stdio::null()); // We don't care about the output (only whether it builds or not) // If Cargo wants to set RUSTFLAGS, use that. if let Ok(rustflags) = var("CARGO_ENCODED_RUSTFLAGS") { diff --git a/cap-primitives/build.rs b/cap-primitives/build.rs index b92c0bce..8bab65a3 100644 --- a/cap-primitives/build.rs +++ b/cap-primitives/build.rs @@ -42,7 +42,6 @@ fn has_feature(feature: &str) -> bool { fn can_compile>(test: T) -> bool { use std::process::Stdio; - let out_dir = var("OUT_DIR").unwrap(); let rustc = var("RUSTC").unwrap(); let target = var("TARGET").unwrap(); @@ -66,8 +65,9 @@ fn can_compile>(test: T) -> bool { .arg("--emit=metadata") // Do as little as possible but still parse. .arg("--target") .arg(target) - .arg("--out-dir") - .arg(out_dir); // Put the output somewhere inconsequential. + .arg("-o") + .arg("-") + .stdout(Stdio::null()); // We don't care about the output (only whether it builds or not) // If Cargo wants to set RUSTFLAGS, use that. if let Ok(rustflags) = var("CARGO_ENCODED_RUSTFLAGS") { diff --git a/cap-std/build.rs b/cap-std/build.rs index 0004c698..f3afe13c 100644 --- a/cap-std/build.rs +++ b/cap-std/build.rs @@ -37,7 +37,6 @@ fn has_feature(feature: &str) -> bool { fn can_compile>(test: T) -> bool { use std::process::Stdio; - let out_dir = var("OUT_DIR").unwrap(); let rustc = var("RUSTC").unwrap(); let target = var("TARGET").unwrap(); @@ -61,8 +60,9 @@ fn can_compile>(test: T) -> bool { .arg("--emit=metadata") // Do as little as possible but still parse. .arg("--target") .arg(target) - .arg("--out-dir") - .arg(out_dir); // Put the output somewhere inconsequential. + .arg("-o") + .arg("-") + .stdout(Stdio::null()); // We don't care about the output (only whether it builds or not) // If Cargo wants to set RUSTFLAGS, use that. if let Ok(rustflags) = var("CARGO_ENCODED_RUSTFLAGS") {