Skip to content

Commit 3a19a92

Browse files
Rollup merge of rust-lang#119414 - xry111:xry111/lto-test, r=Mark-Simulacrum
bootstrap: Move -Clto= setting from Rustc::run to rustc_cargo It prevents a full rebuild of stage 1 compiler when issuing "x.py test" with rust.lto != thin-local in config.toml.
2 parents 98c9d72 + 786e0bb commit 3a19a92

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -905,34 +905,6 @@ impl Step for Rustc {
905905
));
906906
}
907907

908-
// We currently don't support cross-crate LTO in stage0. This also isn't hugely necessary
909-
// and may just be a time sink.
910-
if compiler.stage != 0 {
911-
match builder.config.rust_lto {
912-
RustcLto::Thin | RustcLto::Fat => {
913-
// Since using LTO for optimizing dylibs is currently experimental,
914-
// we need to pass -Zdylib-lto.
915-
cargo.rustflag("-Zdylib-lto");
916-
// Cargo by default passes `-Cembed-bitcode=no` and doesn't pass `-Clto` when
917-
// compiling dylibs (and their dependencies), even when LTO is enabled for the
918-
// crate. Therefore, we need to override `-Clto` and `-Cembed-bitcode` here.
919-
let lto_type = match builder.config.rust_lto {
920-
RustcLto::Thin => "thin",
921-
RustcLto::Fat => "fat",
922-
_ => unreachable!(),
923-
};
924-
cargo.rustflag(&format!("-Clto={lto_type}"));
925-
cargo.rustflag("-Cembed-bitcode=yes");
926-
}
927-
RustcLto::ThinLocal => { /* Do nothing, this is the default */ }
928-
RustcLto::Off => {
929-
cargo.rustflag("-Clto=off");
930-
}
931-
}
932-
} else if builder.config.rust_lto == RustcLto::Off {
933-
cargo.rustflag("-Clto=off");
934-
}
935-
936908
for krate in &*self.crates {
937909
cargo.arg("-p").arg(krate);
938910
}
@@ -989,6 +961,34 @@ pub fn rustc_cargo(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelec
989961

990962
cargo.rustdocflag("-Zcrate-attr=warn(rust_2018_idioms)");
991963

964+
// We currently don't support cross-crate LTO in stage0. This also isn't hugely necessary
965+
// and may just be a time sink.
966+
if stage != 0 {
967+
match builder.config.rust_lto {
968+
RustcLto::Thin | RustcLto::Fat => {
969+
// Since using LTO for optimizing dylibs is currently experimental,
970+
// we need to pass -Zdylib-lto.
971+
cargo.rustflag("-Zdylib-lto");
972+
// Cargo by default passes `-Cembed-bitcode=no` and doesn't pass `-Clto` when
973+
// compiling dylibs (and their dependencies), even when LTO is enabled for the
974+
// crate. Therefore, we need to override `-Clto` and `-Cembed-bitcode` here.
975+
let lto_type = match builder.config.rust_lto {
976+
RustcLto::Thin => "thin",
977+
RustcLto::Fat => "fat",
978+
_ => unreachable!(),
979+
};
980+
cargo.rustflag(&format!("-Clto={lto_type}"));
981+
cargo.rustflag("-Cembed-bitcode=yes");
982+
}
983+
RustcLto::ThinLocal => { /* Do nothing, this is the default */ }
984+
RustcLto::Off => {
985+
cargo.rustflag("-Clto=off");
986+
}
987+
}
988+
} else if builder.config.rust_lto == RustcLto::Off {
989+
cargo.rustflag("-Clto=off");
990+
}
991+
992992
rustc_cargo_env(builder, cargo, target, stage);
993993
}
994994

0 commit comments

Comments
 (0)