Build libstd with -Cbitcode-in-rlib=yes.

So that the rlibs will work with both LTO and non-LTO builds.
This commit is contained in:
Nicholas Nethercote 2020-04-19 21:17:38 +10:00
parent 2984799881
commit a105c5c2c0
4 changed files with 17 additions and 5 deletions

View File

@ -45,7 +45,7 @@ fn run(self, builder: &Builder<'_>) {
let compiler = builder.compiler(0, builder.config.build);
let mut cargo = builder.cargo(compiler, Mode::Std, target, cargo_subcommand(builder.kind));
std_cargo(builder, target, &mut cargo);
std_cargo(builder, target, compiler.stage, &mut cargo);
builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
run_cargo(

View File

@ -86,7 +86,7 @@ fn run(self, builder: &Builder<'_>) {
target_deps.extend(copy_third_party_objects(builder, &compiler, target).into_iter());
let mut cargo = builder.cargo(compiler, Mode::Std, target, "build");
std_cargo(builder, target, &mut cargo);
std_cargo(builder, target, compiler.stage, &mut cargo);
builder.info(&format!(
"Building stage{} std artifacts ({} -> {})",
@ -164,7 +164,7 @@ fn copy_third_party_objects(
/// Configure cargo to compile the standard library, adding appropriate env vars
/// and such.
pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, cargo: &mut Cargo) {
pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, stage: u32, cargo: &mut Cargo) {
if let Some(target) = env::var_os("MACOSX_STD_DEPLOYMENT_TARGET") {
cargo.env("MACOSX_DEPLOYMENT_TARGET", target);
}
@ -231,6 +231,18 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, cargo: &mut Ca
}
}
}
// By default, rustc uses `-Cbitcode-in-rlib=yes`, and Cargo overrides that
// with `-Cbitcode-in-rlib=no` for non-LTO builds. However, libstd must be
// built with bitcode so that the produced rlibs can be used for both LTO
// builds (which use bitcode) and non-LTO builds (which use object code).
// So we override the override here!
//
// But we don't bother for the stage 0 compiler because it's never used
// with LTO.
if stage >= 1 {
cargo.rustflag("-Cbitcode-in-rlib=yes");
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]

View File

@ -394,7 +394,7 @@ fn run(self, builder: &Builder<'_>) {
let run_cargo_rustdoc_for = |package: &str| {
let mut cargo = builder.cargo(compiler, Mode::Std, target, "rustdoc");
compile::std_cargo(builder, target, &mut cargo);
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
// Keep a whitelist so we do not build internal stdlib crates, these will be
// build by the rustc step later if enabled.

View File

@ -1725,7 +1725,7 @@ fn run(self, builder: &Builder<'_>) {
let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
match mode {
Mode::Std => {
compile::std_cargo(builder, target, &mut cargo);
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
}
Mode::Rustc => {
builder.ensure(compile::Rustc { compiler, target });