Skip to content

Commit cfa3518

Browse files
committed
Only apply LTO to rustdoc at stage 2
It doesn't make much sense at stage 1, and it was broken anyway.
1 parent 820bfff commit cfa3518

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
@@ -1064,9 +1064,7 @@ pub fn rustc_cargo(
10641064
cargo.rustflag("-Zdefault-visibility=protected");
10651065
}
10661066

1067-
// We currently don't support cross-crate LTO in stage0. This also isn't hugely necessary
1068-
// and may just be a time sink.
1069-
if compiler.stage != 0 {
1067+
if is_lto_stage(compiler) {
10701068
match builder.config.rust_lto {
10711069
RustcLto::Thin | RustcLto::Fat => {
10721070
// Since using LTO for optimizing dylibs is currently experimental,
@@ -2290,3 +2288,8 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
22902288
// everything else (standard library, future stages...) to be rebuilt.
22912289
t!(file.set_modified(previous_mtime));
22922290
}
2291+
2292+
/// We only use LTO for stage 2+, to speed up build time of intermediate stages.
2293+
pub fn is_lto_stage(build_compiler: &Compiler) -> bool {
2294+
build_compiler.stage != 0
2295+
}

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;
@@ -660,14 +661,16 @@ impl Step for Rustdoc {
660661
);
661662

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

673676
let _guard = builder.msg_tool(

0 commit comments

Comments
 (0)