Apply LTO config to rustdoc

Before, the LTO configuration from `config.toml` was not applied to `rustdoc`.
This commit is contained in:
Jakub Beránek 2025-01-21 17:22:18 +01:00
parent b605c65b6e
commit 1fe351baae
No known key found for this signature in database
GPG key ID: 909CD0D26483516B
4 changed files with 29 additions and 9 deletions

View file

@ -4,8 +4,10 @@ use std::{env, fs};
use crate::core::build_steps::toolstate::ToolState;
use crate::core::build_steps::{compile, llvm};
use crate::core::builder;
use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
use crate::core::config::{DebuginfoLevel, TargetSelection};
use crate::core::builder::{
Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step, cargo_profile_var,
};
use crate::core::config::{DebuginfoLevel, RustcLto, TargetSelection};
use crate::utils::channel::GitInfo;
use crate::utils::exec::{BootstrapCommand, command};
use crate::utils::helpers::{add_dylib_path, exe, t};
@ -645,7 +647,7 @@ impl Step for Rustdoc {
}
// NOTE: Never modify the rustflags here, it breaks the build cache for other tools!
let cargo = prepare_tool_cargo(
let mut cargo = prepare_tool_cargo(
builder,
build_compiler,
Mode::ToolRustc,
@ -656,6 +658,17 @@ impl Step for Rustdoc {
features.as_slice(),
);
// 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);
}
let _guard = builder.msg_tool(
Kind::Build,
Mode::ToolRustc,

View file

@ -10,7 +10,7 @@ use crate::core::config::flags::Color;
use crate::utils::build_stamp;
use crate::utils::helpers::{self, LldThreads, check_cfg_arg, linker_args, linker_flags};
use crate::{
BootstrapCommand, CLang, Compiler, DocTests, DryRun, EXTRA_CHECK_CFGS, GitRepo, Mode,
BootstrapCommand, CLang, Compiler, Config, DocTests, DryRun, EXTRA_CHECK_CFGS, GitRepo, Mode,
TargetSelection, command, prepare_behaviour_dump_dir, t,
};
@ -473,10 +473,7 @@ impl Builder<'_> {
build_stamp::clear_if_dirty(self, &my_out, &rustdoc);
}
let profile_var = |name: &str| {
let profile = if self.config.rust_optimize.is_release() { "RELEASE" } else { "DEV" };
format!("CARGO_PROFILE_{}_{}", profile, name)
};
let profile_var = |name: &str| cargo_profile_var(name, &self.config);
// See comment in rustc_llvm/build.rs for why this is necessary, largely llvm-config
// needs to not accidentally link to libLLVM in stage0/lib.
@ -1221,3 +1218,8 @@ impl Builder<'_> {
}
}
}
pub fn cargo_profile_var(name: &str, config: &Config) -> String {
let profile = if config.rust_optimize.is_release() { "RELEASE" } else { "DEV" };
format!("CARGO_PROFILE_{}_{}", profile, name)
}

View file

@ -11,7 +11,7 @@ use std::{env, fs};
use clap::ValueEnum;
pub use self::cargo::Cargo;
pub use self::cargo::{Cargo, cargo_profile_var};
pub use crate::Compiler;
use crate::core::build_steps::{
check, clean, clippy, compile, dist, doc, gcc, install, llvm, run, setup, test, tool, vendor,

View file

@ -340,4 +340,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Info,
summary: "Change the compiler profile to default to rust.debug-assertions = true",
},
ChangeInfo {
change_id: 135832,
severity: ChangeSeverity::Info,
summary: "Rustdoc now respects the value of rust.lto.",
},
];