@@ -13,13 +13,20 @@ use crate::util::*;
1313/// Performs the setup required to make `cargo miri` work: Getting a custom-built libstd. Then sets
1414/// `MIRI_SYSROOT`. Skipped if `MIRI_SYSROOT` is already set, in which case we expect the user has
1515/// 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 {
1722 let only_setup = matches ! ( subcommand, MiriCommand :: Setup ) ;
1823 let ask_user = !only_setup;
1924 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+ }
2330 }
2431
2532 // 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
9299 command. env ( "RUSTC" , & cargo_miri_path) ;
93100 }
94101 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) ;
95104 // Make sure there are no other wrappers getting in our way (Cc
96105 // https://github.com/rust-lang/miri/issues/1421,
97106 // 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
105114 command. arg ( "-v" ) ;
106115 }
107116 } else {
108- // Supress output.
117+ // Suppress output.
109118 command. stdout ( process:: Stdio :: null ( ) ) ;
110119 command. stderr ( process:: Stdio :: null ( ) ) ;
111120 }
@@ -117,8 +126,6 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
117126 // the user might have set, which is consistent with normal `cargo build` that does
118127 // not apply `RUSTFLAGS` to the sysroot either.
119128 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) ;
122129
123130 // Do the build.
124131 if print_sysroot {
@@ -159,4 +166,6 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
159166 // Print just the sysroot and nothing else to stdout; this way we do not need any escaping.
160167 println ! ( "{}" , sysroot_dir. display( ) ) ;
161168 }
169+
170+ sysroot_dir
162171}
0 commit comments