From 9eb6caa0497cd5679d304d72e56b8a86fa13004e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Thu, 19 Feb 2026 09:28:17 +0100 Subject: [PATCH] Use in-tree Cargo when testing stage 2+ cargo miri --- src/bootstrap/src/core/build_steps/test.rs | 14 ++++++++ src/bootstrap/src/core/builder/tests.rs | 39 ++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index f0fe1c03e7e1..0a5dfebf466b 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -805,6 +805,20 @@ fn run(self, builder: &Builder<'_>) { &[], ); + // If we are testing stage 2+ cargo miri, make sure that it works with the in-tree cargo. + // We want to do this *somewhere* to ensure that Miri + nightly cargo actually works. + if stage >= 2 { + let built_cargo = builder + .ensure(tool::Cargo::from_build_compiler( + // Build stage 1 cargo here, we don't need it to be built in any special way, + // just that it is built from in-tree sources. + builder.compiler(0, builder.host_target), + builder.host_target, + )) + .tool_path; + cargo.env("CARGO", built_cargo); + } + // We're not using `prepare_cargo_test` so we have to do this ourselves. // (We're not using that as the test-cargo-miri crate is not known to bootstrap.) match builder.doc_tests { diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 9c7b66a4d373..8c2f3963903c 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -3079,6 +3079,45 @@ fn install_extended() { "); } + #[test] + fn cargo_miri_stage_1() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("test") + .args(&["cargo-miri"]) + .stage(1) + .get_steps() + .render(), @" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 0 -> miri 1 + [build] rustc 0 -> cargo-miri 1 + [build] rustdoc 1 + [build] rustc 1 -> std 1 + "); + } + + #[test] + fn cargo_miri_stage_2() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("test") + .args(&["cargo-miri"]) + .stage(2) + .get_steps() + .render(), @" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 + [build] rustc 1 -> rustc 2 + [build] rustc 1 -> miri 2 + [build] rustc 1 -> cargo-miri 2 + [build] rustdoc 2 + [build] rustc 2 -> std 2 + [build] rustc 0 -> cargo 1 + "); + } + // Check that `x run miri --target FOO` actually builds miri for the host. #[test] fn run_miri() {