Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ fn spawn_cargo(
force_single_cgu: bool,
) -> std::io::Result<std::process::Child> {
use std::ffi::OsStr;
use std::fmt::Write;

let mut cmd = std::process::Command::new(cargo_path());
let mut rust_flags = std::env::var("RUSTFLAGS").unwrap_or_default();

// Cargo flags.
cmd.arg("rustc")
Expand Down Expand Up @@ -118,8 +120,11 @@ fn spawn_cargo(
.args(cargo.codegen.iter().flat_map(|c| ["-C", c]))
// Next, we care about asm/wasm/llvm-ir/llvm-mac.
.args(syntax.emit().iter().flat_map(|s| ["--emit", s]))
.args(syntax.format().iter().flat_map(|s| ["-C", s]))
.args(target_cpu.iter().map(|cpu| format!("-Ctarget-cpu={cpu}")));
.args(syntax.format().iter().flat_map(|s| ["-C", s]));

if let Some(cpu) = target_cpu {
write!(rust_flags, " -Ctarget-cpu={cpu}").unwrap();
}

{
// None corresponds to disasm
Expand All @@ -135,6 +140,10 @@ fn spawn_cargo(
cmd.arg("-Ccodegen-units=1");
}

// `args` from `cargo rustc -- args` are passed only to the final compiler instance.
// `RUSTFLAGS` envvar is useful for passing flags to all compiler instances.
cmd.env("RUSTFLAGS", rust_flags.trim_start());

if format.verbosity >= 2 {
safeprintln!("Running: {cmd:?}");
}
Expand Down