Skip to content

Commit 00047e4

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 <work@onurozkan.dev>
1 parent af78bae commit 00047e4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/bootstrap/bin/rustc.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ 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+
if crate_type == Some("proc-macro") {
88+
cmd.arg("-C").arg("lto=off");
89+
}
90+
8291
if target.is_some() {
8392
// The stage0 compiler has a special sysroot distinct from what we
8493
// actually downloaded, so we just always pass the `--sysroot` option,
@@ -102,7 +111,7 @@ fn main() {
102111
// `-Ztls-model=initial-exec` must not be applied to proc-macros, see
103112
// issue https://github.com/rust-lang/rust/issues/100530
104113
if env::var("RUSTC_TLS_MODEL_INITIAL_EXEC").is_ok()
105-
&& arg("--crate-type") != Some("proc-macro")
114+
&& crate_type != Some("proc-macro")
106115
&& !matches!(crate_name, Some("proc_macro2" | "quote" | "syn" | "synstructure"))
107116
{
108117
cmd.arg("-Ztls-model=initial-exec");

0 commit comments

Comments
 (0)