@@ -29,20 +29,17 @@ fn miri_path() -> PathBuf {
2929 PathBuf :: from ( env:: var ( "MIRI" ) . unwrap_or_else ( |_| env ! ( "CARGO_BIN_EXE_miri" ) . into ( ) ) )
3030}
3131
32- fn get_host ( ) -> String {
33- rustc_version:: VersionMeta :: for_command ( std:: process:: Command :: new ( miri_path ( ) ) )
34- . expect ( "failed to parse rustc version info" )
35- . host
36- }
37-
3832pub fn flagsplit ( flags : & str ) -> Vec < String > {
3933 // This code is taken from `RUSTFLAGS` handling in cargo.
4034 flags. split ( ' ' ) . map ( str:: trim) . filter ( |s| !s. is_empty ( ) ) . map ( str:: to_string) . collect ( )
4135}
4236
4337// Build the shared object file for testing native function calls.
44- fn build_native_lib ( ) -> PathBuf {
45- let cc = env:: var ( "CC" ) . unwrap_or_else ( |_| "cc" . into ( ) ) ;
38+ fn build_native_lib ( target : & str ) -> PathBuf {
39+ // Loosely follow the logic of the `cc` crate for finding the compiler.
40+ let cc = env:: var ( format ! ( "CC_{target}" ) )
41+ . or_else ( |_| env:: var ( "CC" ) )
42+ . unwrap_or_else ( |_| "cc" . into ( ) ) ;
4643 // Target directory that we can write to.
4744 let so_target_dir = Path :: new ( env ! ( "CARGO_TARGET_TMPDIR" ) ) . join ( "miri-native-lib" ) ;
4845 // Create the directory if it does not already exist.
@@ -201,7 +198,7 @@ fn run_tests(
201198 // If we're testing the native-lib functionality, then build the shared object file for testing
202199 // external C function calls and push the relevant compiler flag.
203200 if path. starts_with ( "tests/native-lib/" ) {
204- let native_lib = build_native_lib ( ) ;
201+ let native_lib = build_native_lib ( target ) ;
205202 let mut flag = std:: ffi:: OsString :: from ( "-Zmiri-native-lib=" ) ;
206203 flag. push ( native_lib. into_os_string ( ) ) ;
207204 config. program . args . push ( flag) ;
@@ -305,14 +302,21 @@ fn ui(
305302 . with_context ( || format ! ( "ui tests in {path} for {target} failed" ) )
306303}
307304
308- fn get_target ( ) -> String {
309- env:: var ( "MIRI_TEST_TARGET" ) . ok ( ) . unwrap_or_else ( get_host)
305+ fn get_host ( ) -> String {
306+ rustc_version:: VersionMeta :: for_command ( std:: process:: Command :: new ( miri_path ( ) ) )
307+ . expect ( "failed to parse rustc version info" )
308+ . host
309+ }
310+
311+ fn get_target ( host : & str ) -> String {
312+ env:: var ( "MIRI_TEST_TARGET" ) . ok ( ) . unwrap_or_else ( || host. to_owned ( ) )
310313}
311314
312315fn main ( ) -> Result < ( ) > {
313316 ui_test:: color_eyre:: install ( ) ?;
314317
315- let target = get_target ( ) ;
318+ let host = get_host ( ) ;
319+ let target = get_target ( & host) ;
316320 let tmpdir = tempfile:: Builder :: new ( ) . prefix ( "miri-uitest-" ) . tempdir ( ) ?;
317321
318322 let mut args = std:: env:: args_os ( ) ;
@@ -329,7 +333,7 @@ fn main() -> Result<()> {
329333 ui ( Mode :: Panic , "tests/panic" , & target, WithDependencies , tmpdir. path ( ) ) ?;
330334 ui ( Mode :: Fail , "tests/fail" , & target, WithoutDependencies , tmpdir. path ( ) ) ?;
331335 ui ( Mode :: Fail , "tests/fail-dep" , & target, WithDependencies , tmpdir. path ( ) ) ?;
332- if cfg ! ( unix) {
336+ if cfg ! ( unix) && target == host {
333337 ui ( Mode :: Pass , "tests/native-lib/pass" , & target, WithoutDependencies , tmpdir. path ( ) ) ?;
334338 ui ( Mode :: Fail , "tests/native-lib/fail" , & target, WithoutDependencies , tmpdir. path ( ) ) ?;
335339 }
0 commit comments