@@ -13,13 +13,20 @@ use crate::util::*;
13
13
/// Performs the setup required to make `cargo miri` work: Getting a custom-built libstd. Then sets
14
14
/// `MIRI_SYSROOT`. Skipped if `MIRI_SYSROOT` is already set, in which case we expect the user has
15
15
/// done all this already.
16
- pub fn setup ( subcommand : & MiriCommand , target : & str , rustc_version : & VersionMeta , verbose : usize ) {
16
+ pub fn setup (
17
+ subcommand : & MiriCommand ,
18
+ target : & str ,
19
+ rustc_version : & VersionMeta ,
20
+ verbose : usize ,
21
+ ) -> PathBuf {
17
22
let only_setup = matches ! ( subcommand, MiriCommand :: Setup ) ;
18
23
let ask_user = !only_setup;
19
24
let print_sysroot = only_setup && has_arg_flag ( "--print-sysroot" ) ; // whether we just print the sysroot path
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`.
22
- return ;
25
+ if !only_setup {
26
+ if let Some ( sysroot) = std:: env:: var_os ( "MIRI_SYSROOT" ) {
27
+ // Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
28
+ return sysroot. into ( ) ;
29
+ }
23
30
}
24
31
25
32
// Determine where the rust sources are located. The env var trumps auto-detection.
@@ -92,6 +99,8 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
92
99
command. env ( "RUSTC" , & cargo_miri_path) ;
93
100
}
94
101
command. env ( "MIRI_CALLED_FROM_SETUP" , "1" ) ;
102
+ // Miri expects `MIRI_SYSROOT` to be set when invoked in target mode. Even if that directory is empty.
103
+ command. env ( "MIRI_SYSROOT" , & sysroot_dir) ;
95
104
// Make sure there are no other wrappers getting in our way (Cc
96
105
// https://github.com/rust-lang/miri/issues/1421,
97
106
// https://github.com/rust-lang/miri/issues/2429). Looks like setting
@@ -105,7 +114,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
105
114
command. arg ( "-v" ) ;
106
115
}
107
116
} else {
108
- // Supress output.
117
+ // Suppress output.
109
118
command. stdout ( process:: Stdio :: null ( ) ) ;
110
119
command. stderr ( process:: Stdio :: null ( ) ) ;
111
120
}
@@ -117,8 +126,6 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
117
126
// the user might have set, which is consistent with normal `cargo build` that does
118
127
// not apply `RUSTFLAGS` to the sysroot either.
119
128
let rustflags = & [ "-Cdebug-assertions=off" , "-Coverflow-checks=on" ] ;
120
- // Make sure all target-level Miri invocations know their sysroot.
121
- std:: env:: set_var ( "MIRI_SYSROOT" , & sysroot_dir) ;
122
129
123
130
// Do the build.
124
131
if print_sysroot {
@@ -159,4 +166,6 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
159
166
// Print just the sysroot and nothing else to stdout; this way we do not need any escaping.
160
167
println ! ( "{}" , sysroot_dir. display( ) ) ;
161
168
}
169
+
170
+ sysroot_dir
162
171
}
0 commit comments