Skip to content

Commit a327e75

Browse files
committed
Auto merge of #115986 - onur-ozkan:fix-cross-compilation-lto-problem, r=wesleywiser
allow LTO on `proc-macro` crates with `-Zdylib-lto` ref #115986 (comment) Fixes #110296
2 parents 60bb519 + bdd66b3 commit a327e75

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

compiler/rustc_codegen_llvm/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ codegen_llvm_lto_disallowed = lto can only be run for executables, cdylibs and s
3737
3838
codegen_llvm_lto_dylib = lto cannot be used for `dylib` crate type without `-Zdylib-lto`
3939
40+
codegen_llvm_lto_proc_macro = lto cannot be used for `proc-macro` crate type without `-Zdylib-lto`
41+
4042
codegen_llvm_missing_features =
4143
add the missing features in a `target_feature` attribute
4244

compiler/rustc_codegen_llvm/src/back/lto.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::back::write::{
22
self, bitcode_section_name, save_temp_bitcode, CodegenDiagnosticsStage, DiagnosticHandlers,
33
};
44
use crate::errors::{
5-
DynamicLinkingWithLTO, LlvmError, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib,
5+
DynamicLinkingWithLTO, LlvmError, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib, LtoProcMacro,
66
};
77
use crate::llvm::{self, build_string};
88
use crate::{LlvmCodegenBackend, ModuleLlvm};
@@ -36,8 +36,12 @@ pub const THIN_LTO_KEYS_INCR_COMP_FILE_NAME: &str = "thin-lto-past-keys.bin";
3636

3737
pub fn crate_type_allows_lto(crate_type: CrateType) -> bool {
3838
match crate_type {
39-
CrateType::Executable | CrateType::Dylib | CrateType::Staticlib | CrateType::Cdylib => true,
40-
CrateType::Rlib | CrateType::ProcMacro => false,
39+
CrateType::Executable
40+
| CrateType::Dylib
41+
| CrateType::Staticlib
42+
| CrateType::Cdylib
43+
| CrateType::ProcMacro => true,
44+
CrateType::Rlib => false,
4145
}
4246
}
4347

@@ -87,6 +91,11 @@ fn prepare_lto(
8791
diag_handler.emit_err(LtoDylib);
8892
return Err(FatalError);
8993
}
94+
} else if *crate_type == CrateType::ProcMacro {
95+
if !cgcx.opts.unstable_opts.dylib_lto {
96+
diag_handler.emit_err(LtoProcMacro);
97+
return Err(FatalError);
98+
}
9099
}
91100
}
92101

compiler/rustc_codegen_llvm/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ pub(crate) struct LtoDisallowed;
138138
#[diag(codegen_llvm_lto_dylib)]
139139
pub(crate) struct LtoDylib;
140140

141+
#[derive(Diagnostic)]
142+
#[diag(codegen_llvm_lto_proc_macro)]
143+
pub(crate) struct LtoProcMacro;
144+
141145
#[derive(Diagnostic)]
142146
#[diag(codegen_llvm_lto_bitcode_from_rlib)]
143147
pub(crate) struct LtoBitcodeFromRlib {

0 commit comments

Comments
 (0)