@@ -1423,7 +1423,16 @@ impl Build {
1423
1423
if !( target. contains ( "android" )
1424
1424
&& android_clang_compiler_uses_target_arg_internally ( & cmd. path ) )
1425
1425
{
1426
- cmd. args . push ( format ! ( "--target={}" , target) . into ( ) ) ;
1426
+ if target. contains ( "darwin" ) {
1427
+ if let Some ( arch) =
1428
+ map_darwin_target_from_rust_to_compiler_architecture ( target)
1429
+ {
1430
+ cmd. args
1431
+ . push ( format ! ( "--target={}-apple-darwin" , arch) . into ( ) ) ;
1432
+ }
1433
+ } else {
1434
+ cmd. args . push ( format ! ( "--target={}" , target) . into ( ) ) ;
1435
+ }
1427
1436
}
1428
1437
}
1429
1438
ToolFamily :: Msvc { clang_cl } => {
@@ -1471,15 +1480,10 @@ impl Build {
1471
1480
}
1472
1481
1473
1482
if target. contains ( "darwin" ) {
1474
- if target. contains ( "x86_64" ) {
1475
- cmd. args . push ( "-arch" . into ( ) ) ;
1476
- cmd. args . push ( "x86_64" . into ( ) ) ;
1477
- } else if target. contains ( "arm64e" ) {
1483
+ if let Some ( arch) = map_darwin_target_from_rust_to_compiler_architecture ( target)
1484
+ {
1478
1485
cmd. args . push ( "-arch" . into ( ) ) ;
1479
- cmd. args . push ( "arm64e" . into ( ) ) ;
1480
- } else if target. contains ( "aarch64" ) {
1481
- cmd. args . push ( "-arch" . into ( ) ) ;
1482
- cmd. args . push ( "arm64" . into ( ) ) ;
1486
+ cmd. args . push ( arch. into ( ) ) ;
1483
1487
}
1484
1488
}
1485
1489
@@ -2962,3 +2966,16 @@ fn autodetect_android_compiler(target: &str, host: &str, gnu: &str, clang: &str)
2962
2966
clang_compiler
2963
2967
}
2964
2968
}
2969
+
2970
+ // Rust and clang/cc don't agree on how to name the target.
2971
+ fn map_darwin_target_from_rust_to_compiler_architecture ( target : & str ) -> Option < & ' static str > {
2972
+ if target. contains ( "x86_64" ) {
2973
+ Some ( "x86_64" )
2974
+ } else if target. contains ( "arm64e" ) {
2975
+ Some ( "arm64e" )
2976
+ } else if target. contains ( "aarch64" ) {
2977
+ Some ( "arm64" )
2978
+ } else {
2979
+ None
2980
+ }
2981
+ }
0 commit comments