diff --git a/cargo-miri/bin.rs b/cargo-miri/bin.rs index f514f4e3e5c3..d35940897191 100644 --- a/cargo-miri/bin.rs +++ b/cargo-miri/bin.rs @@ -612,7 +612,9 @@ 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 {:?} does not contain valid JSON", binary))); - // Set missing env vars. + // 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. for (name, val) in info.env { if env::var_os(&name).is_none() { env::set_var(name, val); diff --git a/test-cargo-miri/build.rs b/test-cargo-miri/build.rs index b1f5fc172620..9851ccf39f3f 100644 --- a/test-cargo-miri/build.rs +++ b/test-cargo-miri/build.rs @@ -12,4 +12,6 @@ fn not_in_miri() -> i32 { fn main() { not_in_miri(); println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-env-changed=MIRITESTVAR"); + println!("cargo:rustc-env=MIRITESTVAR=testval"); } diff --git a/test-cargo-miri/run-test.py b/test-cargo-miri/run-test.py index 665e9834e8e5..2250835c9998 100755 --- a/test-cargo-miri/run-test.py +++ b/test-cargo-miri/run-test.py @@ -50,11 +50,14 @@ def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}): fail("stderr does not match reference") def test_cargo_miri_run(): - test("`cargo miri run`", + test("`cargo miri run` (without isolation)", cargo_miri("run"), "stdout.ref1", "stderr.ref1", stdin=b'12\n21\n', - env={'MIRIFLAGS': "-Zmiri-disable-isolation"}, + env={ + 'MIRIFLAGS': "-Zmiri-disable-isolation", + 'MIRITESTVAR': "wrongval", # make sure the build.rs value takes precedence + }, ) test("`cargo miri run` (with arguments and target)", cargo_miri("run") + ["--bin", "cargo-miri-test", "--", "hello world", '"hello world"'], diff --git a/test-cargo-miri/src/main.rs b/test-cargo-miri/src/main.rs index 17808f57061e..b36b0c725f85 100644 --- a/test-cargo-miri/src/main.rs +++ b/test-cargo-miri/src/main.rs @@ -3,6 +3,9 @@ use byteorder::{BigEndian, ByteOrder}; use std::io::{self, BufRead}; fn main() { + // Check env var set by `build.rs`. + assert_eq!(env!("MIRITESTVAR"), "testval"); + // Exercise external crate, printing to stdout. let buf = &[1,2,3,4]; let n = ::read_u32(buf);