Skip to content

Commit

Permalink
Don't store build check rmeta
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sunfishcode committed Nov 22, 2024
1 parent c461c07 commit 0e55fc8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ fn has_feature(feature: &str) -> bool {
fn can_compile<T: AsRef<str>>(test: T) -> bool {
use std::process::Stdio;

let out_dir = var("OUT_DIR").unwrap();
let rustc = var("RUSTC").unwrap();
let target = var("TARGET").unwrap();

Expand All @@ -72,8 +71,9 @@ fn can_compile<T: AsRef<str>>(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") {
Expand Down
6 changes: 3 additions & 3 deletions cap-async-std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ fn has_feature(feature: &str) -> bool {
fn can_compile<T: AsRef<str>>(test: T) -> bool {
use std::process::Stdio;

let out_dir = var("OUT_DIR").unwrap();
let rustc = var("RUSTC").unwrap();
let target = var("TARGET").unwrap();

Expand All @@ -59,8 +58,9 @@ fn can_compile<T: AsRef<str>>(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") {
Expand Down
6 changes: 3 additions & 3 deletions cap-fs-ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ fn has_feature(feature: &str) -> bool {
fn can_compile<T: AsRef<str>>(test: T) -> bool {
use std::process::Stdio;

let out_dir = var("OUT_DIR").unwrap();
let rustc = var("RUSTC").unwrap();
let target = var("TARGET").unwrap();

Expand All @@ -56,8 +55,9 @@ fn can_compile<T: AsRef<str>>(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") {
Expand Down
6 changes: 3 additions & 3 deletions cap-primitives/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ fn has_feature(feature: &str) -> bool {
fn can_compile<T: AsRef<str>>(test: T) -> bool {
use std::process::Stdio;

let out_dir = var("OUT_DIR").unwrap();
let rustc = var("RUSTC").unwrap();
let target = var("TARGET").unwrap();

Expand All @@ -66,8 +65,9 @@ fn can_compile<T: AsRef<str>>(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") {
Expand Down
6 changes: 3 additions & 3 deletions cap-std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ fn has_feature(feature: &str) -> bool {
fn can_compile<T: AsRef<str>>(test: T) -> bool {
use std::process::Stdio;

let out_dir = var("OUT_DIR").unwrap();
let rustc = var("RUSTC").unwrap();
let target = var("TARGET").unwrap();

Expand All @@ -61,8 +60,9 @@ fn can_compile<T: AsRef<str>>(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") {
Expand Down

0 comments on commit 0e55fc8

Please sign in to comment.