Skip to content

Commit 894e46f

Browse files
committed
build: Use OUT_DIR for test compilation output
The `can_compile` utility writes its temporary output file to the system's global temporary directory. This can clutter the host system with build artifacts. By using Cargo's `OUT_DIR`, the temporary file is written to a directory specific to the build, ensuring that build artifacts are contained within the project's build output and do not mess up the host system. Follow-up to bytecodealliance#1497.
1 parent 5245b81 commit 894e46f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::env::var;
22
use std::io::Write as _;
3+
use std::path::PathBuf;
34

45
/// The directory for inline asm.
56
const ASM_PATH: &str = "src/backend/linux_raw/arch";
@@ -253,12 +254,14 @@ fn can_compile<T: AsRef<str>>(test: T) -> bool {
253254
std::process::Command::new(rustc)
254255
};
255256

257+
let out_dir = var("OUT_DIR").unwrap();
258+
let out_file = PathBuf::from(out_dir).join("rustix_test_can_compile");
256259
cmd.arg("--crate-type=rlib") // Don't require `main`.
257260
.arg("--emit=metadata") // Do as little as possible but still parse.
258261
.arg("--target")
259262
.arg(target)
260263
.arg("-o")
261-
.arg(std::env::temp_dir().join("rustix_test_can_compile"))
264+
.arg(out_file)
262265
.stdout(Stdio::null()); // We don't care about the output (only whether it builds or not)
263266

264267
// If Cargo wants to set RUSTFLAGS, use that.

0 commit comments

Comments
 (0)