@@ -1423,7 +1423,16 @@ impl Build {
14231423 if !( target. contains ( "android" )
14241424 && android_clang_compiler_uses_target_arg_internally ( & cmd. path ) )
14251425 {
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+ }
14271436 }
14281437 }
14291438 ToolFamily :: Msvc { clang_cl } => {
@@ -1471,15 +1480,10 @@ impl Build {
14711480 }
14721481
14731482 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+ {
14781485 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 ( ) ) ;
14831487 }
14841488 }
14851489
@@ -2962,3 +2966,16 @@ fn autodetect_android_compiler(target: &str, host: &str, gnu: &str, clang: &str)
29622966 clang_compiler
29632967 }
29642968}
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