Skip to content

Commit 6020de3

Browse files
authored
Merge pull request #205 from dtolnay/envrustc
Respect RUSTC environment variable if present
2 parents 1d4e1fb + fe8bd08 commit 6020de3

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/main.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -410,22 +410,26 @@ fn apply_args(cmd: &mut Command, args: &Expand, color: &Coloring, outfile: &Path
410410
}
411411

412412
fn needs_rustc_bootstrap() -> bool {
413-
let mut cmd = Command::new(cargo_binary());
414-
cmd.arg("rustc");
415-
cmd.arg("-Zunstable-options");
416-
cmd.arg("--print=sysroot");
417-
cmd.env("RUSTC_BOOTSTRAP", "1");
418-
cmd.stdin(Stdio::null());
419-
cmd.stderr(Stdio::null());
420-
let Ok(output) = cmd.output() else {
421-
return true;
422-
};
423-
let Ok(stdout) = str::from_utf8(&output.stdout) else {
424-
return true;
413+
let rustc = if let Some(rustc) = env::var_os("RUSTC") {
414+
PathBuf::from(rustc)
415+
} else {
416+
let mut cmd = Command::new(cargo_binary());
417+
cmd.arg("rustc");
418+
cmd.arg("-Zunstable-options");
419+
cmd.arg("--print=sysroot");
420+
cmd.env("RUSTC_BOOTSTRAP", "1");
421+
cmd.stdin(Stdio::null());
422+
cmd.stderr(Stdio::null());
423+
let Ok(output) = cmd.output() else {
424+
return true;
425+
};
426+
let Ok(stdout) = str::from_utf8(&output.stdout) else {
427+
return true;
428+
};
429+
let sysroot = Path::new(stdout.trim_end());
430+
sysroot.join("bin").join("rustc")
425431
};
426432

427-
let sysroot = Path::new(stdout.trim_end());
428-
let rustc = sysroot.join("bin").join("rustc");
429433
let mut cmd = Command::new(rustc);
430434
cmd.arg("-Zunpretty=expanded");
431435
cmd.arg("-");

0 commit comments

Comments
 (0)