Make sure tempfiles don't get dropped too early

This commit is contained in:
Richard Feldman 2022-11-22 20:22:08 -05:00
parent 6b446fe592
commit 0b73ea69af
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
6 changed files with 46 additions and 25 deletions

View file

@ -100,18 +100,18 @@ fn build_wasm_test_host() {
let mut outfile = PathBuf::from(&out_dir).join(PLATFORM_FILENAME);
outfile.set_extension("wasm");
let builtins_host_file = tempfile::Builder::new()
let builtins_host_tempfile = tempfile::Builder::new()
.prefix("host_bitcode")
.suffix(".wasm")
.rand_bytes(5)
.tempfile()
.unwrap();
std::fs::write(builtins_host_file.path(), bitcode::HOST_WASM)
std::fs::write(builtins_host_tempfile.path(), bitcode::HOST_WASM)
.expect("failed to write host builtins object to tempfile");
run_zig(&[
"wasm-ld",
builtins_host_file.path().to_str().unwrap(),
builtins_host_tempfile.path().to_str().unwrap(),
platform_path.to_str().unwrap(),
WASI_COMPILER_RT_PATH,
WASI_LIBC_PATH,
@ -120,6 +120,10 @@ fn build_wasm_test_host() {
"--no-entry",
"--relocatable",
]);
// Extend the lifetime of the tempfile so it doesn't get dropped
// (and thus deleted) before the Zig process is done using it!
let _ = builtins_host_tempfile;
}
fn build_wasm_platform(out_dir: &str, source_path: &str) -> PathBuf {