Skip to content

Commit 619f296

Browse files
committed
explain why we always set a sysroot; make sure we error if both MIRI_SYSROOT and --sysroot are set
1 parent 05b7e61 commit 619f296

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/bin/miri.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,7 @@ fn init_late_loggers() {
100100
}
101101
}
102102

103-
fn find_sysroot() -> String {
104-
if let Ok(sysroot) = std::env::var("MIRI_SYSROOT") {
105-
return sysroot;
106-
}
107-
103+
fn compile_time_sysroot() -> String {
108104
// Taken from PR <https://github.com/Manishearth/rust-clippy/pull/911>.
109105
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
110106
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
@@ -167,12 +163,22 @@ fn main() {
167163
}
168164
}
169165

170-
// Determine sysroot and let rustc know about it.
171-
let sysroot_flag = String::from("--sysroot");
172-
if !rustc_args.contains(&sysroot_flag) {
166+
// Determine sysroot.
167+
let sysroot_flag = "--sysroot".to_string();
168+
if let Ok(sysroot) = std::env::var("MIRI_SYSROOT") {
169+
// MIRI_SYSROOT takes priority. rustc will ensure for us that this errors if there
170+
// already is a "--sysroot" flag (because now there would be two).
171+
rustc_args.push(sysroot_flag);
172+
rustc_args.push(sysroot);
173+
} else if !rustc_args.contains(&sysroot_flag) {
174+
// We need to *always* set a --sysroot, as the "default" rustc uses is
175+
// somewhere in the directory miri was built in.
176+
// If neither MIRI_SYSROOT nor --sysroot are given, fall back to env
177+
// vars that are read at *compile-time*.
173178
rustc_args.push(sysroot_flag);
174-
rustc_args.push(find_sysroot());
179+
rustc_args.push(compile_time_sysroot());
175180
}
181+
176182
// Finally, add the default flags all the way in the beginning, but after the binary name.
177183
rustc_args.splice(1..1, miri::miri_default_args().iter().map(ToString::to_string));
178184

0 commit comments

Comments
 (0)