Skip to content

Commit 77a4553

Browse files
committed
Auto merge of #135832 - Kobzol:rustdoc-lto, r=onur-ozkan
Apply LTO config to rustdoc Before, the LTO configuration from `config.toml` was not applied to `rustdoc`. This provides a small perf. and binary size [win](#112049 (comment)) for doc builds. Since this is configured with Cargo profiles and not rustflags, it should not break tool build cache (#131155). I tried to run `x test miri`, `x test rustdoc` and `x test miri` and nothing was rebuilt. r? `@onur-ozkan`
2 parents fdd1a3b + 1fe351b commit 77a4553

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

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

+16-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ use std::{env, fs};
44
use crate::core::build_steps::toolstate::ToolState;
55
use crate::core::build_steps::{compile, llvm};
66
use crate::core::builder;
7-
use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
8-
use crate::core::config::{DebuginfoLevel, TargetSelection};
7+
use crate::core::builder::{
8+
Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step, cargo_profile_var,
9+
};
10+
use crate::core::config::{DebuginfoLevel, RustcLto, TargetSelection};
911
use crate::utils::channel::GitInfo;
1012
use crate::utils::exec::{BootstrapCommand, command};
1113
use crate::utils::helpers::{add_dylib_path, exe, t};
@@ -645,7 +647,7 @@ impl Step for Rustdoc {
645647
}
646648

647649
// NOTE: Never modify the rustflags here, it breaks the build cache for other tools!
648-
let cargo = prepare_tool_cargo(
650+
let mut cargo = prepare_tool_cargo(
649651
builder,
650652
build_compiler,
651653
Mode::ToolRustc,
@@ -656,6 +658,17 @@ impl Step for Rustdoc {
656658
features.as_slice(),
657659
);
658660

661+
// 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);
670+
}
671+
659672
let _guard = builder.msg_tool(
660673
Kind::Build,
661674
Mode::ToolRustc,

src/bootstrap/src/core/builder/cargo.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::core::config::flags::Color;
1010
use crate::utils::build_stamp;
1111
use crate::utils::helpers::{self, LldThreads, check_cfg_arg, linker_args, linker_flags};
1212
use crate::{
13-
BootstrapCommand, CLang, Compiler, DocTests, DryRun, EXTRA_CHECK_CFGS, GitRepo, Mode,
13+
BootstrapCommand, CLang, Compiler, Config, DocTests, DryRun, EXTRA_CHECK_CFGS, GitRepo, Mode,
1414
TargetSelection, command, prepare_behaviour_dump_dir, t,
1515
};
1616

@@ -484,10 +484,7 @@ impl Builder<'_> {
484484
build_stamp::clear_if_dirty(self, &my_out, &rustdoc);
485485
}
486486

487-
let profile_var = |name: &str| {
488-
let profile = if self.config.rust_optimize.is_release() { "RELEASE" } else { "DEV" };
489-
format!("CARGO_PROFILE_{}_{}", profile, name)
490-
};
487+
let profile_var = |name: &str| cargo_profile_var(name, &self.config);
491488

492489
// See comment in rustc_llvm/build.rs for why this is necessary, largely llvm-config
493490
// needs to not accidentally link to libLLVM in stage0/lib.
@@ -1232,3 +1229,8 @@ impl Builder<'_> {
12321229
}
12331230
}
12341231
}
1232+
1233+
pub fn cargo_profile_var(name: &str, config: &Config) -> String {
1234+
let profile = if config.rust_optimize.is_release() { "RELEASE" } else { "DEV" };
1235+
format!("CARGO_PROFILE_{}_{}", profile, name)
1236+
}

src/bootstrap/src/core/builder/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{env, fs};
1111

1212
use clap::ValueEnum;
1313

14-
pub use self::cargo::Cargo;
14+
pub use self::cargo::{Cargo, cargo_profile_var};
1515
pub use crate::Compiler;
1616
use crate::core::build_steps::{
1717
check, clean, clippy, compile, dist, doc, gcc, install, llvm, run, setup, test, tool, vendor,

src/bootstrap/src/utils/change_tracker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
340340
severity: ChangeSeverity::Info,
341341
summary: "Change the compiler profile to default to rust.debug-assertions = true",
342342
},
343+
ChangeInfo {
344+
change_id: 135832,
345+
severity: ChangeSeverity::Info,
346+
summary: "Rustdoc now respects the value of rust.lto.",
347+
},
343348
];

0 commit comments

Comments
 (0)