@@ -54,34 +54,13 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
5454 so_file_path
5555}
5656
57- fn test_config ( target : & str , path : & str , mode : Mode , with_dependencies : bool ) -> Config {
57+ /// Does *not* set any args or env vars, since it is shared between the test runner and
58+ /// run_dep_mode.
59+ fn miri_config ( target : & str , path : & str , mode : Mode , with_dependencies : bool ) -> Config {
5860 // Miri is rustc-like, so we create a default builder for rustc and modify it
5961 let mut program = CommandBuilder :: rustc ( ) ;
6062 program. program = miri_path ( ) ;
6163
62- // Add some flags we always want.
63- program. args . push ( "-Dwarnings" . into ( ) ) ;
64- program. args . push ( "-Dunused" . into ( ) ) ;
65- program. args . push ( "-Ainternal_features" . into ( ) ) ;
66- if let Ok ( extra_flags) = env:: var ( "MIRIFLAGS" ) {
67- for flag in extra_flags. split_whitespace ( ) {
68- program. args . push ( flag. into ( ) ) ;
69- }
70- }
71- program. args . push ( "-Zui-testing" . into ( ) ) ;
72- program. args . push ( "--target" . into ( ) ) ;
73- program. args . push ( target. into ( ) ) ;
74-
75- // If we're on linux, and we're testing the extern-so functionality,
76- // then build the shared object file for testing external C function calls
77- // and push the relevant compiler flag.
78- if cfg ! ( target_os = "linux" ) && path. starts_with ( "tests/extern-so/" ) {
79- let so_file_path = build_so_for_c_ffi_tests ( ) ;
80- let mut flag = std:: ffi:: OsString :: from ( "-Zmiri-extern-so-file=" ) ;
81- flag. push ( so_file_path. into_os_string ( ) ) ;
82- program. args . push ( flag) ;
83- }
84-
8564 let mut config = Config {
8665 target : Some ( target. to_owned ( ) ) ,
8766 stderr_filters : STDERR . clone ( ) ,
@@ -119,17 +98,38 @@ fn run_tests(
11998 with_dependencies : bool ,
12099 tmpdir : & Path ,
121100) -> Result < ( ) > {
122- let mut config = test_config ( target, path, mode, with_dependencies) ;
101+ let mut config = miri_config ( target, path, mode, with_dependencies) ;
123102
124103 // Add a test env var to do environment communication tests.
125104 config. program . envs . push ( ( "MIRI_ENV_VAR_TEST" . into ( ) , Some ( "0" . into ( ) ) ) ) ;
126-
127105 // Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
128106 config. program . envs . push ( ( "MIRI_TEMP" . into ( ) , Some ( tmpdir. to_owned ( ) . into ( ) ) ) ) ;
129-
130107 // If a test ICEs, we want to see a backtrace.
131108 config. program . envs . push ( ( "RUST_BACKTRACE" . into ( ) , Some ( "1" . into ( ) ) ) ) ;
132109
110+ // Add some flags we always want.
111+ config. program . args . push ( "-Dwarnings" . into ( ) ) ;
112+ config. program . args . push ( "-Dunused" . into ( ) ) ;
113+ config. program . args . push ( "-Ainternal_features" . into ( ) ) ;
114+ if let Ok ( extra_flags) = env:: var ( "MIRIFLAGS" ) {
115+ for flag in extra_flags. split_whitespace ( ) {
116+ config. program . args . push ( flag. into ( ) ) ;
117+ }
118+ }
119+ config. program . args . push ( "-Zui-testing" . into ( ) ) ;
120+ config. program . args . push ( "--target" . into ( ) ) ;
121+ config. program . args . push ( target. into ( ) ) ;
122+
123+ // If we're on linux, and we're testing the extern-so functionality,
124+ // then build the shared object file for testing external C function calls
125+ // and push the relevant compiler flag.
126+ if cfg ! ( target_os = "linux" ) && path. starts_with ( "tests/extern-so/" ) {
127+ let so_file_path = build_so_for_c_ffi_tests ( ) ;
128+ let mut flag = std:: ffi:: OsString :: from ( "-Zmiri-extern-so-file=" ) ;
129+ flag. push ( so_file_path. into_os_string ( ) ) ;
130+ config. program . args . push ( flag) ;
131+ }
132+
133133 // Handle command-line arguments.
134134 let args = ui_test:: Args :: test ( ) ?;
135135 let default_bless = env:: var_os ( "RUSTC_BLESS" ) . is_some_and ( |v| v != "0" ) ;
@@ -292,13 +292,12 @@ fn main() -> Result<()> {
292292
293293fn run_dep_mode ( target : String , mut args : impl Iterator < Item = OsString > ) -> Result < ( ) > {
294294 let path = args. next ( ) . expect ( "./miri run-dep must be followed by a file name" ) ;
295- let mut config = test_config (
295+ let config = miri_config (
296296 & target,
297297 "" ,
298298 Mode :: Yolo { rustfix : RustfixMode :: Disabled } ,
299299 /* with dependencies */ true ,
300300 ) ;
301- config. program . args . clear ( ) ; // We want to give the user full control over flags
302301 let dep_args = config. build_dependencies ( ) ?;
303302
304303 let mut cmd = config. program . build ( & config. out_dir ) ;
0 commit comments