@@ -325,8 +325,6 @@ pub struct Build {
325
325
enum ErrorKind {
326
326
/// Error occurred while performing I/O.
327
327
IOError ,
328
- /// Invalid architecture supplied.
329
- ArchitectureInvalid ,
330
328
/// Environment variable not found, with the var in question as extra info.
331
329
EnvVarNotFound ,
332
330
/// Error occurred while using external tools (ie: invocation of compiler).
@@ -2134,7 +2132,7 @@ impl Build {
2134
2132
}
2135
2133
}
2136
2134
ToolFamily :: Gnu => {
2137
- if target. os == "macos " {
2135
+ if target. vendor == "apple " {
2138
2136
let arch = map_darwin_target_from_rust_to_compiler_architecture ( target) ;
2139
2137
cmd. args . push ( "-arch" . into ( ) ) ;
2140
2138
cmd. args . push ( arch. into ( ) ) ;
@@ -2532,113 +2530,38 @@ impl Build {
2532
2530
2533
2531
fn apple_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2534
2532
let target = self . get_target ( ) ?;
2535
- let arch_str = target. full_arch ;
2536
2533
2537
- let arch = if target. os == "macos" {
2538
- match arch_str {
2539
- "i686" => AppleArchSpec :: Device ( "-m32" ) ,
2540
- "x86_64" | "x86_64h" | "aarch64" | "arm64e" => AppleArchSpec :: Device ( "-m64" ) ,
2541
- _ => {
2542
- return Err ( Error :: new (
2543
- ErrorKind :: ArchitectureInvalid ,
2544
- "Unknown architecture for macOS target." ,
2545
- ) ) ;
2546
- }
2547
- }
2548
- } else if target. abi == "macabi" {
2549
- match arch_str {
2550
- "arm64e" => AppleArchSpec :: Catalyst ( "arm64e" ) ,
2551
- "arm64" | "aarch64" => AppleArchSpec :: Catalyst ( "arm64" ) ,
2552
- "x86_64" | "x86_64h" => AppleArchSpec :: Catalyst ( "-m64" ) ,
2553
- _ => {
2554
- return Err ( Error :: new (
2555
- ErrorKind :: ArchitectureInvalid ,
2556
- "Unknown architecture for iOS target." ,
2557
- ) ) ;
2558
- }
2559
- }
2560
- } else if target. abi == "sim" {
2561
- match arch_str {
2562
- "arm64" | "aarch64" => AppleArchSpec :: Simulator ( "arm64" ) ,
2563
- "i386" | "i686" => AppleArchSpec :: Simulator ( "-m32" ) ,
2564
- "x86_64" | "x86_64h" => AppleArchSpec :: Simulator ( "-m64" ) ,
2565
- _ => {
2566
- return Err ( Error :: new (
2567
- ErrorKind :: ArchitectureInvalid ,
2568
- "Unknown architecture for simulator target." ,
2569
- ) ) ;
2570
- }
2571
- }
2572
- } else {
2573
- match arch_str {
2574
- "arm" | "armv7" | "thumbv7" => AppleArchSpec :: Device ( "armv7" ) ,
2575
- "armv7k" => AppleArchSpec :: Device ( "armv7k" ) ,
2576
- "armv7s" | "thumbv7s" => AppleArchSpec :: Device ( "armv7s" ) ,
2577
- "arm64e" => AppleArchSpec :: Device ( "arm64e" ) ,
2578
- "arm64" | "aarch64" => AppleArchSpec :: Device ( "arm64" ) ,
2579
- "arm64_32" => AppleArchSpec :: Device ( "arm64_32" ) ,
2580
- _ => {
2581
- return Err ( Error :: new (
2582
- ErrorKind :: ArchitectureInvalid ,
2583
- format ! ( "Unknown architecture for {:?} target." , target. os) ,
2584
- ) ) ;
2585
- }
2586
- }
2587
- } ;
2588
-
2589
- let sdk_details = apple_os_sdk_parts ( target. os , & arch) ;
2590
- let min_version = self . apple_deployment_target ( & target) ;
2591
-
2592
- match arch {
2593
- AppleArchSpec :: Device ( _) if target. os == "macos" => {
2594
- cmd. args
2595
- . push ( format ! ( "-mmacosx-version-min={}" , min_version) . into ( ) ) ;
2596
- }
2597
- AppleArchSpec :: Device ( arch) => {
2598
- cmd. args . push ( "-arch" . into ( ) ) ;
2599
- cmd. args . push ( arch. into ( ) ) ;
2600
- // `-mxros-version-min` does not exist
2601
- // https://github.com/llvm/llvm-project/issues/88271
2602
- if target. os != "visionos" {
2603
- cmd. args . push (
2604
- format ! ( "-m{}os-version-min={}" , sdk_details. sdk_prefix, min_version)
2605
- . into ( ) ,
2606
- ) ;
2607
- }
2608
- }
2609
- AppleArchSpec :: Simulator ( arch) => {
2610
- if arch. starts_with ( '-' ) {
2611
- // -m32 or -m64
2612
- cmd. args . push ( arch. into ( ) ) ;
2613
- } else {
2614
- cmd. args . push ( "-arch" . into ( ) ) ;
2615
- cmd. args . push ( arch. into ( ) ) ;
2616
- }
2617
- if target. os != "visionos" {
2618
- cmd. args . push (
2619
- format ! (
2620
- "-m{}simulator-version-min={}" ,
2621
- sdk_details. sim_prefix, min_version
2622
- )
2623
- . into ( ) ,
2624
- ) ;
2625
- }
2626
- }
2627
- AppleArchSpec :: Catalyst ( _) => { }
2628
- } ;
2534
+ // If the compiler is Clang, then we've already specifed the target
2535
+ // information (including the deployment target) with the `--target`
2536
+ // option, so we don't need to do anything further here.
2537
+ //
2538
+ // If the compiler is GCC, then we need to specify
2539
+ // `-mmacosx-version-min` to set the deployment target, as well
2540
+ // as to say that the target OS is macOS.
2541
+ //
2542
+ // NOTE: GCC does not support `-miphoneos-version-min=` etc. (because
2543
+ // it does not support iOS in general), but we specify them anyhow in
2544
+ // case we actually have a Clang-like compiler disguised as a GNU-like
2545
+ // compiler, or in case GCC adds support for these in the future.
2546
+ if !cmd. is_like_clang ( ) {
2547
+ let min_version = self . apple_deployment_target ( & target) ;
2548
+ cmd. args
2549
+ . push ( target. apple_version_flag ( & min_version) . into ( ) ) ;
2550
+ }
2629
2551
2630
2552
// AppleClang sometimes requires sysroot even on macOS
2631
2553
if cmd. is_xctoolchain_clang ( ) || target. os != "macos" {
2632
2554
self . cargo_output . print_metadata ( & format_args ! (
2633
2555
"Detecting {:?} SDK path for {}" ,
2634
- target. os, sdk_details. sdk
2556
+ target. os,
2557
+ target. apple_sdk_name( ) ,
2635
2558
) ) ;
2636
- let sdk_path = self . apple_sdk_root ( & sdk_details . sdk ) ?;
2559
+ let sdk_path = self . apple_sdk_root ( & target ) ?;
2637
2560
2638
2561
cmd. args . push ( "-isysroot" . into ( ) ) ;
2639
2562
cmd. args . push ( OsStr :: new ( & sdk_path) . to_owned ( ) ) ;
2640
2563
2641
- if let AppleArchSpec :: Catalyst ( _ ) = arch {
2564
+ if target . abi == "macabi" {
2642
2565
// Mac Catalyst uses the macOS SDK, but to compile against and
2643
2566
// link to iOS-specific frameworks, we should have the support
2644
2567
// library stubs in the include and library search path.
@@ -3719,7 +3642,9 @@ impl Build {
3719
3642
Ok ( Arc :: from ( OsStr :: new ( sdk_path. trim ( ) ) ) )
3720
3643
}
3721
3644
3722
- fn apple_sdk_root ( & self , sdk : & str ) -> Result < Arc < OsStr > , Error > {
3645
+ fn apple_sdk_root ( & self , target : & TargetInfo ) -> Result < Arc < OsStr > , Error > {
3646
+ let sdk = target. apple_sdk_name ( ) ;
3647
+
3723
3648
if let Some ( ret) = self
3724
3649
. build_cache
3725
3650
. apple_sdk_root_cache
@@ -3974,43 +3899,6 @@ fn fail(s: &str) -> ! {
3974
3899
std:: process:: exit ( 1 ) ;
3975
3900
}
3976
3901
3977
- struct AppleSdkTargetParts {
3978
- sdk_prefix : & ' static str ,
3979
- sim_prefix : & ' static str ,
3980
- sdk : Cow < ' static , str > ,
3981
- }
3982
-
3983
- fn apple_os_sdk_parts ( os : & str , arch : & AppleArchSpec ) -> AppleSdkTargetParts {
3984
- let ( sdk_prefix, sim_prefix) = match os {
3985
- "macos" => ( "macosx" , "" ) ,
3986
- "ios" => ( "iphone" , "ios-" ) ,
3987
- "watchos" => ( "watch" , "watch" ) ,
3988
- "tvos" => ( "appletv" , "appletv" ) ,
3989
- "visionos" => ( "xr" , "xr" ) ,
3990
- os => unreachable ! ( "unknown Apple OS {}" , os) ,
3991
- } ;
3992
- let sdk = match arch {
3993
- AppleArchSpec :: Device ( _) if os == "macos" => Cow :: Borrowed ( "macosx" ) ,
3994
- AppleArchSpec :: Device ( _) => format ! ( "{}os" , sdk_prefix) . into ( ) ,
3995
- AppleArchSpec :: Simulator ( _) => format ! ( "{}simulator" , sdk_prefix) . into ( ) ,
3996
- AppleArchSpec :: Catalyst ( _) => Cow :: Borrowed ( "macosx" ) ,
3997
- } ;
3998
-
3999
- AppleSdkTargetParts {
4000
- sdk_prefix,
4001
- sim_prefix,
4002
- sdk,
4003
- }
4004
- }
4005
-
4006
- #[ allow( dead_code) ]
4007
- enum AppleArchSpec {
4008
- Device ( & ' static str ) ,
4009
- Simulator ( & ' static str ) ,
4010
- #[ allow( dead_code) ]
4011
- Catalyst ( & ' static str ) ,
4012
- }
4013
-
4014
3902
// Use by default minimum available API level
4015
3903
// See note about naming here
4016
3904
// https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r21/docs/BuildSystemMaintainers.md#Clang
0 commit comments