@@ -216,76 +216,28 @@ fn init_late_loggers(tcx: TyCtxt<'_>) {
216216 }
217217}
218218
219- /// Returns the "default sysroot" that Miri will use for host things if no `--sysroot` flag is set.
220- /// Should be a compile-time constant.
221- fn host_sysroot ( ) -> Option < String > {
222- if option_env ! ( "RUSTC_STAGE" ) . is_some ( ) {
223- // This is being built as part of rustc, and gets shipped with rustup.
224- // We can rely on the sysroot computation in librustc_session.
225- return None ;
226- }
227- // For builds outside rustc, we need to ensure that we got a sysroot
228- // that gets used as a default. The sysroot computation in librustc_session would
229- // end up somewhere in the build dir (see `get_or_default_sysroot`).
230- // Taken from PR <https://github.com/Manishearth/rust-clippy/pull/911>.
231- let home = option_env ! ( "RUSTUP_HOME" ) . or ( option_env ! ( "MULTIRUST_HOME" ) ) ;
232- let toolchain = option_env ! ( "RUSTUP_TOOLCHAIN" ) . or ( option_env ! ( "MULTIRUST_TOOLCHAIN" ) ) ;
233- Some ( match ( home, toolchain) {
234- ( Some ( home) , Some ( toolchain) ) => {
235- // Check that at runtime, we are still in this toolchain (if there is any toolchain).
236- if let Some ( toolchain_runtime) =
237- env:: var_os ( "RUSTUP_TOOLCHAIN" ) . or_else ( || env:: var_os ( "MULTIRUST_TOOLCHAIN" ) )
238- {
239- if toolchain_runtime != toolchain {
240- show_error ! (
241- "This Miri got built with local toolchain `{toolchain}`, but now is being run under a different toolchain. \n \
242- Make sure to run Miri in the toolchain it got built with, e.g. via `cargo +{toolchain} miri`."
243- )
244- }
245- }
246- format ! ( "{home}/toolchains/{toolchain}" )
247- }
248- _ => option_env ! ( "RUST_SYSROOT" )
249- . unwrap_or_else ( || {
250- show_error ! (
251- "To build Miri without rustup, set the `RUST_SYSROOT` env var at build time" ,
252- )
253- } )
254- . to_owned ( ) ,
255- } )
256- }
257-
258219/// Execute a compiler with the given CLI arguments and callbacks.
259220fn run_compiler (
260221 mut args : Vec < String > ,
261222 target_crate : bool ,
262223 callbacks : & mut ( dyn rustc_driver:: Callbacks + Send ) ,
263224) -> ! {
264- // Make sure we use the right default sysroot. The default sysroot is wrong,
265- // because `get_or_default_sysroot` in `librustc_session` bases that on `current_exe`.
266- //
267- // Make sure we always call `host_sysroot` as that also does some sanity-checks
268- // of the environment we were built in and whether it matches what we are running in.
269- let host_default_sysroot = host_sysroot ( ) ;
270- // Now see if we even need to set something.
271- let sysroot_flag = "--sysroot" ;
272- if !args. iter ( ) . any ( |e| e == sysroot_flag) {
273- // No sysroot was set, let's see if we have a custom default we want to configure.
274- let default_sysroot = if target_crate {
225+ if target_crate {
226+ // Miri needs a custom sysroot for target crates.
227+ // If no `--sysroot` is given, the `MIRI_SYSROOT` env var is consulted to find where
228+ // that sysroot lives, and that is passed to rustc.
229+ let sysroot_flag = "--sysroot" ;
230+ if !args. iter ( ) . any ( |e| e == sysroot_flag) {
275231 // Using the built-in default here would be plain wrong, so we *require*
276232 // the env var to make sure things make sense.
277- Some ( env:: var ( "MIRI_SYSROOT" ) . unwrap_or_else ( |_| {
233+ let miri_sysroot = env:: var ( "MIRI_SYSROOT" ) . unwrap_or_else ( |_| {
278234 show_error ! (
279235 "Miri was invoked in 'target' mode without `MIRI_SYSROOT` or `--sysroot` being set"
280- )
281- } ) )
282- } else {
283- host_default_sysroot
284- } ;
285- if let Some ( sysroot) = default_sysroot {
286- // We need to overwrite the default that librustc_session would compute.
236+ )
237+ } ) ;
238+
287239 args. push ( sysroot_flag. to_owned ( ) ) ;
288- args. push ( sysroot ) ;
240+ args. push ( miri_sysroot ) ;
289241 }
290242 }
291243
0 commit comments