Skip to content

Commit e3ca994

Browse files
committed
Auto merge of #1684 - RalfJung:env, r=oli-obk
prefer build-time env vars over run-time values Fixes #1661
2 parents 6fdda8a + 4a13f24 commit e3ca994

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ different Miri binaries, and as such worth documenting:
286286
directory after loading all the source files, but before commencing
287287
interpretation. This is useful if the interpreted program wants a different
288288
working directory at run-time than at build-time.
289+
* `MIRI_VERBOSE` when set to any value tells the various `cargo-miri` phases to
290+
perform verbose logging.
289291

290292
[testing-miri]: CONTRIBUTING.md#testing-the-miri-driver
291293

cargo-miri/bin.rs

+11-6
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)