Skip to content

Commit e5973ee

Browse files
committed
[WIP] Support hybrid LTO/non-LTO rlibs.
1 parent 11a347d commit e5973ee

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

build_system/build_sysroot.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ fn build_clif_sysroot_for_triple(
243243
prefix.to_str().unwrap()
244244
));
245245
}
246-
rustflags.push("-Clto=thin".to_owned());
247-
rustflags.push("-Zdylib-lto".to_owned());
248246
rustflags.push("-Cembed-bitcode=yes".to_owned());
249247
compiler.rustflags.extend(rustflags);
250248
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
@@ -256,7 +254,6 @@ fn build_clif_sysroot_for_triple(
256254
if compiler.triple.contains("apple") {
257255
build_cmd.env("CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO", "packed");
258256
}
259-
build_cmd.env("CARGO_PROFILE_RELEASE_LTO", "thin");
260257
spawn_and_wait(build_cmd);
261258

262259
for entry in fs::read_dir(build_dir.join("deps")).unwrap() {

src/lib.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,23 +207,30 @@ impl CodegenBackend for CraneliftCodegenBackend {
207207
.unwrap_or_else(|err| tcx.sess.dcx().fatal(err))
208208
});
209209
match config.codegen_mode {
210-
CodegenMode::Aot => match tcx.sess.lto() {
211-
Lto::No | Lto::ThinLocal => {
212-
driver::aot::run_aot(tcx, metadata, need_metadata_module)
213-
}
214-
Lto::Thin | Lto::Fat => {
215-
if tcx.crate_name(LOCAL_CRATE) == sym::compiler_builtins {
216-
return driver::aot::run_aot(tcx, metadata, need_metadata_module);
217-
}
218-
210+
CodegenMode::Aot => {
211+
if tcx.sess.opts.cg.linker_plugin_lto.enabled() {
219212
#[cfg(feature = "lto")]
220213
return driver::lto::run_aot(tcx, metadata, need_metadata_module);
221214

222215
#[cfg(not(feature = "lto"))]
223216
tcx.dcx()
224217
.fatal("LTO support was disabled when compiling rustc_codegen_cranelift");
225218
}
226-
},
219+
match tcx.sess.lto() {
220+
Lto::No | Lto::ThinLocal => {
221+
driver::aot::run_aot(tcx, metadata, need_metadata_module)
222+
}
223+
Lto::Thin | Lto::Fat => {
224+
#[cfg(feature = "lto")]
225+
return driver::lto::run_aot(tcx, metadata, need_metadata_module);
226+
227+
#[cfg(not(feature = "lto"))]
228+
tcx.dcx().fatal(
229+
"LTO support was disabled when compiling rustc_codegen_cranelift",
230+
);
231+
}
232+
}
233+
}
227234
CodegenMode::Jit | CodegenMode::JitLazy => {
228235
#[cfg(feature = "jit")]
229236
driver::jit::run_jit(tcx, config.codegen_mode, config.jit_args);

0 commit comments

Comments
 (0)