Skip to content

Commit d9727d1

Browse files
authored
Rollup merge of #123504 - RalfJung:test-cargo-miri, r=Mark-Simulacrum
bootstrap: split cargo-miri test into separate Step This makes it easier to test just the driver or the cargo-miri integration. ````@rust-lang/miri```` this means to test both you now need to do `./x.py test miri cargo-miri`.
2 parents 459dd38 + 234057d commit d9727d1

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

src/bootstrap/src/core/build_steps/test.rs

+35-4
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ impl Step for Miri {
597597
builder.ensure(compile::Std::new(target_compiler, host));
598598
let host_sysroot = builder.sysroot(target_compiler);
599599

600-
// # Run `cargo test`.
600+
// Run `cargo test`.
601601
// This is with the Miri crate, so it uses the host compiler.
602602
let mut cargo = tool::prepare_tool_cargo(
603603
builder,
@@ -652,15 +652,46 @@ impl Step for Miri {
652652
builder.run(&mut cargo);
653653
}
654654
}
655+
}
656+
}
657+
658+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
659+
pub struct CargoMiri {
660+
target: TargetSelection,
661+
}
662+
663+
impl Step for CargoMiri {
664+
type Output = ();
665+
const ONLY_HOSTS: bool = false;
655666

656-
// # Run `cargo miri test`.
667+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
668+
run.path("src/tools/miri/cargo-miri")
669+
}
670+
671+
fn make_run(run: RunConfig<'_>) {
672+
run.builder.ensure(CargoMiri { target: run.target });
673+
}
674+
675+
/// Tests `cargo miri test`.
676+
fn run(self, builder: &Builder<'_>) {
677+
let host = builder.build.build;
678+
let target = self.target;
679+
let stage = builder.top_stage;
680+
if stage == 0 {
681+
eprintln!("cargo-miri cannot be tested at stage 0");
682+
std::process::exit(1);
683+
}
684+
685+
// This compiler runs on the host, we'll just use it for the target.
686+
let compiler = builder.compiler(stage, host);
687+
688+
// Run `cargo miri test`.
657689
// This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
658690
// that we get the desired output), but that is sufficient to make sure that the libtest harness
659691
// itself executes properly under Miri, and that all the logic in `cargo-miri` does not explode.
660-
// This is running the build `cargo-miri` for the given target, so we need the target compiler.
661692
let mut cargo = tool::prepare_tool_cargo(
662693
builder,
663-
target_compiler,
694+
compiler,
664695
Mode::ToolStd, // it's unclear what to use here, we're not building anything just doing a smoke test!
665696
target,
666697
"miri-test",

src/bootstrap/src/core/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ impl<'a> Builder<'a> {
808808
test::EditionGuide,
809809
test::Rustfmt,
810810
test::Miri,
811+
test::CargoMiri,
811812
test::Clippy,
812813
test::RustDemangler,
813814
test::CompiletestTest,

src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ python3 "$X_PY" test --stage 2 src/tools/rustfmt
3232
# that bugs which only surface when the GC runs at a specific time are more likely to cause CI to fail.
3333
# This significantly increases the runtime of our test suite, or we'd do this in PR CI too.
3434
if [ -z "${PR_CI_JOB:-}" ]; then
35-
MIRIFLAGS=-Zmiri-provenance-gc=1 python3 "$X_PY" test --stage 2 src/tools/miri
35+
MIRIFLAGS=-Zmiri-provenance-gc=1 python3 "$X_PY" test --stage 2 src/tools/miri src/tools/miri/cargo-miri
3636
else
37-
python3 "$X_PY" test --stage 2 src/tools/miri
37+
python3 "$X_PY" test --stage 2 src/tools/miri src/tools/miri/cargo-miri
3838
fi
3939
# We natively run this script on x86_64-unknown-linux-gnu and x86_64-pc-windows-msvc.
4040
# Also cover some other targets via cross-testing, in particular all tier 1 targets.
4141
case $HOST_TARGET in
4242
x86_64-unknown-linux-gnu)
4343
# Only this branch runs in PR CI.
4444
# Fully test all main OSes, including a 32bit target.
45-
python3 "$X_PY" test --stage 2 src/tools/miri --target x86_64-apple-darwin
46-
python3 "$X_PY" test --stage 2 src/tools/miri --target i686-pc-windows-msvc
45+
python3 "$X_PY" test --stage 2 src/tools/miri src/tools/miri/cargo-miri --target x86_64-apple-darwin
46+
python3 "$X_PY" test --stage 2 src/tools/miri src/tools/miri/cargo-miri --target i686-pc-windows-msvc
4747
# Only run "pass" tests for the remaining targets, which is quite a bit faster.
4848
python3 "$X_PY" test --stage 2 src/tools/miri --target x86_64-pc-windows-gnu --test-args pass
4949
python3 "$X_PY" test --stage 2 src/tools/miri --target i686-unknown-linux-gnu --test-args pass

0 commit comments

Comments
 (0)