Skip to content

Commit e73fc97

Browse files
committed
cargo-miri: honor RUSTC env var
1 parent 70f83a3 commit e73fc97

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

src/bin/cargo-miri.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::io::{self, BufRead, Write};
66
use std::ops::Not;
77
use std::path::{Path, PathBuf};
88
use std::process::Command;
9+
use std::ffi::OsString;
910

1011
const XARGO_MIN_VERSION: (u32, u32, u32) = (0, 3, 20);
1112

@@ -85,29 +86,23 @@ fn get_arg_flag_value(name: &str) -> Option<String> {
8586
}
8687
}
8788

88-
/// Returns the path to the `miri` binary
89-
fn find_miri() -> PathBuf {
89+
/// Returns a command for the right `miri` binary.
90+
fn miri() -> Command {
9091
let mut path = std::env::current_exe().expect("current executable path invalid");
9192
path.set_file_name("miri");
92-
path
93+
Command::new(path)
9394
}
9495

9596
fn cargo() -> Command {
96-
if let Ok(val) = std::env::var("CARGO") {
97-
// Bootstrap tells us where to find cargo
98-
Command::new(val)
99-
} else {
100-
Command::new("cargo")
101-
}
97+
Command::new(env::var_os("CARGO").unwrap_or_else(|| OsString::from("cargo")))
10298
}
10399

104100
fn xargo_check() -> Command {
105-
if let Ok(val) = std::env::var("XARGO_CHECK") {
106-
// Bootstrap tells us where to find xargo
107-
Command::new(val)
108-
} else {
109-
Command::new("xargo-check")
110-
}
101+
Command::new(env::var_os("XARGO_CHECK").unwrap_or_else(|| OsString::from("xargo-check")))
102+
}
103+
104+
fn rustc() -> Command {
105+
Command::new(env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc")))
111106
}
112107

113108
fn list_targets() -> impl Iterator<Item = cargo_metadata::Target> {
@@ -188,8 +183,8 @@ fn test_sysroot_consistency() {
188183
return;
189184
}
190185

191-
let rustc_sysroot = get_sysroot(Command::new("rustc"));
192-
let miri_sysroot = get_sysroot(Command::new(find_miri()));
186+
let rustc_sysroot = get_sysroot(rustc());
187+
let miri_sysroot = get_sysroot(miri());
193188

194189
if rustc_sysroot != miri_sysroot {
195190
show_error(format!(
@@ -301,7 +296,7 @@ fn setup(subcommand: MiriCommand) {
301296
Ok(val) => PathBuf::from(val),
302297
Err(_) => {
303298
// Check for `rust-src` rustup component.
304-
let sysroot = Command::new("rustc")
299+
let sysroot = rustc()
305300
.args(&["--print", "sysroot"])
306301
.output()
307302
.expect("failed to get rustc sysroot")
@@ -554,9 +549,9 @@ fn inside_cargo_rustc() {
554549
serde_json::from_str(&magic).expect("failed to deserialize MIRI_ARGS");
555550
args.append(&mut user_args);
556551
// Run this in Miri.
557-
Command::new(find_miri())
552+
miri()
558553
} else {
559-
Command::new("rustc")
554+
rustc()
560555
};
561556

562557
// Run it.

0 commit comments

Comments
 (0)