Skip to content

Commit 2c18cc1

Browse files
committed
Build libstd with -Cembed-bitcode=yes.
So that the artifacts will work with both LTO and non-LTO builds.
1 parent 8b1fc0e commit 2c18cc1

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

src/bootstrap/check.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 12 additions & 2 deletions
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,16 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, cargo: &mut Ca
231231
}
232232
}
233233
}
234+
235+
// libstd must be built with embedded bitcode so that the produced
236+
// artifacts can be used for both LTO builds (which use bitcode) and
237+
// non-LTO builds (which use object code).
238+
//
239+
// But we don't bother for the stage 0 compiler because it's never used
240+
// with LTO.
241+
if stage >= 1 {
242+
cargo.rustflag("-Cembed-bitcode=yes");
243+
}
234244
}
235245

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

src/bootstrap/doc.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)