@@ -29,20 +29,17 @@ fn miri_path() -> PathBuf {
29
29
PathBuf :: from ( env:: var ( "MIRI" ) . unwrap_or_else ( |_| env ! ( "CARGO_BIN_EXE_miri" ) . into ( ) ) )
30
30
}
31
31
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
-
38
32
pub fn flagsplit ( flags : & str ) -> Vec < String > {
39
33
// This code is taken from `RUSTFLAGS` handling in cargo.
40
34
flags. split ( ' ' ) . map ( str:: trim) . filter ( |s| !s. is_empty ( ) ) . map ( str:: to_string) . collect ( )
41
35
}
42
36
43
37
// 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 ( ) ) ;
46
43
// Target directory that we can write to.
47
44
let so_target_dir = Path :: new ( env ! ( "CARGO_TARGET_TMPDIR" ) ) . join ( "miri-native-lib" ) ;
48
45
// Create the directory if it does not already exist.
@@ -201,7 +198,7 @@ fn run_tests(
201
198
// If we're testing the native-lib functionality, then build the shared object file for testing
202
199
// external C function calls and push the relevant compiler flag.
203
200
if path. starts_with ( "tests/native-lib/" ) {
204
- let native_lib = build_native_lib ( ) ;
201
+ let native_lib = build_native_lib ( target ) ;
205
202
let mut flag = std:: ffi:: OsString :: from ( "-Zmiri-native-lib=" ) ;
206
203
flag. push ( native_lib. into_os_string ( ) ) ;
207
204
config. program . args . push ( flag) ;
@@ -305,14 +302,21 @@ fn ui(
305
302
. with_context ( || format ! ( "ui tests in {path} for {target} failed" ) )
306
303
}
307
304
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 ( ) )
310
313
}
311
314
312
315
fn main ( ) -> Result < ( ) > {
313
316
ui_test:: color_eyre:: install ( ) ?;
314
317
315
- let target = get_target ( ) ;
318
+ let host = get_host ( ) ;
319
+ let target = get_target ( & host) ;
316
320
let tmpdir = tempfile:: Builder :: new ( ) . prefix ( "miri-uitest-" ) . tempdir ( ) ?;
317
321
318
322
let mut args = std:: env:: args_os ( ) ;
@@ -329,7 +333,7 @@ fn main() -> Result<()> {
329
333
ui ( Mode :: Panic , "tests/panic" , & target, WithDependencies , tmpdir. path ( ) ) ?;
330
334
ui ( Mode :: Fail , "tests/fail" , & target, WithoutDependencies , tmpdir. path ( ) ) ?;
331
335
ui ( Mode :: Fail , "tests/fail-dep" , & target, WithDependencies , tmpdir. path ( ) ) ?;
332
- if cfg ! ( unix) {
336
+ if cfg ! ( unix) && target == host {
333
337
ui ( Mode :: Pass , "tests/native-lib/pass" , & target, WithoutDependencies , tmpdir. path ( ) ) ?;
334
338
ui ( Mode :: Fail , "tests/native-lib/fail" , & target, WithoutDependencies , tmpdir. path ( ) ) ?;
335
339
}
0 commit comments