From 262b2fd24e1876c807afb37d58281920a655366b Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 15 May 2022 21:26:20 -0400 Subject: [PATCH] Handle multiple `find` results in wasi libc build --- wasi-libc-sys/build.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/wasi-libc-sys/build.rs b/wasi-libc-sys/build.rs index 74f08c4d11..588b759020 100644 --- a/wasi-libc-sys/build.rs +++ b/wasi-libc-sys/build.rs @@ -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) - let find_libc_output = run_command(Path::new("."), "find", [&zig_cache_dir, "-name", "libc.a"]); - let zig_libc_path = find_libc_output.trim(); // get rid of a newline + let cwd = std::env::current_dir().unwrap(); + 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( - Path::new("."), - "find", - [&zig_cache_dir, "-name", "compiler_rt.o"], - ); - let zig_crt_path = find_crt_output.trim(); // get rid of a newline + let find_crt_output = run_command(&cwd, "find", [&zig_cache_dir, "-name", "compiler_rt.o"]); + // If `find` printed multiple results, take the first. + let zig_crt_path = find_crt_output.split("\n").next().unwrap(); // Copy libc to where Cargo expects the output of this crate fs::copy(&zig_libc_path, &out_file).unwrap();