Skip to content

Commit 39ebb07

Browse files
committed
Auto merge of #1726 - hyd-dev:stub-d, r=RalfJung
cargo-miri: create stub .d files Thanks `@RalfJung` for the discovery: #1724 (comment) ❤️ Fixes #1724.
2 parents 4ecb5a9 + 6d5ce21 commit 39ebb07

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

cargo-miri/bin.rs

+9
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,15 @@ fn phase_cargo_rustc(mut args: env::Args) {
609609
let print = get_arg_flag_value("--print").is_some(); // whether this is cargo passing `--print` to get some infos
610610

611611
let store_json = |info: CrateRunInfo| {
612+
// Create a stub .d file to stop Cargo from "rebuilding" the crate:
613+
// https://github.com/rust-lang/miri/issues/1724#issuecomment-787115693
614+
// As we store a JSON file instead of building the crate here, an empty file is fine.
615+
let dep_info_name = out_filename("", ".d");
616+
if verbose {
617+
eprintln!("[cargo-miri rustc] writing stub dep-info to `{}`", dep_info_name.display());
618+
}
619+
File::create(dep_info_name).expect("failed to create fake .d file");
620+
612621
let filename = out_filename("", "");
613622
if verbose {
614623
eprintln!("[cargo-miri rustc] writing run info to `{}`", filename.display());

test-cargo-miri/run-test.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,15 @@ def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}):
5050
print("--- END stderr ---")
5151
fail("exit code was {}".format(p.returncode))
5252

53-
def test_no_rebuild(name, cmd):
53+
def test_no_rebuild(name, cmd, env={}):
5454
print("Testing {}...".format(name))
55+
p_env = os.environ.copy()
56+
p_env.update(env)
5557
p = subprocess.Popen(
5658
cmd,
5759
stdout=subprocess.PIPE,
5860
stderr=subprocess.PIPE,
61+
env=p_env,
5962
)
6063
(stdout, stderr) = p.communicate()
6164
stdout = stdout.decode("UTF-8")
@@ -79,6 +82,12 @@ def test_cargo_miri_run():
7982
'MIRITESTVAR': "wrongval", # make sure the build.rs value takes precedence
8083
},
8184
)
85+
# Special test: run it again *without* `-q` to make sure nothing is being rebuilt (Miri issue #1722)
86+
test_no_rebuild("`cargo miri run` (no rebuild)",
87+
cargo_miri("run", quiet=False) + ["--", ""],
88+
env={'MIRITESTVAR': "wrongval"}, # changing the env var causes a rebuild (re-runs build.rs),
89+
# so keep it set
90+
)
8291
test("`cargo miri run` (with arguments and target)",
8392
cargo_miri("run") + ["--bin", "cargo-miri-test", "--", "hello world", '"hello world"'],
8493
"run.args.stdout.ref", "run.args.stderr.ref",
@@ -88,12 +97,6 @@ def test_cargo_miri_run():
8897
"run.subcrate.stdout.ref", "run.subcrate.stderr.ref",
8998
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
9099
)
91-
# Special test: run it again *without* `-q` to make sure nothing is being rebuilt (Miri issue #1722)
92-
# FIXME: move this test up to right after the first `test`
93-
# (currently that fails, only the 3rd and later runs are really clean... see Miri issue #1722)
94-
test_no_rebuild("`cargo miri run` (no rebuild)",
95-
cargo_miri("run", quiet=False) + ["--", ""],
96-
)
97100

98101
def test_cargo_miri_test():
99102
# rustdoc is not run on foreign targets

0 commit comments

Comments
 (0)