Skip to content

Commit 74b7714

Browse files
committed
Auto merge of #1723 - RalfJung:cargo-miri, r=RalfJung
cargo-miri: avoid unnecessary rebuilds Fixes #1722
2 parents e29f137 + 3e987e1 commit 74b7714

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

cargo-miri/bin.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,17 @@ fn phase_cargo_rustc(mut args: env::Args) {
692692
exec(cmd);
693693

694694
// Create a stub .rlib file if "link" was requested by cargo.
695+
// This is necessary to prevent cargo from doing rebuilds all the time.
695696
if emit_link_hack {
696697
// Some platforms prepend "lib", some do not... let's just create both files.
697-
let filename = out_filename("lib", ".rlib");
698-
File::create(filename).expect("failed to create rlib file");
699-
let filename = out_filename("", ".rlib");
700-
File::create(filename).expect("failed to create rlib file");
698+
File::create(out_filename("lib", ".rlib")).expect("failed to create fake .rlib file");
699+
File::create(out_filename("", ".rlib")).expect("failed to create fake .rlib file");
700+
// Just in case this is a cdylib or staticlib, also create those fake files.
701+
File::create(out_filename("lib", ".so")).expect("failed to create fake .so file");
702+
File::create(out_filename("lib", ".a")).expect("failed to create fake .a file");
703+
File::create(out_filename("lib", ".dylib")).expect("failed to create fake .dylib file");
704+
File::create(out_filename("", ".dll")).expect("failed to create fake .dll file");
705+
File::create(out_filename("", ".lib")).expect("failed to create fake .lib file");
701706
}
702707
}
703708

test-cargo-miri/run-test.py

+29-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ def fail(msg):
1515
print("\nTEST FAIL: {}".format(msg))
1616
sys.exit(1)
1717

18-
def cargo_miri(cmd):
19-
args = ["cargo", "miri", cmd, "-q"]
18+
def cargo_miri(cmd, quiet = True):
19+
args = ["cargo", "miri", cmd]
20+
if quiet:
21+
args += ["-q"]
2022
if 'MIRI_TEST_TARGET' in os.environ:
2123
args += ["--target", os.environ['MIRI_TEST_TARGET']]
2224
return args
@@ -48,6 +50,25 @@ def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}):
4850
print("--- END stderr ---")
4951
fail("exit code was {}".format(p.returncode))
5052

53+
def test_no_rebuild(name, cmd):
54+
print("Testing {}...".format(name))
55+
p = subprocess.Popen(
56+
cmd,
57+
stdout=subprocess.PIPE,
58+
stderr=subprocess.PIPE,
59+
)
60+
(stdout, stderr) = p.communicate()
61+
stdout = stdout.decode("UTF-8")
62+
stderr = stderr.decode("UTF-8")
63+
if p.returncode != 0:
64+
fail("rebuild failed");
65+
# Also check for 'Running' as a sanity check.
66+
if stderr.count(" Compiling ") > 0 or stderr.count(" Running ") == 0:
67+
print("--- BEGIN stderr ---")
68+
print(stderr, end="")
69+
print("--- END stderr ---")
70+
fail("Something was being rebuilt when it should not be (or we got no output)");
71+
5172
def test_cargo_miri_run():
5273
test("`cargo miri run` (no isolation)",
5374
cargo_miri("run"),
@@ -67,6 +88,12 @@ def test_cargo_miri_run():
6788
"run.subcrate.stdout.ref", "run.subcrate.stderr.ref",
6889
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
6990
)
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+
)
7097

7198
def test_cargo_miri_test():
7299
# rustdoc is not run on foreign targets

0 commit comments

Comments
 (0)