@@ -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
@@ -111,7 +114,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
111114 ( command, rustflags)
112115 } ;
113116 // Make sure all target-level Miri invocations know their sysroot.
114- std:: env:: set_var ( "MIRI_SYSROOT" , sysroot_dir) ;
117+ std:: env:: set_var ( "MIRI_SYSROOT" , & sysroot_dir) ;
115118
116119 // Do the build.
117120 if only_setup {
@@ -121,7 +124,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
121124 // We want to be quiet, but still let the user know that something is happening.
122125 eprint ! ( "Preparing a sysroot for Miri (target: {target})... " ) ;
123126 }
124- Sysroot :: new ( sysroot_dir, target)
127+ Sysroot :: new ( & sysroot_dir, target)
125128 . build_from_source ( & rust_src, BuildMode :: Check , sysroot_config, rustc_version, cargo_cmd)
126129 . unwrap_or_else ( |_| {
127130 if only_setup {
0 commit comments