Skip to content

Commit

Permalink
disable LTO on proc-macro crates when cross compiling
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
onur-ozkan committed Sep 19, 2023
1 parent af78bae commit 524d847
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");
Expand Down

0 comments on commit 524d847

Please sign in to comment.