Skip to content

Commit 1210939

Browse files
committed
[WIP] Support hybrid LTO/non-LTO rlibs.
1 parent ba833af commit 1210939

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
@@ -210,23 +210,30 @@ impl CodegenBackend for CraneliftCodegenBackend {
210210
.unwrap_or_else(|err| tcx.sess.dcx().fatal(err))
211211
});
212212
match config.codegen_mode {
213-
CodegenMode::Aot => match tcx.sess.lto() {
214-
Lto::No | Lto::ThinLocal => {
215-
driver::aot::run_aot(tcx, metadata, need_metadata_module)
216-
}
217-
Lto::Thin | Lto::Fat => {
218-
if tcx.crate_name(LOCAL_CRATE) == sym::compiler_builtins {
219-
return driver::aot::run_aot(tcx, metadata, need_metadata_module);
220-
}
221-
213+
CodegenMode::Aot => {
214+
if tcx.sess.opts.cg.linker_plugin_lto.enabled() {
222215
#[cfg(feature = "lto")]
223216
return driver::lto::run_aot(tcx, metadata, need_metadata_module);
224217

225218
#[cfg(not(feature = "lto"))]
226219
tcx.dcx()
227220
.fatal("LTO support was disabled when compiling rustc_codegen_cranelift");
228221
}
229-
},
222+
match tcx.sess.lto() {
223+
Lto::No | Lto::ThinLocal => {
224+
driver::aot::run_aot(tcx, metadata, need_metadata_module)
225+
}
226+
Lto::Thin | Lto::Fat => {
227+
#[cfg(feature = "lto")]
228+
return driver::lto::run_aot(tcx, metadata, need_metadata_module);
229+
230+
#[cfg(not(feature = "lto"))]
231+
tcx.dcx().fatal(
232+
"LTO support was disabled when compiling rustc_codegen_cranelift",
233+
);
234+
}
235+
}
236+
}
230237
CodegenMode::Jit | CodegenMode::JitLazy => {
231238
#[cfg(feature = "jit")]
232239
driver::jit::run_jit(tcx, config.codegen_mode, config.jit_args);

0 commit comments

Comments
 (0)