diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index 567416d079b12..6c5f70b2f4381 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)] @@ -315,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)] @@ -373,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, @@ -432,6 +448,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 { @@ -467,6 +487,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/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..b96a988cde3ff 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) } @@ -178,6 +182,14 @@ impl StepMetadata { self.stage = Some(stage); self } + + 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 })) + } } pub struct RunConfig<'a> { diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 8adf93ea52889..1c5267cb75e9b 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 @@ -1233,6 +1233,289 @@ 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 + [check] cranelift + [check] gcc + "); + + insta::assert_snapshot!( + ctx.config("check") + .path("rustc") + .render_steps(), @r" + [check] std + [build] llvm + [check] rustc + "); + } + + #[test] + 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 + [check] cranelift + [check] gcc + "); + } + + #[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 + [check] cranelift + [check] gcc + "); + } + + #[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(); + insta::assert_snapshot!( + ctx.config("check") + .path("library") + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [check] std + "); + } + + #[test] + 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_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(); + insta::assert_snapshot!( + ctx.config("check") + .path("miri") + .render_steps(), @r" + [check] std + [build] llvm + [check] rustc + [check] Miri + "); + } + + #[test] + 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 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 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 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 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(); @@ -1384,7 +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.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 }