prefer build-time env vars over run-time values

This commit is contained in:
Ralf Jung 2021-01-23 16:51:29 +01:00
parent 6fdda8aac9
commit 225e255cfe

View File

@ -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
// <https://github.com/rust-lang/miri/issues/1661> 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