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

@ -23,19 +23,19 @@ fn main() {
pre_linked_binary_path.extend(["pre_linked_binary"]);
pre_linked_binary_path.set_extension("o");
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");
let output = Command::new(&zig_executable())
.args([
"wasm-ld",
builtins_host_file.path().to_str().unwrap(),
builtins_host_tempfile.path().to_str().unwrap(),
platform_obj.to_str().unwrap(),
WASI_COMPILER_RT_PATH,
WASI_LIBC_PATH,
@ -48,6 +48,10 @@ fn main() {
.output()
.unwrap();
// 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;
assert!(output.status.success(), "{:#?}", output);
assert!(output.stdout.is_empty(), "{:#?}", output);
assert!(output.stderr.is_empty(), "{:#?}", output);