From 864ae3b936e9c9fe87e9307162ffbc73a564d287 Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 14 Jul 2022 12:11:42 +0200 Subject: [PATCH] wasi-libc-sys: use environment variables to translate from build.rs to a const, instead of rust code generation --- crates/wasi-libc-sys/.gitignore | 1 - crates/wasi-libc-sys/build.rs | 24 ++++++++---------------- crates/wasi-libc-sys/src/lib.rs | 6 ++++-- 3 files changed, 12 insertions(+), 19 deletions(-) delete mode 100644 crates/wasi-libc-sys/.gitignore diff --git a/crates/wasi-libc-sys/.gitignore b/crates/wasi-libc-sys/.gitignore deleted file mode 100644 index 9802e8fdbf..0000000000 --- a/crates/wasi-libc-sys/.gitignore +++ /dev/null @@ -1 +0,0 @@ -src/generated.rs diff --git a/crates/wasi-libc-sys/build.rs b/crates/wasi-libc-sys/build.rs index 0029ad53b8..cfc9f6fefa 100644 --- a/crates/wasi-libc-sys/build.rs +++ b/crates/wasi-libc-sys/build.rs @@ -40,23 +40,15 @@ fn main() { // Copy libc to where Cargo expects the output of this crate fs::copy(&libc_path, &out_file).unwrap(); - // Generate some Rust code to indicate where the file is - let generated_rust = [ - "pub const WASI_LIBC_PATH: &str =", - &format!( - " \"{}\";", - out_file.to_str().unwrap().replace('\\', "\\\\") - ), - "pub const WASI_COMPILER_RT_PATH: &str =", - &format!( - " \"{}\";", - compiler_rt_path.to_str().unwrap().replace('\\', "\\\\") - ), - "", - ] - .join("\n"); + println!( + "cargo:rustc-env=WASI_LIBC_PATH=\"{}\"", + out_file.to_str().unwrap().replace('\\', "\\\\") + ); - fs::write("src/generated.rs", generated_rust).unwrap(); + println!( + "cargo:rustc-env=WASI_COMPILER_RT_PATH=\"{}\"", + compiler_rt_path.to_str().unwrap().replace('\\', "\\\\") + ); } fn zig_executable() -> String { diff --git a/crates/wasi-libc-sys/src/lib.rs b/crates/wasi-libc-sys/src/lib.rs index bc487bd282..e0322e6d16 100644 --- a/crates/wasi-libc-sys/src/lib.rs +++ b/crates/wasi-libc-sys/src/lib.rs @@ -14,5 +14,7 @@ extern "C" { // Tell users of this crate where to find the Wasm .a file // If a non-Wasm target is using this crate, we assume it is a build script that wants to emit Wasm // For Wasm target, it won't ever be used, but we expose it just to keep things simple -mod generated; -pub use generated::{WASI_COMPILER_RT_PATH, WASI_LIBC_PATH}; + +// these variables are set by build.rs +pub const WASI_LIBC_PATH: &str = env!("WASI_LIBC_PATH"); +pub const WASI_COMPILER_RT_PATH: &str = env!("WASI_COMPILER_RT_PATH");