]> git.lizzy.rs Git - rust.git/commitdiff
explain why we always set a sysroot; make sure we error if both MIRI_SYSROOT and...
authorRalf Jung <post@ralfj.de>
Sun, 9 Jun 2019 12:31:05 +0000 (14:31 +0200)
committerRalf Jung <post@ralfj.de>
Sun, 9 Jun 2019 12:31:05 +0000 (14:31 +0200)
src/bin/miri.rs

index 31ed5f2ccd5386cddab1d1782f1eb0149f866db6..660f1bec2d6240a091334170d9c66a27b117b059 100644 (file)
@@ -100,11 +100,7 @@ fn init_late_loggers() {
     }
 }
 
-fn find_sysroot() -> String {
-    if let Ok(sysroot) = std::env::var("MIRI_SYSROOT") {
-        return sysroot;
-    }
-
+fn compile_time_sysroot() -> String {
     // Taken from PR <https://github.com/Manishearth/rust-clippy/pull/911>.
     let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
     let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
@@ -167,12 +163,22 @@ fn main() {
         }
     }
 
-    // Determine sysroot and let rustc know about it.
-    let sysroot_flag = String::from("--sysroot");
-    if !rustc_args.contains(&sysroot_flag) {
+    // Determine sysroot.
+    let sysroot_flag = "--sysroot".to_string();
+    if let Ok(sysroot) = std::env::var("MIRI_SYSROOT") {
+        // MIRI_SYSROOT takes priority. rustc will ensure for us that this errors if there
+        // already is a "--sysroot" flag (because now there would be two).
+        rustc_args.push(sysroot_flag);
+        rustc_args.push(sysroot);
+    } else if !rustc_args.contains(&sysroot_flag) {
+        // We need to *always* set a --sysroot, as the "default" rustc uses is
+        // somewhere in the directory miri was built in.
+        // If neither MIRI_SYSROOT nor --sysroot are given, fall back to env
+        // vars that are read at *compile-time*.
         rustc_args.push(sysroot_flag);
-        rustc_args.push(find_sysroot());
+        rustc_args.push(compile_time_sysroot());
     }
+
     // Finally, add the default flags all the way in the beginning, but after the binary name.
     rustc_args.splice(1..1, miri::miri_default_args().iter().map(ToString::to_string));