@@ -17,10 +17,8 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
1717 let only_setup = matches ! ( subcommand, MiriCommand :: Setup ) ;
1818 let ask_user = !only_setup;
1919 let print_sysroot = only_setup && has_arg_flag ( "--print-sysroot" ) ; // whether we just print the sysroot path
20- if std:: env:: var_os ( "MIRI_SYSROOT" ) . is_some ( ) {
21- if only_setup {
22- println ! ( "WARNING: MIRI_SYSROOT already set, not doing anything." )
23- }
20+ if !only_setup && std:: env:: var_os ( "MIRI_SYSROOT" ) . is_some ( ) {
21+ // Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
2422 return ;
2523 }
2624
@@ -61,8 +59,13 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
6159 }
6260
6361 // Determine where to put the sysroot.
64- let user_dirs = directories:: ProjectDirs :: from ( "org" , "rust-lang" , "miri" ) . unwrap ( ) ;
65- let sysroot_dir = user_dirs. cache_dir ( ) ;
62+ let sysroot_dir = match std:: env:: var_os ( "MIRI_SYSROOT" ) {
63+ Some ( dir) => PathBuf :: from ( dir) ,
64+ None => {
65+ let user_dirs = directories:: ProjectDirs :: from ( "org" , "rust-lang" , "miri" ) . unwrap ( ) ;
66+ user_dirs. cache_dir ( ) . to_owned ( )
67+ }
68+ } ;
6669 // Sysroot configuration and build details.
6770 let sysroot_config = if std:: env:: var_os ( "MIRI_NO_STD" ) . is_some ( ) {
6871 SysrootConfig :: NoStd
@@ -114,7 +117,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
114117 // not apply `RUSTFLAGS` to the sysroot either.
115118 let rustflags = & [ "-Cdebug-assertions=off" , "-Coverflow-checks=on" ] ;
116119 // Make sure all target-level Miri invocations know their sysroot.
117- std:: env:: set_var ( "MIRI_SYSROOT" , sysroot_dir) ;
120+ std:: env:: set_var ( "MIRI_SYSROOT" , & sysroot_dir) ;
118121
119122 // Do the build.
120123 if only_setup {
@@ -124,7 +127,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
124127 // We want to be quiet, but still let the user know that something is happening.
125128 eprint ! ( "Preparing a sysroot for Miri (target: {target})... " ) ;
126129 }
127- SysrootBuilder :: new ( sysroot_dir, target)
130+ SysrootBuilder :: new ( & sysroot_dir, target)
128131 . build_mode ( BuildMode :: Check )
129132 . rustc_version ( rustc_version. clone ( ) )
130133 . sysroot_config ( sysroot_config)
0 commit comments