Skip to content

Commit 06a24e9

Browse files
committed
Auto merge of rust-lang#136586 - Kobzol:lto-rustdoc-fix-stage-1, r=onur-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`
2 parents 8c61cd4 + cfa3518 commit 06a24e9

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1105,9 +1105,7 @@ pub fn rustc_cargo(
11051105
cargo.rustflag("-Zdefault-visibility=protected");
11061106
}
11071107

1108-
// We currently don't support cross-crate LTO in stage0. This also isn't hugely necessary
1109-
// and may just be a time sink.
1110-
if compiler.stage != 0 {
1108+
if is_lto_stage(compiler) {
11111109
match builder.config.rust_lto {
11121110
RustcLto::Thin | RustcLto::Fat => {
11131111
// Since using LTO for optimizing dylibs is currently experimental,
@@ -2335,3 +2333,8 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
23352333
// everything else (standard library, future stages...) to be rebuilt.
23362334
t!(file.set_modified(previous_mtime));
23372335
}
2336+
2337+
/// We only use LTO for stage 2+, to speed up build time of intermediate stages.
2338+
pub fn is_lto_stage(build_compiler: &Compiler) -> bool {
2339+
build_compiler.stage != 0
2340+
}

src/bootstrap/src/core/build_steps/tool.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::path::PathBuf;
22
use std::{env, fs};
33

4+
use crate::core::build_steps::compile::is_lto_stage;
45
use crate::core::build_steps::toolstate::ToolState;
56
use crate::core::build_steps::{compile, llvm};
67
use crate::core::builder;
@@ -659,14 +660,16 @@ impl Step for Rustdoc {
659660
);
660661

661662
// rustdoc is performance sensitive, so apply LTO to it.
662-
let lto = match builder.config.rust_lto {
663-
RustcLto::Off => Some("off"),
664-
RustcLto::Thin => Some("thin"),
665-
RustcLto::Fat => Some("fat"),
666-
RustcLto::ThinLocal => None,
667-
};
668-
if let Some(lto) = lto {
669-
cargo.env(cargo_profile_var("LTO", &builder.config), lto);
663+
if is_lto_stage(&build_compiler) {
664+
let lto = match builder.config.rust_lto {
665+
RustcLto::Off => Some("off"),
666+
RustcLto::Thin => Some("thin"),
667+
RustcLto::Fat => Some("fat"),
668+
RustcLto::ThinLocal => None,
669+
};
670+
if let Some(lto) = lto {
671+
cargo.env(cargo_profile_var("LTO", &builder.config), lto);
672+
}
670673
}
671674

672675
let _guard = builder.msg_tool(

0 commit comments

Comments
 (0)