From 524d84749d1042035c4065a95bd010f8c41cf1be Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Wed, 20 Sep 2023 00:09:53 +0300 Subject: [PATCH] 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 https://github.com/rust-lang/rust/issues/110296 for more information. Signed-off-by: onur-ozkan --- src/bootstrap/bin/rustc.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 20cd63b966bce..ad04eabcd2b6e 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -79,6 +79,17 @@ fn main() { cmd.args(lint_flags.split_whitespace()); } + let crate_type = arg("--crate-type"); + + // When cross-compiling with LTO=thin/fat, Cargo invokes rustc + // with LTO enabled even for proc-macro crates, which causes compilation to fail. + // See https://github.com/rust-lang/rust/issues/110296 for more information. + // + // FIXME: maybe fix this on the cargo side? + if crate_type == Some("proc-macro") { + cmd.arg("-C").arg("lto=off"); + } + if target.is_some() { // The stage0 compiler has a special sysroot distinct from what we // actually downloaded, so we just always pass the `--sysroot` option, @@ -102,7 +113,7 @@ fn main() { // `-Ztls-model=initial-exec` must not be applied to proc-macros, see // issue https://github.com/rust-lang/rust/issues/100530 if env::var("RUSTC_TLS_MODEL_INITIAL_EXEC").is_ok() - && arg("--crate-type") != Some("proc-macro") + && crate_type != Some("proc-macro") && !matches!(crate_name, Some("proc_macro2" | "quote" | "syn" | "synstructure")) { cmd.arg("-Ztls-model=initial-exec");