@@ -86,7 +86,7 @@ impl Step for Std {
86
86
target_deps. extend ( copy_third_party_objects ( builder, & compiler, target) . into_iter ( ) ) ;
87
87
88
88
let mut cargo = builder. cargo ( compiler, Mode :: Std , target, "build" ) ;
89
- std_cargo ( builder, target, & mut cargo) ;
89
+ std_cargo ( builder, target, compiler . stage , & mut cargo) ;
90
90
91
91
builder. info ( & format ! (
92
92
"Building stage{} std artifacts ({} -> {})" ,
@@ -164,7 +164,7 @@ fn copy_third_party_objects(
164
164
165
165
/// Configure cargo to compile the standard library, adding appropriate env vars
166
166
/// and such.
167
- pub fn std_cargo ( builder : & Builder < ' _ > , target : Interned < String > , cargo : & mut Cargo ) {
167
+ pub fn std_cargo ( builder : & Builder < ' _ > , target : Interned < String > , stage : u32 , cargo : & mut Cargo ) {
168
168
if let Some ( target) = env:: var_os ( "MACOSX_STD_DEPLOYMENT_TARGET" ) {
169
169
cargo. env ( "MACOSX_DEPLOYMENT_TARGET" , target) ;
170
170
}
@@ -231,6 +231,18 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, cargo: &mut Ca
231
231
}
232
232
}
233
233
}
234
+
235
+ // By default, rustc uses `-Cbitcode-in-rlib=yes`, and Cargo overrides that
236
+ // with `-Cbitcode-in-rlib=no` for non-LTO builds. However, libstd must be
237
+ // built with bitcode so that the produced rlibs can be used for both LTO
238
+ // builds (which use bitcode) and non-LTO builds (which use object code).
239
+ // So we override the override here!
240
+ //
241
+ // But we don't bother for the stage 0 compiler because it's never used
242
+ // with LTO.
243
+ if stage >= 1 {
244
+ cargo. rustflag ( "-Cbitcode-in-rlib=yes" ) ;
245
+ }
234
246
}
235
247
236
248
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
0 commit comments