Skip to content

Commit

Permalink
Auto merge of rust-lang#136586 - Kobzol:lto-rustdoc-fix-stage-1, r=on…
Browse files Browse the repository at this point in the history
…ur-ozkan

Only apply LTO to rustdoc at stage 2

It doesn't make much sense at stage 1, and it was broken anyway. This was implemented in rust-lang#135832. The issue with LTO and stage 1 rustdoc was reported [here](https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/x.20test.20with.20lto.20.3D.20.22thin.22.20fails.20to.20build.20rustdoc.3F).

r? `@onur-ozkan`
  • Loading branch information
bors committed Feb 11, 2025
2 parents 8c61cd4 + cfa3518 commit 06a24e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,9 +1105,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,
Expand Down Expand Up @@ -2335,3 +2333,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
}
19 changes: 11 additions & 8 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -659,14 +660,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(
Expand Down

0 comments on commit 06a24e9

Please sign in to comment.