Merge pull request #205 from dtolnay/envrustc

Respect RUSTC environment variable if present
This commit is contained in:
David Tolnay 2023-12-26 10:17:40 -08:00 committed by GitHub
commit 6020de36ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -410,22 +410,26 @@ fn apply_args(cmd: &mut Command, args: &Expand, color: &Coloring, outfile: &Path
} }
fn needs_rustc_bootstrap() -> bool { fn needs_rustc_bootstrap() -> bool {
let mut cmd = Command::new(cargo_binary()); let rustc = if let Some(rustc) = env::var_os("RUSTC") {
cmd.arg("rustc"); PathBuf::from(rustc)
cmd.arg("-Zunstable-options"); } else {
cmd.arg("--print=sysroot"); let mut cmd = Command::new(cargo_binary());
cmd.env("RUSTC_BOOTSTRAP", "1"); cmd.arg("rustc");
cmd.stdin(Stdio::null()); cmd.arg("-Zunstable-options");
cmd.stderr(Stdio::null()); cmd.arg("--print=sysroot");
let Ok(output) = cmd.output() else { cmd.env("RUSTC_BOOTSTRAP", "1");
return true; cmd.stdin(Stdio::null());
}; cmd.stderr(Stdio::null());
let Ok(stdout) = str::from_utf8(&output.stdout) else { let Ok(output) = cmd.output() else {
return true; return true;
};
let Ok(stdout) = str::from_utf8(&output.stdout) else {
return true;
};
let sysroot = Path::new(stdout.trim_end());
sysroot.join("bin").join("rustc")
}; };
let sysroot = Path::new(stdout.trim_end());
let rustc = sysroot.join("bin").join("rustc");
let mut cmd = Command::new(rustc); let mut cmd = Command::new(rustc);
cmd.arg("-Zunpretty=expanded"); cmd.arg("-Zunpretty=expanded");
cmd.arg("-"); cmd.arg("-");