diff --git a/cargo-miri/bin.rs b/cargo-miri/bin.rs index d18e9608cf5..b413a0b222e 100644 --- a/cargo-miri/bin.rs +++ b/cargo-miri/bin.rs @@ -655,16 +655,21 @@ fn phase_cargo_runner(binary: &Path, binary_args: env::Args) { let info: CrateRunInfo = serde_json::from_reader(file) .unwrap_or_else(|_| show_error(format!("file {:?} contains outdated or invalid JSON; try `cargo clean`", binary))); - // Set missing env vars. Looks like `build.rs` vars are still set at run-time, but - // `CARGO_BIN_EXE_*` are not. This means we can give the run-time environment precedence, - // to rather do too little than too much. + let mut cmd = miri(); + + // Set missing env vars. We prefer build-time env vars over run-time ones; see + // for the kind of issue that fixes. for (name, val) in info.env { - if env::var_os(&name).is_none() { - env::set_var(name, val); + if verbose { + if let Some(old_val) = env::var_os(&name) { + if old_val != val { + eprintln!("[cargo-miri runner] Overwriting run-time env var {:?}={:?} with build-time value {:?}", name, old_val, val); + } + } } + cmd.env(name, val); } - let mut cmd = miri(); // Forward rustc arguments. // We need to patch "--extern" filenames because we forced a check-only // build without cargo knowing about that: replace `.rlib` suffix by