@@ -17,10 +17,8 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
17
17
let only_setup = matches ! ( subcommand, MiriCommand :: Setup ) ;
18
18
let ask_user = !only_setup;
19
19
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`.
24
22
return ;
25
23
}
26
24
@@ -61,8 +59,13 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
61
59
}
62
60
63
61
// 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
+ } ;
66
69
// Sysroot configuration and build details.
67
70
let sysroot_config = if std:: env:: var_os ( "MIRI_NO_STD" ) . is_some ( ) {
68
71
SysrootConfig :: NoStd
@@ -111,7 +114,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
111
114
( command, rustflags)
112
115
} ;
113
116
// 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) ;
115
118
116
119
// Do the build.
117
120
if only_setup {
@@ -121,7 +124,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
121
124
// We want to be quiet, but still let the user know that something is happening.
122
125
eprint ! ( "Preparing a sysroot for Miri (target: {target})... " ) ;
123
126
}
124
- Sysroot :: new ( sysroot_dir, target)
127
+ Sysroot :: new ( & sysroot_dir, target)
125
128
. build_from_source ( & rust_src, BuildMode :: Check , sysroot_config, rustc_version, cargo_cmd)
126
129
. unwrap_or_else ( |_| {
127
130
if only_setup {
0 commit comments