Skip to content

Commit 524d847

Browse files
committed
disable LTO on proc-macro crates when cross compiling
When cross-compiling with LTO=thin/fat, Cargo invokes rustc with LTO enabled even for proc-macro crates, which causes compilation to fail. See #110296 for more information. Signed-off-by: onur-ozkan <[email protected]>
1 parent af78bae commit 524d847

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/bootstrap/bin/rustc.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ fn main() {
7979
cmd.args(lint_flags.split_whitespace());
8080
}
8181

82+
let crate_type = arg("--crate-type");
83+
84+
// When cross-compiling with LTO=thin/fat, Cargo invokes rustc
85+
// with LTO enabled even for proc-macro crates, which causes compilation to fail.
86+
// See https://github.com/rust-lang/rust/issues/110296 for more information.
87+
//
88+
// FIXME: maybe fix this on the cargo side?
89+
if crate_type == Some("proc-macro") {
90+
cmd.arg("-C").arg("lto=off");
91+
}
92+
8293
if target.is_some() {
8394
// The stage0 compiler has a special sysroot distinct from what we
8495
// actually downloaded, so we just always pass the `--sysroot` option,
@@ -102,7 +113,7 @@ fn main() {
102113
// `-Ztls-model=initial-exec` must not be applied to proc-macros, see
103114
// issue https://github.com/rust-lang/rust/issues/100530
104115
if env::var("RUSTC_TLS_MODEL_INITIAL_EXEC").is_ok()
105-
&& arg("--crate-type") != Some("proc-macro")
116+
&& crate_type != Some("proc-macro")
106117
&& !matches!(crate_name, Some("proc_macro2" | "quote" | "syn" | "synstructure"))
107118
{
108119
cmd.arg("-Ztls-model=initial-exec");

0 commit comments

Comments
 (0)