Handle multiple find results in wasi libc build

This commit is contained in:
Richard Feldman 2022-05-15 21:26:20 -04:00
parent c90fc98524
commit 262b2fd24e
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798

View file

@ -32,15 +32,14 @@ fn main() {
); );
// Find the libc.a and compiler_rt.o files that Zig wrote (as a side-effect of compiling the dummy program) // Find the libc.a and compiler_rt.o files that Zig wrote (as a side-effect of compiling the dummy program)
let find_libc_output = run_command(Path::new("."), "find", [&zig_cache_dir, "-name", "libc.a"]); let cwd = std::env::current_dir().unwrap();
let zig_libc_path = find_libc_output.trim(); // get rid of a newline let find_libc_output = run_command(&cwd, "find", [&zig_cache_dir, "-name", "libc.a"]);
// If `find` printed multiple results, take the first.
let zig_libc_path = find_libc_output.split("\n").next().unwrap();
let find_crt_output = run_command( let find_crt_output = run_command(&cwd, "find", [&zig_cache_dir, "-name", "compiler_rt.o"]);
Path::new("."), // If `find` printed multiple results, take the first.
"find", let zig_crt_path = find_crt_output.split("\n").next().unwrap();
[&zig_cache_dir, "-name", "compiler_rt.o"],
);
let zig_crt_path = find_crt_output.trim(); // get rid of a newline
// Copy libc to where Cargo expects the output of this crate // Copy libc to where Cargo expects the output of this crate
fs::copy(&zig_libc_path, &out_file).unwrap(); fs::copy(&zig_libc_path, &out_file).unwrap();