From 3c391a639411aaddec92fa96227528b1fd8d8ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 25 Jun 2025 16:42:15 +0200 Subject: [PATCH 1/8] Automatically derive stage in step metadata where possible --- src/bootstrap/src/core/build_steps/compile.rs | 12 +- src/bootstrap/src/core/build_steps/tool.rs | 1 - src/bootstrap/src/core/builder/mod.rs | 6 + src/bootstrap/src/core/builder/tests.rs | 103 +++++++++--------- 4 files changed, 60 insertions(+), 62 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 84064150738f5..c3a3eddd16128 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -306,11 +306,7 @@ impl Step for Std { } fn metadata(&self) -> Option { - Some( - StepMetadata::build("std", self.target) - .built_by(self.compiler) - .stage(self.compiler.stage), - ) + Some(StepMetadata::build("std", self.target).built_by(self.compiler)) } } @@ -1186,11 +1182,7 @@ impl Step for Rustc { } fn metadata(&self) -> Option { - Some( - StepMetadata::build("rustc", self.target) - .built_by(self.build_compiler) - .stage(self.build_compiler.stage + 1), - ) + Some(StepMetadata::build("rustc", self.target).built_by(self.build_compiler)) } } diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index a7220515ca09d..ad3f8d8976701 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -1195,7 +1195,6 @@ macro_rules! tool_extended { Some( StepMetadata::build($tool_name, self.target) .built_by(self.compiler.with_stage(self.compiler.stage.saturating_sub(1))) - .stage(self.compiler.stage) ) } } diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index 8e9e8b496de7c..e46a811b9b17b 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -178,6 +178,12 @@ impl StepMetadata { self.stage = Some(stage); self } + + pub fn get_stage(&self) -> Option { + self.stage.or(self + .built_by + .map(|compiler| if self.name == "std" { compiler.stage } else { compiler.stage + 1 })) + } } pub struct RunConfig<'a> { diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 8adf93ea52889..f8ed284dbe0d4 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -863,7 +863,7 @@ mod snapshot { insta::assert_snapshot!( ctx.config("build") .path("opt-dist") - .render_steps(), @"[build] rustc 0 -> OptimizedDist "); + .render_steps(), @"[build] rustc 0 -> OptimizedDist 1 "); } #[test] @@ -880,7 +880,7 @@ mod snapshot { ctx.config("build") .path("opt-dist") .stage(1) - .render_steps(), @"[build] rustc 0 -> OptimizedDist "); + .render_steps(), @"[build] rustc 0 -> OptimizedDist 1 "); } #[test] @@ -890,7 +890,7 @@ mod snapshot { ctx.config("build") .path("opt-dist") .stage(2) - .render_steps(), @"[build] rustc 0 -> OptimizedDist "); + .render_steps(), @"[build] rustc 0 -> OptimizedDist 1 "); } #[test] @@ -984,8 +984,8 @@ mod snapshot { ctx .config("dist") .render_steps(), @r" - [build] rustc 0 -> UnstableBookGen - [build] rustc 0 -> Rustbook + [build] rustc 0 -> UnstableBookGen 1 + [build] rustc 0 -> Rustbook 1 [build] llvm [build] rustc 0 -> rustc 1 [build] rustc 1 -> std 1 @@ -993,14 +993,14 @@ mod snapshot { [build] rustdoc 1 [doc] std 2 [build] rustc 2 -> std 2 - [build] rustc 0 -> LintDocs - [build] rustc 0 -> RustInstaller + [build] rustc 0 -> LintDocs 1 + [build] rustc 0 -> RustInstaller 1 [dist] docs [doc] std 2 [dist] mingw - [build] rustc 0 -> GenerateCopyright + [build] rustc 0 -> GenerateCopyright 1 [dist] rustc - [dist] rustc 1 -> std + [dist] rustc 1 -> std 1 [dist] src <> " ); @@ -1014,25 +1014,25 @@ mod snapshot { .config("dist") .args(&["--set", "build.extended=true"]) .render_steps(), @r" - [build] rustc 0 -> UnstableBookGen - [build] rustc 0 -> Rustbook + [build] rustc 0 -> UnstableBookGen 1 + [build] rustc 0 -> Rustbook 1 [build] llvm [build] rustc 0 -> rustc 1 - [build] rustc 0 -> WasmComponentLd + [build] rustc 0 -> WasmComponentLd 1 [build] rustc 1 -> std 1 [build] rustc 1 -> rustc 2 - [build] rustc 1 -> WasmComponentLd + [build] rustc 1 -> WasmComponentLd 2 [build] rustdoc 1 [doc] std 2 [build] rustc 2 -> std 2 - [build] rustc 0 -> LintDocs - [build] rustc 0 -> RustInstaller + [build] rustc 0 -> LintDocs 1 + [build] rustc 0 -> RustInstaller 1 [dist] docs [doc] std 2 [dist] mingw - [build] rustc 0 -> GenerateCopyright + [build] rustc 0 -> GenerateCopyright 1 [dist] rustc - [dist] rustc 1 -> std + [dist] rustc 1 -> std 1 [dist] src <> [build] rustc 0 -> rustfmt 1 [build] rustc 0 -> cargo-fmt 1 @@ -1052,8 +1052,8 @@ mod snapshot { .hosts(&[&host_target()]) .targets(&[&host_target(), TEST_TRIPLE_1]) .render_steps(), @r" - [build] rustc 0 -> UnstableBookGen - [build] rustc 0 -> Rustbook + [build] rustc 0 -> UnstableBookGen 1 + [build] rustc 0 -> Rustbook 1 [build] llvm [build] rustc 0 -> rustc 1 [build] rustc 1 -> std 1 @@ -1062,19 +1062,19 @@ mod snapshot { [doc] std 2 [doc] std 2 [build] rustc 2 -> std 2 - [build] rustc 0 -> LintDocs - [build] rustc 0 -> RustInstaller + [build] rustc 0 -> LintDocs 1 + [build] rustc 0 -> RustInstaller 1 [dist] docs [dist] docs [doc] std 2 [doc] std 2 [dist] mingw [dist] mingw - [build] rustc 0 -> GenerateCopyright + [build] rustc 0 -> GenerateCopyright 1 [dist] rustc - [dist] rustc 1 -> std + [dist] rustc 1 -> std 1 [build] rustc 2 -> std 2 - [dist] rustc 2 -> std + [dist] rustc 2 -> std 2 [dist] src <> " ); @@ -1089,8 +1089,8 @@ mod snapshot { .hosts(&[&host_target(), TEST_TRIPLE_1]) .targets(&[&host_target()]) .render_steps(), @r" - [build] rustc 0 -> UnstableBookGen - [build] rustc 0 -> Rustbook + [build] rustc 0 -> UnstableBookGen 1 + [build] rustc 0 -> Rustbook 1 [build] llvm [build] rustc 0 -> rustc 1 [build] rustc 1 -> std 1 @@ -1098,20 +1098,20 @@ mod snapshot { [build] rustdoc 1 [doc] std 2 [build] rustc 2 -> std 2 - [build] rustc 0 -> LintDocs + [build] rustc 0 -> LintDocs 1 [build] rustc 1 -> std 1 [build] rustc 2 -> std 2 - [build] rustc 0 -> RustInstaller + [build] rustc 0 -> RustInstaller 1 [dist] docs [doc] std 2 [dist] mingw - [build] rustc 0 -> GenerateCopyright + [build] rustc 0 -> GenerateCopyright 1 [dist] rustc [build] llvm [build] rustc 1 -> rustc 2 [build] rustdoc 1 [dist] rustc - [dist] rustc 1 -> std + [dist] rustc 1 -> std 1 [dist] src <> " ); @@ -1126,8 +1126,8 @@ mod snapshot { .hosts(&[&host_target(), TEST_TRIPLE_1]) .targets(&[&host_target(), TEST_TRIPLE_1]) .render_steps(), @r" - [build] rustc 0 -> UnstableBookGen - [build] rustc 0 -> Rustbook + [build] rustc 0 -> UnstableBookGen 1 + [build] rustc 0 -> Rustbook 1 [build] llvm [build] rustc 0 -> rustc 1 [build] rustc 1 -> std 1 @@ -1136,24 +1136,24 @@ mod snapshot { [doc] std 2 [doc] std 2 [build] rustc 2 -> std 2 - [build] rustc 0 -> LintDocs + [build] rustc 0 -> LintDocs 1 [build] rustc 1 -> std 1 [build] rustc 2 -> std 2 - [build] rustc 0 -> RustInstaller + [build] rustc 0 -> RustInstaller 1 [dist] docs [dist] docs [doc] std 2 [doc] std 2 [dist] mingw [dist] mingw - [build] rustc 0 -> GenerateCopyright + [build] rustc 0 -> GenerateCopyright 1 [dist] rustc [build] llvm [build] rustc 1 -> rustc 2 [build] rustdoc 1 [dist] rustc - [dist] rustc 1 -> std - [dist] rustc 1 -> std + [dist] rustc 1 -> std 1 + [dist] rustc 1 -> std 1 [dist] src <> " ); @@ -1168,8 +1168,8 @@ mod snapshot { .hosts(&[]) .targets(&[TEST_TRIPLE_1]) .render_steps(), @r" - [build] rustc 0 -> UnstableBookGen - [build] rustc 0 -> Rustbook + [build] rustc 0 -> UnstableBookGen 1 + [build] rustc 0 -> Rustbook 1 [build] llvm [build] rustc 0 -> rustc 1 [build] rustc 1 -> std 1 @@ -1177,12 +1177,12 @@ mod snapshot { [build] rustdoc 1 [doc] std 2 [build] rustc 2 -> std 2 - [build] rustc 0 -> RustInstaller + [build] rustc 0 -> RustInstaller 1 [dist] docs [doc] std 2 [dist] mingw [build] rustc 2 -> std 2 - [dist] rustc 2 -> std + [dist] rustc 2 -> std 2 "); } @@ -1198,31 +1198,31 @@ mod snapshot { .targets(&[TEST_TRIPLE_1]) .args(&["--set", "rust.channel=nightly", "--set", "build.extended=true"]) .render_steps(), @r" - [build] rustc 0 -> UnstableBookGen - [build] rustc 0 -> Rustbook + [build] rustc 0 -> UnstableBookGen 1 + [build] rustc 0 -> Rustbook 1 [build] llvm [build] rustc 0 -> rustc 1 - [build] rustc 0 -> WasmComponentLd + [build] rustc 0 -> WasmComponentLd 1 [build] rustc 1 -> std 1 [build] rustc 1 -> rustc 2 - [build] rustc 1 -> WasmComponentLd + [build] rustc 1 -> WasmComponentLd 2 [build] rustdoc 1 [doc] std 2 [build] rustc 2 -> std 2 [build] rustc 1 -> std 1 [build] rustc 2 -> std 2 - [build] rustc 0 -> LintDocs - [build] rustc 0 -> RustInstaller + [build] rustc 0 -> LintDocs 1 + [build] rustc 0 -> RustInstaller 1 [dist] docs [doc] std 2 [dist] mingw [build] llvm [build] rustc 1 -> rustc 2 - [build] rustc 1 -> WasmComponentLd + [build] rustc 1 -> WasmComponentLd 2 [build] rustdoc 1 - [build] rustc 0 -> GenerateCopyright + [build] rustc 0 -> GenerateCopyright 1 [dist] rustc - [dist] rustc 1 -> std + [dist] rustc 1 -> std 1 [dist] src <> [build] rustc 0 -> rustfmt 1 [build] rustc 0 -> cargo-fmt 1 @@ -1384,7 +1384,8 @@ fn render_metadata(metadata: &StepMetadata) -> String { if let Some(compiler) = metadata.built_by { write!(record, "{} -> ", render_compiler(compiler)); } - let stage = if let Some(stage) = metadata.stage { format!("{stage} ") } else { "".to_string() }; + let stage = + if let Some(stage) = metadata.get_stage() { format!("{stage} ") } else { "".to_string() }; write!(record, "{} {stage}<{}>", metadata.name, normalize_target(metadata.target)); record } From 4dfa59dcfb60f2250ceff511f39a5cbcd2a06bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 25 Jun 2025 16:50:22 +0200 Subject: [PATCH 2/8] Add snapshot tests for checking compiler, library and rustc tools --- src/bootstrap/src/core/build_steps/check.rs | 14 +- src/bootstrap/src/core/builder/mod.rs | 4 + src/bootstrap/src/core/builder/tests.rs | 165 ++++++++++++++++++++ 3 files changed, 182 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index 567416d079b12..23cc2ae332669 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -5,7 +5,7 @@ use crate::core::build_steps::compile::{ }; use crate::core::build_steps::tool::{COMPILETEST_ALLOW_FEATURES, SourceType, prepare_tool_cargo}; use crate::core::builder::{ - self, Alias, Builder, Kind, RunConfig, ShouldRun, Step, crate_description, + self, Alias, Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description, }; use crate::core::config::TargetSelection; use crate::utils::build_stamp::{self, BuildStamp}; @@ -167,6 +167,10 @@ impl Step for Std { let _guard = builder.msg_check("library test/bench/example targets", target, Some(stage)); run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false); } + + fn metadata(&self) -> Option { + Some(StepMetadata::check("std", self.target)) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -258,6 +262,10 @@ impl Step for Rustc { let hostdir = builder.sysroot_target_libdir(compiler, compiler.host); add_to_sysroot(builder, &libdir, &hostdir, &stamp); } + + fn metadata(&self) -> Option { + Some(StepMetadata::check("rustc", self.target)) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -467,6 +475,10 @@ macro_rules! tool_check_step { let Self { target } = self; run_tool_check_step(builder, target, stringify!($name), $path); } + + fn metadata(&self) -> Option { + Some(StepMetadata::check(stringify!($name), self.target)) + } } } } diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index e46a811b9b17b..930efaf0f45b3 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -153,6 +153,10 @@ impl StepMetadata { Self::new(name, target, Kind::Build) } + pub fn check(name: &'static str, target: TargetSelection) -> Self { + Self::new(name, target, Kind::Check) + } + pub fn doc(name: &'static str, target: TargetSelection) -> Self { Self::new(name, target, Kind::Doc) } diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index f8ed284dbe0d4..662c1945148b8 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1233,6 +1233,171 @@ mod snapshot { "); } + #[test] + fn check_compiler_no_explicit_stage() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("compiler") + .render_steps(), @r" + [check] std + [build] llvm + [check] rustc + "); + + insta::assert_snapshot!( + ctx.config("check") + .path("rustc") + .render_steps(), @r" + [build] llvm + [check] rustc 0 -> rustc 1 + "); + } + + #[test] + #[should_panic] + fn check_compiler_stage_0() { + let ctx = TestCtx::new(); + ctx.config("check").path("compiler").stage(0).run(); + } + + #[test] + fn check_compiler_stage_1() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("compiler") + .stage(1) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 + [check] rustc + "); + } + + #[test] + fn check_compiler_stage_2() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("compiler") + .stage(2) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 + [build] rustc 1 -> rustc 2 + [build] rustc 2 -> std 2 + [check] rustc + "); + } + + #[test] + fn check_library_no_explicit_stage() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("library") + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [check] std + "); + } + + #[test] + #[should_panic] + fn check_library_stage_0() { + let ctx = TestCtx::new(); + ctx.config("check").path("library").stage(0).run(); + } + + #[test] + fn check_library_stage_1() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("library") + .stage(1) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [check] std + "); + } + + #[test] + fn check_library_stage_2() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("library") + .stage(2) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 + [build] rustc 1 -> rustc 2 + [check] std + "); + } + + #[test] + fn check_miri_no_explicit_stage() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("miri") + .render_steps(), @r" + [check] std + [build] llvm + [check] rustc + [check] Miri + "); + } + + #[test] + #[should_panic] + fn check_miri_stage_0() { + let ctx = TestCtx::new(); + ctx.config("check").path("miri").stage(0).run(); + } + + #[test] + fn check_miri_stage_1() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("miri") + .stage(1) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 + [check] rustc + [check] Miri + "); + } + + #[test] + fn check_miri_stage_2() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("miri") + .stage(2) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 + [build] rustc 1 -> rustc 2 + [build] rustc 2 -> std 2 + [check] rustc + [check] Miri + "); + } + #[test] fn test_exclude() { let ctx = TestCtx::new(); From a7c625146e368a90b14de25b7c15a92b10040817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 2 Jul 2025 09:04:09 +0200 Subject: [PATCH 3/8] Add compiletest check tests --- src/bootstrap/src/core/build_steps/check.rs | 4 +++ src/bootstrap/src/core/builder/tests.rs | 30 ++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index 23cc2ae332669..f62f17561abee 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -440,6 +440,10 @@ impl Step for Compiletest { let _guard = builder.msg_check("compiletest artifacts", self.target, None); run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false); } + + fn metadata(&self) -> Option { + Some(StepMetadata::check("compiletest", self.target)) + } } macro_rules! tool_check_step { diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 662c1945148b8..924025eea3ecd 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1249,13 +1249,13 @@ mod snapshot { ctx.config("check") .path("rustc") .render_steps(), @r" + [check] std [build] llvm - [check] rustc 0 -> rustc 1 + [check] rustc "); } #[test] - #[should_panic] fn check_compiler_stage_0() { let ctx = TestCtx::new(); ctx.config("check").path("compiler").stage(0).run(); @@ -1307,7 +1307,6 @@ mod snapshot { } #[test] - #[should_panic] fn check_library_stage_0() { let ctx = TestCtx::new(); ctx.config("check").path("library").stage(0).run(); @@ -1358,7 +1357,6 @@ mod snapshot { } #[test] - #[should_panic] fn check_miri_stage_0() { let ctx = TestCtx::new(); ctx.config("check").path("miri").stage(0).run(); @@ -1398,6 +1396,30 @@ mod snapshot { "); } + #[test] + fn check_compiletest() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("compiletest") + .render_steps(), @"[check] compiletest "); + } + + #[test] + fn check_compiletest_stage1_libtest() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("compiletest") + .args(&["--set", "build.compiletest-use-stage0-libtest=false"]) + .render_steps(), @r" + [check] std + [build] llvm + [check] rustc + [check] compiletest + "); + } + #[test] fn test_exclude() { let ctx = TestCtx::new(); From 029304e4a678bd69c3aab56a2e140bc866aa9a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 2 Jul 2025 09:05:02 +0200 Subject: [PATCH 4/8] Add codegen check tests --- src/bootstrap/src/core/build_steps/check.rs | 4 ++++ src/bootstrap/src/core/builder/tests.rs | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index f62f17561abee..7db124a43f1c7 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -323,6 +323,10 @@ impl Step for CodegenBackend { run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false); } + + fn metadata(&self) -> Option { + Some(StepMetadata::check(self.backend, self.target)) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 924025eea3ecd..76480e4e309f2 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1243,6 +1243,8 @@ mod snapshot { [check] std [build] llvm [check] rustc + [check] cranelift + [check] gcc "); insta::assert_snapshot!( @@ -1273,6 +1275,8 @@ mod snapshot { [build] rustc 0 -> rustc 1 [build] rustc 1 -> std 1 [check] rustc + [check] cranelift + [check] gcc "); } @@ -1290,6 +1294,8 @@ mod snapshot { [build] rustc 1 -> rustc 2 [build] rustc 2 -> std 2 [check] rustc + [check] cranelift + [check] gcc "); } @@ -1420,6 +1426,21 @@ mod snapshot { "); } + #[test] + fn check_codegen() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("rustc_codegen_cranelift") + .render_steps(), @r" + [check] std + [build] llvm + [check] rustc + [check] cranelift + [check] gcc + "); + } + #[test] fn test_exclude() { let ctx = TestCtx::new(); From c17da9ebc2de36307bb5db9325e6dc38d9c4f98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 2 Jul 2025 09:05:47 +0200 Subject: [PATCH 5/8] Add Rust Analyzer check tests --- src/bootstrap/src/core/build_steps/check.rs | 4 ++++ src/bootstrap/src/core/builder/tests.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index 7db124a43f1c7..6c5f70b2f4381 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -385,6 +385,10 @@ impl Step for RustAnalyzer { let _guard = builder.msg_check("rust-analyzer artifacts", target, None); run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false); } + + fn metadata(&self) -> Option { + Some(StepMetadata::check("rust-analyzer", self.target)) + } } /// Compiletest is implicitly "checked" when it gets built in order to run tests, diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 76480e4e309f2..838a147091d0a 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1441,6 +1441,20 @@ mod snapshot { "); } + #[test] + fn check_rust_analyzer() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("rust-analyzer") + .render_steps(), @r" + [check] std + [build] llvm + [check] rustc + [check] rust-analyzer + "); + } + #[test] fn test_exclude() { let ctx = TestCtx::new(); From 07a1b824429e681cd1cd2e55f6f6ce803ff110d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 2 Jul 2025 09:06:00 +0200 Subject: [PATCH 6/8] Add bootstrap tool check test --- src/bootstrap/src/core/builder/tests.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 838a147091d0a..1c6c14f47dec3 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1455,6 +1455,20 @@ mod snapshot { "); } + #[test] + fn check_bootstrap_tool() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .path("run-make-support") + .render_steps(), @r" + [check] std + [build] llvm + [check] rustc + [check] RunMakeSupport + "); + } + #[test] fn test_exclude() { let ctx = TestCtx::new(); From e6c64df274407ab63f817c5e7712afc289d89a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 2 Jul 2025 09:07:28 +0200 Subject: [PATCH 7/8] Add cross-compilation check tests --- src/bootstrap/src/core/builder/tests.rs | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 1c6c14f47dec3..a6a147682db1d 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1299,6 +1299,38 @@ mod snapshot { "); } + #[test] + fn check_cross_compile() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .stage(2) + .targets(&[TEST_TRIPLE_1]) + .hosts(&[TEST_TRIPLE_1]) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 + [build] rustc 1 -> rustc 2 + [build] rustc 2 -> std 2 + [build] rustc 1 -> std 1 + [build] rustc 2 -> std 2 + [check] rustc + [check] Rustdoc + [check] cranelift + [check] gcc + [check] Clippy + [check] Miri + [check] CargoMiri + [check] MiroptTestTools + [check] Rustfmt + [check] rust-analyzer + [check] TestFloatParse + [check] FeaturesStatusDump + [check] std + "); + } + #[test] fn check_library_no_explicit_stage() { let ctx = TestCtx::new(); @@ -1348,6 +1380,21 @@ mod snapshot { "); } + #[test] + fn check_library_cross_compile() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("check") + .paths(&["core", "alloc", "std"]) + .targets(&[TEST_TRIPLE_1, TEST_TRIPLE_2]) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [check] std + [check] std + "); + } + #[test] fn check_miri_no_explicit_stage() { let ctx = TestCtx::new(); From 3f3c49813706e692ccabd7d8fac990f7b9525699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 2 Jul 2025 12:18:56 +0200 Subject: [PATCH 8/8] Apply review comments --- src/bootstrap/src/core/builder/mod.rs | 2 ++ src/bootstrap/src/core/builder/tests.rs | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index 930efaf0f45b3..b96a988cde3ff 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -186,6 +186,8 @@ impl StepMetadata { pub fn get_stage(&self) -> Option { self.stage.or(self .built_by + // For std, its stage corresponds to the stage of the compiler that builds it. + // For everything else, a stage N things gets built by a stage N-1 compiler. .map(|compiler| if self.name == "std" { compiler.stage } else { compiler.stage + 1 })) } } diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index a6a147682db1d..1c5267cb75e9b 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1667,8 +1667,7 @@ fn render_metadata(metadata: &StepMetadata) -> String { if let Some(compiler) = metadata.built_by { write!(record, "{} -> ", render_compiler(compiler)); } - let stage = - if let Some(stage) = metadata.get_stage() { format!("{stage} ") } else { "".to_string() }; + let stage = metadata.get_stage().map(|stage| format!("{stage} ")).unwrap_or_default(); write!(record, "{} {stage}<{}>", metadata.name, normalize_target(metadata.target)); record }