Skip to content

Commit ae64f71

Browse files
committed
Workaround rust-lang/cargo#14575 when using LTO to build tools
1 parent 0602a8e commit ae64f71

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use crate::core::build_steps::{compile, llvm};
1919
use crate::core::builder;
2020
use crate::core::builder::{
2121
Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step, StepMetadata, apply_pgo,
22-
cargo_profile_var,
2322
};
2423
use crate::core::config::{DebuginfoLevel, OverrideAllocator, RustcLto, TargetSelection};
2524
use crate::utils::exec::{BootstrapCommand, command};
@@ -127,14 +126,20 @@ impl Step for ToolBuild {
127126
if is_lto_stage(&self.build_compiler)
128127
&& (self.mode == Mode::ToolRustcPrivate || self.path == "src/tools/cargo")
129128
{
130-
let lto = match builder.config.rust_lto {
131-
RustcLto::Off => Some("off"),
132-
RustcLto::Thin => Some("thin"),
133-
RustcLto::Fat => Some("fat"),
134-
RustcLto::ThinLocal => None,
135-
};
136-
if let Some(lto) = lto {
137-
cargo.env(cargo_profile_var("LTO", &builder.config, self.mode), lto);
129+
// We don't use Cargo's LTO setting here to workaround https://github.com/rust-lang/cargo/issues/14575
130+
match builder.config.rust_lto {
131+
RustcLto::Thin => {
132+
cargo.rustflag("-Clto=thin");
133+
cargo.rustflag("-Cembed-bitcode=yes");
134+
}
135+
RustcLto::Fat => {
136+
cargo.rustflag("-Clto=fat");
137+
cargo.rustflag("-Cembed-bitcode=yes");
138+
}
139+
RustcLto::ThinLocal => { /* Do nothing, this is the default */ }
140+
RustcLto::Off => {
141+
cargo.rustflag("-Clto=off");
142+
}
138143
}
139144
}
140145

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use clap::ValueEnum;
1313
#[cfg(feature = "tracing")]
1414
use tracing::instrument;
1515

16-
pub use self::cargo::{Cargo, apply_pgo, cargo_profile_var};
16+
pub use self::cargo::{Cargo, apply_pgo};
1717
pub use crate::Compiler;
1818
use crate::core::build_steps::compile::{Std, StdLink};
1919
use crate::core::build_steps::tool::RustcPrivateCompilers;

0 commit comments

Comments
 (0)