From 56b8bc947ff87556426110d6524432023991cf52 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 20 Mar 2023 06:22:36 -0700 Subject: [PATCH] Don't use RUSTC_WRAPPER if it's empty. (#305) Port bytecodealliance/rustix#565 to cap-std. --- build.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 280aeddf..1a2cead4 100644 --- a/build.rs +++ b/build.rs @@ -50,7 +50,14 @@ fn can_compile>(test: T) -> bool { let rustc = var("RUSTC").unwrap(); let target = var("TARGET").unwrap(); - let mut cmd = if let Ok(wrapper) = var("RUSTC_WRAPPER") { + // Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string, + // as documented [here]. + // [here]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-reads + let wrapper = var("RUSTC_WRAPPER") + .ok() + .and_then(|w| if w.is_empty() { None } else { Some(w) }); + + let mut cmd = if let Some(wrapper) = wrapper { let mut cmd = std::process::Command::new(wrapper); // The wrapper's first argument is supposed to be the path to rustc. cmd.arg(rustc);