diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 64c4e648..2dbd0d6d 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -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); @@ -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() { diff --git a/src/lib.rs b/src/lib.rs index 5d21884d..18a2b2c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -207,15 +207,8 @@ 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); @@ -223,7 +216,21 @@ impl CodegenBackend for CraneliftCodegenBackend { 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);