From 598387bfb53bb6cf5edb00a5b53294b766446221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 26 Aug 2025 08:52:04 +0200 Subject: [PATCH] Add snapshot test for cross-compiled dist without docs --- src/bootstrap/src/core/builder/mod.rs | 3 +- src/bootstrap/src/core/builder/tests.rs | 90 ++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index 4f1bed13c13e..76cade25a038 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -145,8 +145,7 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash { } /// Metadata that describes an executed step, mostly for testing and tracing. -#[allow(unused)] -#[derive(Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct StepMetadata { name: String, kind: Kind, diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 5260b43f706c..46f34456a49d 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1493,7 +1493,7 @@ mod snapshot { /// This also serves as an important regression test for /// and . #[test] - fn dist_all_cross() { + fn dist_all_cross_extended() { let ctx = TestCtx::new(); insta::assert_snapshot!( ctx @@ -1571,8 +1571,77 @@ mod snapshot { "); } - // Enable dist cranelift tarball by default with `x dist` if cranelift is enabled in - // `rust.codegen-backends`. + /// Simulates e.g. the powerpc64 builder, which is fully cross-compiled from x64, but it does + /// not build docs. Crutically, it shouldn't build host stage 2 rustc. + #[test] + fn dist_all_cross_extended_no_docs() { + let ctx = TestCtx::new(); + let steps = ctx + .config("dist") + .hosts(&[TEST_TRIPLE_1]) + .targets(&[TEST_TRIPLE_1]) + .args(&[ + "--set", + "rust.channel=nightly", + "--set", + "build.extended=true", + "--set", + "build.docs=false", + ]) + .get_steps(); + + // Make sure that we don't build stage2 host rustc + // steps.assert_no_match(|m| { + // m.name == "rustc" + // && m.built_by.map(|b| b.stage) == Some(1) + // && *m.target.triple == host_target() + // }); + + insta::assert_snapshot!( + steps.render(), @r" + [dist] mingw + [build] llvm + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 0 -> WasmComponentLd 1 + [build] rustc 1 -> std 1 + [build] rustc 1 -> std 1 + [build] rustc 1 -> rustc 2 + [build] rustc 1 -> WasmComponentLd 2 + [build] rustdoc 2 + [build] rustc 1 -> rust-analyzer-proc-macro-srv 2 + [build] rustc 0 -> GenerateCopyright 1 + [build] rustc 0 -> RustInstaller 1 + [dist] rustc + [build] rustc 1 -> rustc 2 + [build] rustc 1 -> WasmComponentLd 2 + [build] rustc 2 -> std 2 + [dist] rustc 2 -> std 2 + [dist] rustc 1 -> rustc-dev 2 + [dist] rustc 1 -> analysis 2 + [dist] src <> + [build] rustc 1 -> cargo 2 + [dist] rustc 1 -> cargo 2 + [build] rustc 1 -> rust-analyzer 2 + [dist] rustc 1 -> rust-analyzer 2 + [build] rustc 1 -> rustfmt 2 + [build] rustc 1 -> cargo-fmt 2 + [dist] rustc 1 -> rustfmt 2 + [build] rustc 1 -> clippy-driver 2 + [build] rustc 1 -> cargo-clippy 2 + [dist] rustc 1 -> clippy 2 + [build] rustc 1 -> miri 2 + [build] rustc 1 -> cargo-miri 2 + [dist] rustc 1 -> miri 2 + [build] rustc 1 -> LlvmBitcodeLinker 2 + [dist] rustc 1 -> std 1 + [dist] rustc 1 -> extended 2 + [dist] reproducible-artifacts + "); + } + + /// Enable dist cranelift tarball by default with `x dist` if cranelift is enabled in + /// `rust.codegen-backends`. #[test] fn dist_cranelift_by_default() { let ctx = TestCtx::new(); @@ -2426,6 +2495,21 @@ impl ExecutedSteps { } } + /// Make sure that no metadata matches the given `func`. + #[track_caller] + fn assert_no_match(&self, func: F) + where + F: Fn(StepMetadata) -> bool, + { + for metadata in self.steps.iter().filter_map(|s| s.metadata.clone()) { + if func(metadata.clone()) { + panic!( + "Metadata {metadata:?} was found, even though it should have not been present" + ); + } + } + } + fn contains(&self, metadata: &StepMetadata) -> bool { self.steps .iter()