Skip to content

Commit 2773092

Browse files
committed
[WIP] Support hybrid LTO/non-LTO rlibs.
1 parent 48abaf5 commit 2773092

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

build_system/build_sysroot.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ fn build_clif_sysroot_for_triple(
212212
}
213213

214214
// Build sysroot
215-
let mut rustflags = vec!["-Zforce-unstable-if-unmarked".to_owned()];
215+
let mut rustflags =
216+
vec!["-Zforce-unstable-if-unmarked".to_owned(), "-Cembed-bitcode=yes".to_owned()];
216217
if !panic_unwind_support {
217218
rustflags.push("-Cpanic=abort".to_owned());
218219
}
@@ -237,8 +238,6 @@ fn build_clif_sysroot_for_triple(
237238
rustflags.push("--remap-path-prefix".to_owned());
238239
rustflags.push(format!("library/={}/library", prefix.to_str().unwrap()));
239240
}
240-
rustflags.push("-Clto=thin".to_owned());
241-
rustflags.push("-Zdylib-lto".to_owned());
242241
rustflags.push("-Cembed-bitcode=yes".to_owned());
243242
compiler.rustflags.extend(rustflags);
244243
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
@@ -256,7 +255,6 @@ fn build_clif_sysroot_for_triple(
256255
if env::var_os("CARGO_BUILD_INCREMENTAL").is_none() {
257256
build_cmd.env("CARGO_BUILD_INCREMENTAL", "true");
258257
}
259-
build_cmd.env("CARGO_PROFILE_RELEASE_LTO", "thin");
260258
spawn_and_wait(build_cmd);
261259

262260
for entry in fs::read_dir(build_dir.join("build"))

src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,17 @@ impl CodegenBackend for CraneliftCodegenBackend {
221221
#[cfg(not(feature = "jit"))]
222222
tcx.dcx().fatal("jit support was disabled when compiling rustc_codegen_cranelift");
223223
} else {
224+
if tcx.sess.opts.cg.linker_plugin_lto.enabled() {
225+
#[cfg(feature = "lto")]
226+
return driver::lto::run_lto(tcx);
227+
228+
#[cfg(not(feature = "lto"))]
229+
tcx.dcx().fatal("LTO support was disabled when compiling rustc_codegen_cranelift");
230+
}
231+
224232
match tcx.sess.lto() {
225233
Lto::No | Lto::ThinLocal => driver::aot::run_aot(tcx),
226234
Lto::Thin | Lto::Fat => {
227-
if tcx.is_compiler_builtins(LOCAL_CRATE) {
228-
return driver::aot::run_aot(tcx);
229-
}
230-
231235
#[cfg(feature = "lto")]
232236
return driver::lto::run_lto(tcx);
233237

0 commit comments

Comments
 (0)