about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakub Beránek <berykubik@gmail.com>2025-02-05 16:48:01 +0100
committerJakub Beránek <berykubik@gmail.com>2025-02-05 22:21:22 +0100
commitcfa351895108a5d60237b5549f05911852c40ad1 (patch)
tree978b0cc0a3d1391d510b80cf3538809c70e75ae0
parent820bfffc25fee9866aa8176529091e04b8824f09 (diff)
downloadrust-cfa351895108a5d60237b5549f05911852c40ad1.tar.gz
rust-cfa351895108a5d60237b5549f05911852c40ad1.zip
Only apply LTO to rustdoc at stage 2
It doesn't make much sense at stage 1, and it was broken anyway.
-rw-r--r--src/bootstrap/src/core/build_steps/compile.rs9
-rw-r--r--src/bootstrap/src/core/build_steps/tool.rs19
2 files changed, 17 insertions, 11 deletions
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs
index cd3558ac6a4..dcc587c42ce 100644
--- a/src/bootstrap/src/core/build_steps/compile.rs
+++ b/src/bootstrap/src/core/build_steps/compile.rs
@@ -1064,9 +1064,7 @@ pub fn rustc_cargo(
         cargo.rustflag("-Zdefault-visibility=protected");
     }
 
-    // We currently don't support cross-crate LTO in stage0. This also isn't hugely necessary
-    // and may just be a time sink.
-    if compiler.stage != 0 {
+    if is_lto_stage(compiler) {
         match builder.config.rust_lto {
             RustcLto::Thin | RustcLto::Fat => {
                 // Since using LTO for optimizing dylibs is currently experimental,
@@ -2290,3 +2288,8 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
     // everything else (standard library, future stages...) to be rebuilt.
     t!(file.set_modified(previous_mtime));
 }
+
+/// We only use LTO for stage 2+, to speed up build time of intermediate stages.
+pub fn is_lto_stage(build_compiler: &Compiler) -> bool {
+    build_compiler.stage != 0
+}
diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs
index 75fac88252b..64e7a555bbb 100644
--- a/src/bootstrap/src/core/build_steps/tool.rs
+++ b/src/bootstrap/src/core/build_steps/tool.rs
@@ -1,6 +1,7 @@
 use std::path::PathBuf;
 use std::{env, fs};
 
+use crate::core::build_steps::compile::is_lto_stage;
 use crate::core::build_steps::toolstate::ToolState;
 use crate::core::build_steps::{compile, llvm};
 use crate::core::builder;
@@ -660,14 +661,16 @@ impl Step for Rustdoc {
         );
 
         // rustdoc is performance sensitive, so apply LTO to it.
-        let lto = match builder.config.rust_lto {
-            RustcLto::Off => Some("off"),
-            RustcLto::Thin => Some("thin"),
-            RustcLto::Fat => Some("fat"),
-            RustcLto::ThinLocal => None,
-        };
-        if let Some(lto) = lto {
-            cargo.env(cargo_profile_var("LTO", &builder.config), lto);
+        if is_lto_stage(&build_compiler) {
+            let lto = match builder.config.rust_lto {
+                RustcLto::Off => Some("off"),
+                RustcLto::Thin => Some("thin"),
+                RustcLto::Fat => Some("fat"),
+                RustcLto::ThinLocal => None,
+            };
+            if let Some(lto) = lto {
+                cargo.env(cargo_profile_var("LTO", &builder.config), lto);
+            }
         }
 
         let _guard = builder.msg_tool(