Skip to content

Commit 225e255

Browse files
committed
prefer build-time env vars over run-time values
1 parent 6fdda8a commit 225e255

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

cargo-miri/bin.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,16 +655,21 @@ fn phase_cargo_runner(binary: &Path, binary_args: env::Args) {
655655
let info: CrateRunInfo = serde_json::from_reader(file)
656656
.unwrap_or_else(|_| show_error(format!("file {:?} contains outdated or invalid JSON; try `cargo clean`", binary)));
657657

658-
// Set missing env vars. Looks like `build.rs` vars are still set at run-time, but
659-
// `CARGO_BIN_EXE_*` are not. This means we can give the run-time environment precedence,
660-
// to rather do too little than too much.
658+
let mut cmd = miri();
659+
660+
// Set missing env vars. We prefer build-time env vars over run-time ones; see
661+
// <https://github.com/rust-lang/miri/issues/1661> for the kind of issue that fixes.
661662
for (name, val) in info.env {
662-
if env::var_os(&name).is_none() {
663-
env::set_var(name, val);
663+
if verbose {
664+
if let Some(old_val) = env::var_os(&name) {
665+
if old_val != val {
666+
eprintln!("[cargo-miri runner] Overwriting run-time env var {:?}={:?} with build-time value {:?}", name, old_val, val);
667+
}
668+
}
664669
}
670+
cmd.env(name, val);
665671
}
666672

667-
let mut cmd = miri();
668673
// Forward rustc arguments.
669674
// We need to patch "--extern" filenames because we forced a check-only
670675
// build without cargo knowing about that: replace `.rlib` suffix by

0 commit comments

Comments
 (0)