Skip to content

Commit

Permalink
[WIP] Support hybrid LTO/non-LTO rlibs.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Dec 5, 2024
1 parent 11a347d commit e5973ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
3 changes: 0 additions & 3 deletions build_system/build_sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ fn build_clif_sysroot_for_triple(
prefix.to_str().unwrap()
));
}
rustflags.push("-Clto=thin".to_owned());
rustflags.push("-Zdylib-lto".to_owned());
rustflags.push("-Cembed-bitcode=yes".to_owned());
compiler.rustflags.extend(rustflags);
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
Expand All @@ -256,7 +254,6 @@ fn build_clif_sysroot_for_triple(
if compiler.triple.contains("apple") {
build_cmd.env("CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO", "packed");
}
build_cmd.env("CARGO_PROFILE_RELEASE_LTO", "thin");
spawn_and_wait(build_cmd);

for entry in fs::read_dir(build_dir.join("deps")).unwrap() {
Expand Down
27 changes: 17 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,30 @@ impl CodegenBackend for CraneliftCodegenBackend {
.unwrap_or_else(|err| tcx.sess.dcx().fatal(err))
});
match config.codegen_mode {
CodegenMode::Aot => match tcx.sess.lto() {
Lto::No | Lto::ThinLocal => {
driver::aot::run_aot(tcx, metadata, need_metadata_module)
}
Lto::Thin | Lto::Fat => {
if tcx.crate_name(LOCAL_CRATE) == sym::compiler_builtins {
return driver::aot::run_aot(tcx, metadata, need_metadata_module);
}

CodegenMode::Aot => {
if tcx.sess.opts.cg.linker_plugin_lto.enabled() {
#[cfg(feature = "lto")]
return driver::lto::run_aot(tcx, metadata, need_metadata_module);

#[cfg(not(feature = "lto"))]
tcx.dcx()
.fatal("LTO support was disabled when compiling rustc_codegen_cranelift");
}
},
match tcx.sess.lto() {
Lto::No | Lto::ThinLocal => {
driver::aot::run_aot(tcx, metadata, need_metadata_module)
}
Lto::Thin | Lto::Fat => {
#[cfg(feature = "lto")]
return driver::lto::run_aot(tcx, metadata, need_metadata_module);

#[cfg(not(feature = "lto"))]
tcx.dcx().fatal(
"LTO support was disabled when compiling rustc_codegen_cranelift",
);
}
}
}
CodegenMode::Jit | CodegenMode::JitLazy => {
#[cfg(feature = "jit")]
driver::jit::run_jit(tcx, config.codegen_mode, config.jit_args);
Expand Down

0 comments on commit e5973ee

Please sign in to comment.