@@ -100,11 +100,7 @@ fn init_late_loggers() {
100
100
}
101
101
}
102
102
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 {
108
104
// Taken from PR <https://github.com/Manishearth/rust-clippy/pull/911>.
109
105
let home = option_env ! ( "RUSTUP_HOME" ) . or ( option_env ! ( "MULTIRUST_HOME" ) ) ;
110
106
let toolchain = option_env ! ( "RUSTUP_TOOLCHAIN" ) . or ( option_env ! ( "MULTIRUST_TOOLCHAIN" ) ) ;
@@ -167,12 +163,22 @@ fn main() {
167
163
}
168
164
}
169
165
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*.
173
178
rustc_args. push ( sysroot_flag) ;
174
- rustc_args. push ( find_sysroot ( ) ) ;
179
+ rustc_args. push ( compile_time_sysroot ( ) ) ;
175
180
}
181
+
176
182
// Finally, add the default flags all the way in the beginning, but after the binary name.
177
183
rustc_args. splice ( 1 ..1 , miri:: miri_default_args ( ) . iter ( ) . map ( ToString :: to_string) ) ;
178
184
0 commit comments