From c2e5c212232f615c6ad1e5a5926dddaff150e218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 26 Aug 2025 09:57:44 +0200 Subject: [PATCH 1/5] Add snapshot test for rustc docs --- src/bootstrap/src/core/builder/tests.rs | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 3c2cb7828501d..8674af1ded05b 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1724,6 +1724,47 @@ mod snapshot { "); } + #[test] + fn dist_rustc_docs() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx + .config("dist") + .path("rustc-docs") + .render_steps(), @r" + [build] rustc 0 -> UnstableBookGen 1 + [build] rustc 0 -> Rustbook 1 + [doc] unstable-book (book) + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 + [doc] book (book) + [doc] book/first-edition (book) + [doc] book/second-edition (book) + [doc] book/2018-edition (book) + [build] rustdoc 1 + [doc] rustc 1 -> standalone 2 + [build] rustc 1 -> rustc 2 + [build] rustdoc 2 + [doc] rustc 2 -> std 2 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [build] rustc 1 -> error-index 2 + [doc] rustc 1 -> error-index 2 + [doc] nomicon (book) + [doc] rustc 1 -> reference (book) 2 + [doc] rustdoc (book) + [doc] rust-by-example (book) + [build] rustc 0 -> LintDocs 1 + [doc] rustc (book) + [doc] cargo (book) + [doc] clippy (book) + [doc] embedded-book (book) + [doc] edition-guide (book) + [doc] style-guide (book) + [doc] rustc 1 -> releases 2 + [build] rustc 0 -> RustInstaller 1 + "); + } + #[test] fn check_compiler_no_explicit_stage() { let ctx = TestCtx::new(); From 31e900b78f6c85b3944bd6644aebe3ba7eff4e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 26 Aug 2025 10:03:00 +0200 Subject: [PATCH 2/5] Add metadata to `dist::JsonDocs` --- src/bootstrap/src/core/build_steps/dist.rs | 7 ++++++- src/bootstrap/src/core/builder/tests.rs | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index 778c3beb50f35..5287aa07fc178 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -96,6 +96,8 @@ impl Step for Docs { } } +/// Builds the `rust-docs-json` installer component. +/// It contains the documentation of the standard library in JSON format. #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct JsonDocs { build_compiler: Compiler, @@ -118,7 +120,6 @@ impl Step for JsonDocs { }); } - /// Builds the `rust-docs-json` installer component. fn run(self, builder: &Builder<'_>) -> Option { let target = self.target; let directory = builder.ensure(crate::core::build_steps::doc::Std::from_build_compiler( @@ -135,6 +136,10 @@ impl Step for JsonDocs { tarball.add_bulk_dir(directory, dest); Some(tarball.generate()) } + + fn metadata(&self) -> Option { + Some(StepMetadata::dist("json-docs", self.target).built_by(self.build_compiler)) + } } /// Builds the `rustc-docs` installer component. diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 8674af1ded05b..5c8cec4615df9 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1142,6 +1142,7 @@ mod snapshot { [build] rustc 0 -> RustInstaller 1 [dist] docs [doc] rustc 2 -> std 2 crates=[] + [dist] rustc 2 -> json-docs 3 [dist] mingw [build] rustc 0 -> GenerateCopyright 1 [dist] rustc @@ -1205,6 +1206,7 @@ mod snapshot { [build] rustc 0 -> RustInstaller 1 [dist] docs [doc] rustc 2 -> std 2 crates=[] + [dist] rustc 2 -> json-docs 3 [dist] mingw [build] rustc 1 -> rust-analyzer-proc-macro-srv 2 [build] rustc 0 -> GenerateCopyright 1 @@ -1291,7 +1293,9 @@ mod snapshot { [dist] docs [dist] docs [doc] rustc 2 -> std 2 crates=[] + [dist] rustc 2 -> json-docs 3 [doc] rustc 2 -> std 2 crates=[] + [dist] rustc 2 -> json-docs 3 [dist] mingw [dist] mingw [build] rustc 0 -> GenerateCopyright 1 @@ -1353,6 +1357,7 @@ mod snapshot { [build] rustc 0 -> RustInstaller 1 [dist] docs [doc] rustc 2 -> std 2 crates=[] + [dist] rustc 2 -> json-docs 3 [dist] mingw [build] rustc 0 -> GenerateCopyright 1 [dist] rustc @@ -1433,7 +1438,9 @@ mod snapshot { [dist] docs [dist] docs [doc] rustc 2 -> std 2 crates=[] + [dist] rustc 2 -> json-docs 3 [doc] rustc 2 -> std 2 crates=[] + [dist] rustc 2 -> json-docs 3 [dist] mingw [dist] mingw [build] rustc 0 -> GenerateCopyright 1 @@ -1489,6 +1496,7 @@ mod snapshot { [build] rustc 0 -> RustInstaller 1 [dist] docs [doc] rustc 2 -> std 2 crates=[] + [dist] rustc 2 -> json-docs 3 [dist] mingw [build] rustc 2 -> std 2 [dist] rustc 2 -> std 2 @@ -1543,6 +1551,7 @@ mod snapshot { [build] rustc 0 -> RustInstaller 1 [dist] docs [doc] rustc 2 -> std 2 crates=[] + [dist] rustc 2 -> json-docs 3 [dist] mingw [build] rustdoc 2 [build] rustc 1 -> rust-analyzer-proc-macro-srv 2 @@ -1567,6 +1576,7 @@ mod snapshot { [dist] rustc 1 -> miri 2 [build] rustc 1 -> LlvmBitcodeLinker 2 [doc] rustc 2 -> std 2 crates=[] + [dist] rustc 2 -> json-docs 3 [dist] rustc 1 -> extended 2 [dist] reproducible-artifacts "); @@ -1684,6 +1694,7 @@ mod snapshot { [build] rustc 0 -> RustInstaller 1 [dist] docs [doc] rustc 2 -> std 2 crates=[] + [dist] rustc 2 -> json-docs 3 [dist] mingw [build] rustc 0 -> GenerateCopyright 1 [dist] rustc From edcdb80914c9bc32bf3901ca68ff76d122cd2286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 26 Aug 2025 10:13:55 +0200 Subject: [PATCH 3/5] Add `compiler_for_std` --- src/bootstrap/src/core/build_steps/compile.rs | 2 +- src/bootstrap/src/core/build_steps/dist.rs | 2 +- src/bootstrap/src/core/build_steps/doc.rs | 4 +++- src/bootstrap/src/core/builder/mod.rs | 8 ++++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index d30005c8d51d9..bc978e1c4d061 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -150,7 +150,7 @@ impl Step for Std { trace!(force_recompile); run.builder.ensure(Std { - build_compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()), + build_compiler: run.builder.compiler_for_std(run.builder.top_stage, run.target), target: run.target, crates, force_recompile, diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index 5287aa07fc178..1320c3f65d5d1 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -115,7 +115,7 @@ impl Step for JsonDocs { fn make_run(run: RunConfig<'_>) { run.builder.ensure(JsonDocs { - build_compiler: run.builder.compiler(run.builder.top_stage, run.builder.host_target), + build_compiler: run.builder.compiler_for_std(run.builder.top_stage, run.target), target: run.target, }); } diff --git a/src/bootstrap/src/core/build_steps/doc.rs b/src/bootstrap/src/core/build_steps/doc.rs index 8c20c8c479af0..379d997e1f2cb 100644 --- a/src/bootstrap/src/core/build_steps/doc.rs +++ b/src/bootstrap/src/core/build_steps/doc.rs @@ -616,7 +616,9 @@ impl Step for Std { return; } run.builder.ensure(Std { - build_compiler: run.builder.compiler(run.builder.top_stage, run.builder.host_target), + build_compiler: run + .builder + .compiler_for_std(run.builder.top_stage, run.builder.host_target), target: run.target, format: if run.builder.config.cmd.json() { DocumentationFormat::Json diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index f794f4e079aeb..02ca1a335163e 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -1360,6 +1360,14 @@ impl<'a> Builder<'a> { self.ensure(compile::Assemble { target_compiler: Compiler::new(stage, host) }) } + pub fn compiler_for_std(&self, stage: u32, target: TargetSelection) -> Compiler { + if compile::Std::should_be_uplifted_from_stage_1(self, stage, target) { + self.compiler(1, self.host_target) + } else { + self.compiler(stage, self.host_target) + } + } + /// Similar to `compiler`, except handles the full-bootstrap option to /// silently use the stage1 compiler instead of a stage2 compiler if one is /// requested. From 41563c7d4a0e54a414502f727df9b9caa737da39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 26 Aug 2025 22:42:04 +0200 Subject: [PATCH 4/5] Use `compiler_for_std` in `dist::Std` --- src/bootstrap/src/core/build_steps/compile.rs | 4 +- src/bootstrap/src/core/build_steps/dist.rs | 17 +--- src/bootstrap/src/core/builder/mod.rs | 15 ++++ src/bootstrap/src/core/builder/tests.rs | 82 +++++++++---------- 4 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index bc978e1c4d061..72069df4cbd3b 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -150,7 +150,9 @@ impl Step for Std { trace!(force_recompile); run.builder.ensure(Std { - build_compiler: run.builder.compiler_for_std(run.builder.top_stage, run.target), + // Note: we don't use compiler_for_std here, so that `x build library --stage 2` + // builds a stage2 rustc. + build_compiler: run.builder.compiler(run.builder.top_stage, builder.host_target), target: run.target, crates, force_recompile, diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index 1320c3f65d5d1..a76bef93317fe 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -769,22 +769,7 @@ pub struct Std { impl Std { pub fn new(builder: &Builder<'_>, target: TargetSelection) -> Self { - // This is an important optimization mainly for CI. - // Normally, to build stage N libstd, we need stage N rustc. - // However, if we know that we will uplift libstd from stage 1 anyway, building the stage N - // rustc can be wasteful. - // In particular, if we do a cross-compiling dist stage 2 build from T1 to T2, we need: - // - stage 2 libstd for T2 (uplifted from stage 1, where it was built by T1 rustc) - // - stage 2 rustc for T2 - // However, without this optimization, we would also build stage 2 rustc for **T1**, which - // is completely wasteful. - let build_compiler = - if compile::Std::should_be_uplifted_from_stage_1(builder, builder.top_stage, target) { - builder.compiler(1, builder.host_target) - } else { - builder.compiler(builder.top_stage, builder.host_target) - }; - Std { build_compiler, target } + Std { build_compiler: builder.compiler_for_std(builder.top_stage, target), target } } } diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index 02ca1a335163e..4f37e0edbaddd 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -1360,6 +1360,21 @@ impl<'a> Builder<'a> { self.ensure(compile::Assemble { target_compiler: Compiler::new(stage, host) }) } + /// This function can be used to provide a build compiler for building + /// the standard library, in order to avoid unnecessary rustc builds in case where std uplifting + /// would happen anyway. + /// + /// This is an important optimization mainly for CI. + /// + /// Normally, to build stage N libstd, we need stage N rustc. + /// However, if we know that we will uplift libstd from stage 1 anyway, building the stage N + /// rustc can be wasteful. + /// In particular, if we do a cross-compiling dist stage 2 build from target1 to target2, + /// we need: + /// - stage 2 libstd for target2 (uplifted from stage 1, where it was built by target1 rustc) + /// - stage 2 rustc for target2 + /// However, without this optimization, we would also build stage 2 rustc for **target1**, + /// which is completely wasteful. pub fn compiler_for_std(&self, stage: u32, target: TargetSelection) -> Compiler { if compile::Std::should_be_uplifted_from_stage_1(self, stage, target) { self.compiler(1, self.host_target) diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 5c8cec4615df9..491df10519a34 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1122,9 +1122,8 @@ mod snapshot { [doc] book/2018-edition (book) [build] rustdoc 1 [doc] rustc 1 -> standalone 2 + [doc] rustc 1 -> std 1 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> rustc 2 - [build] rustdoc 2 - [doc] rustc 2 -> std 2 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> error-index 2 [doc] rustc 1 -> error-index 2 [doc] nomicon (book) @@ -1141,9 +1140,10 @@ mod snapshot { [doc] rustc 1 -> releases 2 [build] rustc 0 -> RustInstaller 1 [dist] docs - [doc] rustc 2 -> std 2 crates=[] - [dist] rustc 2 -> json-docs 3 + [doc] rustc 1 -> std 1 crates=[] + [dist] rustc 1 -> json-docs 2 [dist] mingw + [build] rustdoc 2 [build] rustc 0 -> GenerateCopyright 1 [dist] rustc [dist] rustc 1 -> std 1 @@ -1183,12 +1183,11 @@ mod snapshot { [doc] book/2018-edition (book) [build] rustdoc 1 [doc] rustc 1 -> standalone 2 + [doc] rustc 1 -> std 1 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> rustc 2 [build] rustc 1 -> LldWrapper 2 [build] rustc 1 -> WasmComponentLd 2 [build] rustc 1 -> LlvmBitcodeLinker 2 - [build] rustdoc 2 - [doc] rustc 2 -> std 2 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> error-index 2 [doc] rustc 1 -> error-index 2 [doc] nomicon (book) @@ -1205,9 +1204,10 @@ mod snapshot { [doc] rustc 1 -> releases 2 [build] rustc 0 -> RustInstaller 1 [dist] docs - [doc] rustc 2 -> std 2 crates=[] - [dist] rustc 2 -> json-docs 3 + [doc] rustc 1 -> std 1 crates=[] + [dist] rustc 1 -> json-docs 2 [dist] mingw + [build] rustdoc 2 [build] rustc 1 -> rust-analyzer-proc-macro-srv 2 [build] rustc 0 -> GenerateCopyright 1 [dist] rustc @@ -1228,6 +1228,8 @@ mod snapshot { [build] rustc 1 -> miri 2 [build] rustc 1 -> cargo-miri 2 [dist] rustc 1 -> miri 2 + [doc] rustc 2 -> std 2 crates=[] + [dist] rustc 2 -> json-docs 3 [dist] rustc 1 -> extended 2 [dist] reproducible-artifacts "); @@ -1261,10 +1263,9 @@ mod snapshot { [doc] book/2018-edition (book) [doc] rustc 1 -> standalone 2 [doc] rustc 1 -> standalone 2 + [doc] rustc 1 -> std 1 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 1 -> std 1 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> rustc 2 - [build] rustdoc 2 - [doc] rustc 2 -> std 2 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] - [doc] rustc 2 -> std 2 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> error-index 2 [doc] rustc 1 -> error-index 2 [doc] nomicon (book) @@ -1292,8 +1293,9 @@ mod snapshot { [build] rustc 0 -> RustInstaller 1 [dist] docs [dist] docs - [doc] rustc 2 -> std 2 crates=[] - [dist] rustc 2 -> json-docs 3 + [doc] rustc 1 -> std 1 crates=[] + [dist] rustc 1 -> json-docs 2 + [build] rustdoc 2 [doc] rustc 2 -> std 2 crates=[] [dist] rustc 2 -> json-docs 3 [dist] mingw @@ -1331,9 +1333,8 @@ mod snapshot { [doc] book/2018-edition (book) [build] rustdoc 1 [doc] rustc 1 -> standalone 2 + [doc] rustc 1 -> std 1 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> rustc 2 - [build] rustdoc 2 - [doc] rustc 2 -> std 2 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> error-index 2 [doc] rustc 1 -> error-index 2 [build] llvm @@ -1356,9 +1357,10 @@ mod snapshot { [doc] rustc 1 -> releases 2 [build] rustc 0 -> RustInstaller 1 [dist] docs - [doc] rustc 2 -> std 2 crates=[] - [dist] rustc 2 -> json-docs 3 + [doc] rustc 1 -> std 1 crates=[] + [dist] rustc 1 -> json-docs 2 [dist] mingw + [build] rustdoc 2 [build] rustc 0 -> GenerateCopyright 1 [dist] rustc [build] rustdoc 2 @@ -1401,10 +1403,9 @@ mod snapshot { [doc] book/2018-edition (book) [doc] rustc 1 -> standalone 2 [doc] rustc 1 -> standalone 2 + [doc] rustc 1 -> std 1 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 1 -> std 1 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> rustc 2 - [build] rustdoc 2 - [doc] rustc 2 -> std 2 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] - [doc] rustc 2 -> std 2 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> error-index 2 [doc] rustc 1 -> error-index 2 [build] llvm @@ -1437,12 +1438,13 @@ mod snapshot { [build] rustc 0 -> RustInstaller 1 [dist] docs [dist] docs - [doc] rustc 2 -> std 2 crates=[] - [dist] rustc 2 -> json-docs 3 - [doc] rustc 2 -> std 2 crates=[] - [dist] rustc 2 -> json-docs 3 + [doc] rustc 1 -> std 1 crates=[] + [dist] rustc 1 -> json-docs 2 + [doc] rustc 1 -> std 1 crates=[] + [dist] rustc 1 -> json-docs 2 [dist] mingw [dist] mingw + [build] rustdoc 2 [build] rustc 0 -> GenerateCopyright 1 [dist] rustc [build] rustdoc 2 @@ -1480,9 +1482,7 @@ mod snapshot { [build] rustdoc 1 [build] rustc 1 -> std 1 [doc] rustc 1 -> standalone 2 - [build] rustc 1 -> rustc 2 - [build] rustdoc 2 - [doc] rustc 2 -> std 2 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 1 -> std 1 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [doc] nomicon (book) [doc] rustc 1 -> reference (book) 2 [doc] rustdoc (book) @@ -1495,6 +1495,8 @@ mod snapshot { [doc] rustc 1 -> releases 2 [build] rustc 0 -> RustInstaller 1 [dist] docs + [build] rustc 1 -> rustc 2 + [build] rustdoc 2 [doc] rustc 2 -> std 2 crates=[] [dist] rustc 2 -> json-docs 3 [dist] mingw @@ -1527,10 +1529,7 @@ mod snapshot { [build] rustdoc 1 [build] rustc 1 -> std 1 [doc] rustc 1 -> standalone 2 - [build] rustc 1 -> rustc 2 - [build] rustc 1 -> WasmComponentLd 2 - [build] rustdoc 2 - [doc] rustc 2 -> std 2 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 1 -> std 1 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] llvm [build] rustc 1 -> rustc 2 [build] rustc 1 -> WasmComponentLd 2 @@ -1550,8 +1549,8 @@ mod snapshot { [doc] rustc 1 -> releases 2 [build] rustc 0 -> RustInstaller 1 [dist] docs - [doc] rustc 2 -> std 2 crates=[] - [dist] rustc 2 -> json-docs 3 + [doc] rustc 1 -> std 1 crates=[] + [dist] rustc 1 -> json-docs 2 [dist] mingw [build] rustdoc 2 [build] rustc 1 -> rust-analyzer-proc-macro-srv 2 @@ -1583,7 +1582,7 @@ mod snapshot { } /// 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. + /// not build docs. Crucially, it shouldn't build host stage 2 rustc. /// /// This is a regression test for /// and . @@ -1673,10 +1672,9 @@ mod snapshot { [doc] book/2018-edition (book) [build] rustdoc 1 [doc] rustc 1 -> standalone 2 + [doc] rustc 1 -> std 1 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> rustc 2 [build] rustc 1 -> rustc_codegen_cranelift 2 - [build] rustdoc 2 - [doc] rustc 2 -> std 2 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> error-index 2 [doc] rustc 1 -> error-index 2 [doc] nomicon (book) @@ -1693,9 +1691,10 @@ mod snapshot { [doc] rustc 1 -> releases 2 [build] rustc 0 -> RustInstaller 1 [dist] docs - [doc] rustc 2 -> std 2 crates=[] - [dist] rustc 2 -> json-docs 3 + [doc] rustc 1 -> std 1 crates=[] + [dist] rustc 1 -> json-docs 2 [dist] mingw + [build] rustdoc 2 [build] rustc 0 -> GenerateCopyright 1 [dist] rustc [dist] rustc 1 -> rustc_codegen_cranelift 2 @@ -1755,9 +1754,8 @@ mod snapshot { [doc] book/2018-edition (book) [build] rustdoc 1 [doc] rustc 1 -> standalone 2 + [doc] rustc 1 -> std 1 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> rustc 2 - [build] rustdoc 2 - [doc] rustc 2 -> std 2 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> error-index 2 [doc] rustc 1 -> error-index 2 [doc] nomicon (book) @@ -2467,10 +2465,9 @@ mod snapshot { [doc] book/2018-edition (book) [build] rustdoc 1 [doc] rustc 1 -> standalone 2 + [doc] rustc 1 -> std 1 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> rustc 2 [build] rustc 1 -> WasmComponentLd 2 - [build] rustdoc 2 - [doc] rustc 2 -> std 2 crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 -> error-index 2 [doc] rustc 1 -> error-index 2 [doc] nomicon (book) @@ -2488,6 +2485,7 @@ mod snapshot { [build] rustc 0 -> RustInstaller 1 [dist] docs [dist] rustc 1 -> std 1 + [build] rustdoc 2 [build] rustc 1 -> rust-analyzer-proc-macro-srv 2 [build] rustc 0 -> GenerateCopyright 1 [dist] rustc From 6864a5bf42baeb64d23f0b086152a9c2893b5ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 26 Aug 2025 23:00:54 +0200 Subject: [PATCH 5/5] Use std uplifting more often --- src/bootstrap/src/core/build_steps/compile.rs | 28 ++++--------------- src/bootstrap/src/core/build_steps/dist.rs | 4 +-- src/bootstrap/src/core/build_steps/doc.rs | 4 +-- src/bootstrap/src/core/builder/mod.rs | 5 ++-- src/bootstrap/src/core/builder/tests.rs | 19 ++++++------- 5 files changed, 20 insertions(+), 40 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 72069df4cbd3b..0b75e85772f86 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -99,28 +99,12 @@ impl Std { deps } - /// Returns true if the standard library will be uplifted from stage 1 for the given - /// `build_compiler` (which determines the stdlib stage) and `target`. + /// Returns true if the standard library should be uplifted from stage 1. /// - /// Uplifting is enabled if we're building a stage2+ libstd, full bootstrap is - /// disabled and we have a stage1 libstd already compiled for the given target. - pub fn should_be_uplifted_from_stage_1( - builder: &Builder<'_>, - stage: u32, - target: TargetSelection, - ) -> bool { - stage > 1 - && !builder.config.full_bootstrap - // This estimates if a stage1 libstd exists for the given target. If we're not - // cross-compiling, it should definitely exist by the time we're building a stage2 - // libstd. - // Or if we are cross-compiling, and we are building a cross-compiled rustc, then that - // rustc needs to link to a cross-compiled libstd, so again we should have a stage1 - // libstd for the given target prepared. - // Even if we guess wrong in the cross-compiled case, the worst that should happen is - // that we build a fresh stage1 libstd below, and then we immediately uplift it, so we - // don't pay the libstd build cost twice. - && (target == builder.host_target || builder.config.hosts.contains(&target)) + /// Uplifting is enabled if we're building a stage2+ libstd and full bootstrap is + /// disabled. + pub fn should_be_uplifted_from_stage_1(builder: &Builder<'_>, stage: u32) -> bool { + stage > 1 && !builder.config.full_bootstrap } } @@ -228,7 +212,7 @@ impl Step for Std { // Stage of the stdlib that we're building let stage = build_compiler.stage; - if Self::should_be_uplifted_from_stage_1(builder, build_compiler.stage, target) { + if Self::should_be_uplifted_from_stage_1(builder, build_compiler.stage) { let build_compiler_for_std_to_uplift = builder.compiler(1, builder.host_target); let stage_1_stamp = builder.std(build_compiler_for_std_to_uplift, target); diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index a76bef93317fe..f113dd7683d87 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -115,7 +115,7 @@ impl Step for JsonDocs { fn make_run(run: RunConfig<'_>) { run.builder.ensure(JsonDocs { - build_compiler: run.builder.compiler_for_std(run.builder.top_stage, run.target), + build_compiler: run.builder.compiler_for_std(run.builder.top_stage), target: run.target, }); } @@ -769,7 +769,7 @@ pub struct Std { impl Std { pub fn new(builder: &Builder<'_>, target: TargetSelection) -> Self { - Std { build_compiler: builder.compiler_for_std(builder.top_stage, target), target } + Std { build_compiler: builder.compiler_for_std(builder.top_stage), target } } } diff --git a/src/bootstrap/src/core/build_steps/doc.rs b/src/bootstrap/src/core/build_steps/doc.rs index 379d997e1f2cb..9ef1fee1fecc5 100644 --- a/src/bootstrap/src/core/build_steps/doc.rs +++ b/src/bootstrap/src/core/build_steps/doc.rs @@ -616,9 +616,7 @@ impl Step for Std { return; } run.builder.ensure(Std { - build_compiler: run - .builder - .compiler_for_std(run.builder.top_stage, run.builder.host_target), + build_compiler: run.builder.compiler_for_std(run.builder.top_stage), target: run.target, format: if run.builder.config.cmd.json() { DocumentationFormat::Json diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index 4f37e0edbaddd..b224a7e73221d 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -1373,10 +1373,11 @@ impl<'a> Builder<'a> { /// we need: /// - stage 2 libstd for target2 (uplifted from stage 1, where it was built by target1 rustc) /// - stage 2 rustc for target2 + /// /// However, without this optimization, we would also build stage 2 rustc for **target1**, /// which is completely wasteful. - pub fn compiler_for_std(&self, stage: u32, target: TargetSelection) -> Compiler { - if compile::Std::should_be_uplifted_from_stage_1(self, stage, target) { + pub fn compiler_for_std(&self, stage: u32) -> Compiler { + if compile::Std::should_be_uplifted_from_stage_1(self, stage) { self.compiler(1, self.host_target) } else { self.compiler(stage, self.host_target) diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 491df10519a34..b079117c5a7d1 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1066,6 +1066,7 @@ mod snapshot { [build] rustc 1 -> rustc 2 [build] rustc 2 -> std 2 [build] rustc 2 -> std 2 + [build] rustc 1 -> std 1 [build] rustc 2 -> std 2 "); } @@ -1295,16 +1296,15 @@ mod snapshot { [dist] docs [doc] rustc 1 -> std 1 crates=[] [dist] rustc 1 -> json-docs 2 - [build] rustdoc 2 - [doc] rustc 2 -> std 2 crates=[] - [dist] rustc 2 -> json-docs 3 + [doc] rustc 1 -> std 1 crates=[] + [dist] rustc 1 -> json-docs 2 [dist] mingw [dist] mingw + [build] rustdoc 2 [build] rustc 0 -> GenerateCopyright 1 [dist] rustc [dist] rustc 1 -> std 1 - [build] rustc 2 -> std 2 - [dist] rustc 2 -> std 2 + [dist] rustc 1 -> std 1 [dist] rustc 1 -> rustc-dev 2 [dist] src <> [dist] reproducible-artifacts @@ -1495,13 +1495,10 @@ mod snapshot { [doc] rustc 1 -> releases 2 [build] rustc 0 -> RustInstaller 1 [dist] docs - [build] rustc 1 -> rustc 2 - [build] rustdoc 2 - [doc] rustc 2 -> std 2 crates=[] - [dist] rustc 2 -> json-docs 3 + [doc] rustc 1 -> std 1 crates=[] + [dist] rustc 1 -> json-docs 2 [dist] mingw - [build] rustc 2 -> std 2 - [dist] rustc 2 -> std 2 + [dist] rustc 1 -> std 1 "); }