@@ -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
@@ -114,7 +117,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
114
117
// not apply `RUSTFLAGS` to the sysroot either.
115
118
let rustflags = & [ "-Cdebug-assertions=off" , "-Coverflow-checks=on" ] ;
116
119
// 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) ;
118
121
119
122
// Do the build.
120
123
if only_setup {
@@ -124,7 +127,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
124
127
// We want to be quiet, but still let the user know that something is happening.
125
128
eprint ! ( "Preparing a sysroot for Miri (target: {target})... " ) ;
126
129
}
127
- SysrootBuilder :: new ( sysroot_dir, target)
130
+ SysrootBuilder :: new ( & sysroot_dir, target)
128
131
. build_mode ( BuildMode :: Check )
129
132
. rustc_version ( rustc_version. clone ( ) )
130
133
. sysroot_config ( sysroot_config)
0 commit comments