Skip to content

Commit a105c5c

Browse files
committed
Build libstd with -Cbitcode-in-rlib=yes.
So that the rlibs will work with both LTO and non-LTO builds.
1 parent 2984799 commit a105c5c

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/bootstrap/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Step for Std {
4545
let compiler = builder.compiler(0, builder.config.build);
4646

4747
let mut cargo = builder.cargo(compiler, Mode::Std, target, cargo_subcommand(builder.kind));
48-
std_cargo(builder, target, &mut cargo);
48+
std_cargo(builder, target, compiler.stage, &mut cargo);
4949

5050
builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
5151
run_cargo(

src/bootstrap/compile.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Step for Std {
8686
target_deps.extend(copy_third_party_objects(builder, &compiler, target).into_iter());
8787

8888
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);
9090

9191
builder.info(&format!(
9292
"Building stage{} std artifacts ({} -> {})",
@@ -164,7 +164,7 @@ fn copy_third_party_objects(
164164

165165
/// Configure cargo to compile the standard library, adding appropriate env vars
166166
/// 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) {
168168
if let Some(target) = env::var_os("MACOSX_STD_DEPLOYMENT_TARGET") {
169169
cargo.env("MACOSX_DEPLOYMENT_TARGET", target);
170170
}
@@ -231,6 +231,18 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, cargo: &mut Ca
231231
}
232232
}
233233
}
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+
}
234246
}
235247

236248
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]

src/bootstrap/doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl Step for Std {
394394

395395
let run_cargo_rustdoc_for = |package: &str| {
396396
let mut cargo = builder.cargo(compiler, Mode::Std, target, "rustdoc");
397-
compile::std_cargo(builder, target, &mut cargo);
397+
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
398398

399399
// Keep a whitelist so we do not build internal stdlib crates, these will be
400400
// build by the rustc step later if enabled.

src/bootstrap/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ impl Step for Crate {
17251725
let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
17261726
match mode {
17271727
Mode::Std => {
1728-
compile::std_cargo(builder, target, &mut cargo);
1728+
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
17291729
}
17301730
Mode::Rustc => {
17311731
builder.ensure(compile::Rustc { compiler, target });

0 commit comments

Comments
 (0)