From bb031fcea8a0ade39a9d94bce8a3725373ef56b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 11 Aug 2024 00:47:41 +0200 Subject: [PATCH 1/2] Perform ThinLTO on x86_64-pc-windows-msvc dist builder --- src/ci/github-actions/jobs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index e03ad184842e3..0a66c7905eab1 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -721,6 +721,7 @@ auto: --target=x86_64-pc-windows-msvc --enable-full-tools --enable-profiler + --set rust.lto=thin --set rust.codegen-units=1 SCRIPT: python x.py build --set rust.debug=true opt-dist && PGO_HOST=x86_64-pc-windows-msvc ./build/x86_64-pc-windows-msvc/stage1-tools-bin/opt-dist windows-ci -- python x.py dist bootstrap --include-default-paths DIST_REQUIRE_ALL_TOOLS: 1 From 92be9b20394b522b7206b8567a459311ed862cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 26 Jul 2026 04:54:31 +0200 Subject: [PATCH 2/2] Workaround https://github.com/rust-lang/cargo/issues/14575 when using LTO to build tools --- src/bootstrap/src/core/build_steps/tool.rs | 24 ++++++++++++++-------- src/bootstrap/src/core/builder/mod.rs | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 89143c8e74333..d45b39ed74ae3 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -19,7 +19,7 @@ use crate::core::build_steps::{compile, llvm}; use crate::core::builder; use crate::core::builder::{ Builder, Cargo as CargoCommand, CommandLineStep, RunConfig, ShouldRun, Step, StepMetadata, - apply_pgo, cargo_profile_var, + apply_pgo, }; use crate::core::config::{DebuginfoLevel, OverrideAllocator, RustcLto, TargetSelection}; use crate::utils::exec::{BootstrapCommand, command}; @@ -123,14 +123,20 @@ impl Step for ToolBuild { if is_lto_stage(&self.build_compiler) && (self.mode == Mode::ToolRustcPrivate || self.path == "src/tools/cargo") { - 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, self.mode), lto); + // We don't use Cargo's LTO setting here to workaround https://github.com/rust-lang/cargo/issues/14575 + match builder.config.rust_lto { + RustcLto::Thin => { + cargo.rustflag("-Clto=thin"); + cargo.rustflag("-Cembed-bitcode=yes"); + } + RustcLto::Fat => { + cargo.rustflag("-Clto=fat"); + cargo.rustflag("-Cembed-bitcode=yes"); + } + RustcLto::ThinLocal => { /* Do nothing, this is the default */ } + RustcLto::Off => { + cargo.rustflag("-Clto=off"); + } } } diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index 50188887a5314..9de8ee0b23927 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -13,7 +13,7 @@ use clap::ValueEnum; #[cfg(feature = "tracing")] use tracing::instrument; -pub use self::cargo::{Cargo, apply_pgo, cargo_profile_var}; +pub use self::cargo::{Cargo, apply_pgo}; pub use crate::Compiler; use crate::core::build_steps::compile::{Std, StdLink}; use crate::core::build_steps::tool::RustcPrivateCompilers;