@@ -19,7 +19,6 @@ use crate::core::build_steps::{compile, llvm};
1919use crate :: core:: builder;
2020use crate :: core:: builder:: {
2121 Builder , Cargo as CargoCommand , RunConfig , ShouldRun , Step , StepMetadata , apply_pgo,
22- cargo_profile_var,
2322} ;
2423use crate :: core:: config:: { DebuginfoLevel , OverrideAllocator , RustcLto , TargetSelection } ;
2524use 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
0 commit comments