@@ -2141,8 +2141,8 @@ impl Build {
2141
2141
}
2142
2142
}
2143
2143
2144
- if target. contains ( "apple-ios" ) || target . contains ( " apple-watchos ") {
2145
- self . ios_watchos_flags ( cmd) ?;
2144
+ if target. contains ( "- apple-" ) {
2145
+ self . apple_flags ( cmd) ?;
2146
2146
}
2147
2147
2148
2148
if self . static_flag . unwrap_or ( false ) {
@@ -2360,37 +2360,45 @@ impl Build {
2360
2360
Ok ( ( ) )
2361
2361
}
2362
2362
2363
- fn ios_watchos_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2363
+ fn apple_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2364
2364
enum ArchSpec {
2365
2365
Device ( & ' static str ) ,
2366
2366
Simulator ( & ' static str ) ,
2367
2367
Catalyst ( & ' static str ) ,
2368
2368
}
2369
2369
2370
2370
enum Os {
2371
+ MacOs ,
2371
2372
Ios ,
2372
2373
WatchOs ,
2373
2374
}
2374
- impl Display for Os {
2375
+ impl std :: fmt :: Debug for Os {
2375
2376
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
2376
2377
match self {
2378
+ Os :: MacOs => f. write_str ( "macOS" ) ,
2377
2379
Os :: Ios => f. write_str ( "iOS" ) ,
2378
2380
Os :: WatchOs => f. write_str ( "WatchOS" ) ,
2379
2381
}
2380
2382
}
2381
2383
}
2382
2384
2383
2385
let target = self . get_target ( ) ?;
2384
- let os = if target. contains ( "-watchos" ) {
2386
+ let os = if target. contains ( "-darwin" ) {
2387
+ Os :: MacOs
2388
+ } else if target. contains ( "-watchos" ) {
2385
2389
Os :: WatchOs
2386
2390
} else {
2387
2391
Os :: Ios
2388
2392
} ;
2393
+ let is_mac = match os {
2394
+ Os :: MacOs => true ,
2395
+ _ => false ,
2396
+ } ;
2389
2397
2390
- let arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2398
+ let arch_str = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2391
2399
Error :: new (
2392
2400
ErrorKind :: ArchitectureInvalid ,
2393
- format ! ( "Unknown architecture for {} target." , os) ,
2401
+ format ! ( "Unknown architecture for {:? } target." , os) ,
2394
2402
)
2395
2403
} ) ?;
2396
2404
@@ -2404,11 +2412,22 @@ impl Build {
2404
2412
None => false ,
2405
2413
} ;
2406
2414
2407
- let arch = if is_catalyst {
2408
- match arch {
2415
+ let arch = if is_mac {
2416
+ match arch_str {
2417
+ "i686" => ArchSpec :: Device ( "-m32" ) ,
2418
+ "x86_64" | "x86_64h" | "aarch64" => ArchSpec :: Device ( "-m64" ) ,
2419
+ _ => {
2420
+ return Err ( Error :: new (
2421
+ ErrorKind :: ArchitectureInvalid ,
2422
+ "Unknown architecture for macOS target." ,
2423
+ ) ) ;
2424
+ }
2425
+ }
2426
+ } else if is_catalyst {
2427
+ match arch_str {
2409
2428
"arm64e" => ArchSpec :: Catalyst ( "arm64e" ) ,
2410
2429
"arm64" | "aarch64" => ArchSpec :: Catalyst ( "arm64" ) ,
2411
- "x86_64" => ArchSpec :: Catalyst ( "-m64" ) ,
2430
+ "x86_64" | "x86_64h" => ArchSpec :: Catalyst ( "-m64" ) ,
2412
2431
_ => {
2413
2432
return Err ( Error :: new (
2414
2433
ErrorKind :: ArchitectureInvalid ,
@@ -2417,9 +2436,9 @@ impl Build {
2417
2436
}
2418
2437
}
2419
2438
} else if is_sim {
2420
- match arch {
2439
+ match arch_str {
2421
2440
"arm64" | "aarch64" => ArchSpec :: Simulator ( "arm64" ) ,
2422
- "x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2441
+ "x86_64" | "x86_64h" => ArchSpec :: Simulator ( "-m64" ) ,
2423
2442
_ => {
2424
2443
return Err ( Error :: new (
2425
2444
ErrorKind :: ArchitectureInvalid ,
@@ -2428,25 +2447,37 @@ impl Build {
2428
2447
}
2429
2448
}
2430
2449
} else {
2431
- match arch {
2450
+ match arch_str {
2432
2451
"arm" | "armv7" | "thumbv7" => ArchSpec :: Device ( "armv7" ) ,
2433
2452
"armv7k" => ArchSpec :: Device ( "armv7k" ) ,
2434
2453
"armv7s" | "thumbv7s" => ArchSpec :: Device ( "armv7s" ) ,
2435
2454
"arm64e" => ArchSpec :: Device ( "arm64e" ) ,
2436
2455
"arm64" | "aarch64" => ArchSpec :: Device ( "arm64" ) ,
2437
2456
"arm64_32" => ArchSpec :: Device ( "arm64_32" ) ,
2438
2457
"i386" | "i686" => ArchSpec :: Simulator ( "-m32" ) ,
2439
- "x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2458
+ "x86_64" | "x86_64h" => ArchSpec :: Simulator ( "-m64" ) ,
2440
2459
_ => {
2441
2460
return Err ( Error :: new (
2442
2461
ErrorKind :: ArchitectureInvalid ,
2443
- format ! ( "Unknown architecture for {} target." , os) ,
2462
+ format ! ( "Unknown architecture for {:? } target." , os) ,
2444
2463
) ) ;
2445
2464
}
2446
2465
}
2447
2466
} ;
2448
2467
2449
2468
let ( sdk_prefix, sim_prefix, min_version) = match os {
2469
+ Os :: MacOs => (
2470
+ "macosx" ,
2471
+ "" ,
2472
+ std:: env:: var ( "MACOSX_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| {
2473
+ ( if arch_str == "aarch64" {
2474
+ "11.0"
2475
+ } else {
2476
+ "10.7"
2477
+ } )
2478
+ . into ( )
2479
+ } ) ,
2480
+ ) ,
2450
2481
Os :: Ios => (
2451
2482
"iphone" ,
2452
2483
"ios-" ,
@@ -2460,6 +2491,11 @@ impl Build {
2460
2491
} ;
2461
2492
2462
2493
let sdk = match arch {
2494
+ ArchSpec :: Device ( _) if is_mac => {
2495
+ cmd. args
2496
+ . push ( format ! ( "-mmacosx-version-min={}" , min_version) . into ( ) ) ;
2497
+ "macosx" . to_owned ( )
2498
+ }
2463
2499
ArchSpec :: Device ( arch) => {
2464
2500
cmd. args . push ( "-arch" . into ( ) ) ;
2465
2501
cmd. args . push ( arch. into ( ) ) ;
@@ -2482,17 +2518,19 @@ impl Build {
2482
2518
ArchSpec :: Catalyst ( _) => "macosx" . to_owned ( ) ,
2483
2519
} ;
2484
2520
2485
- self . print ( & format_args ! ( "Detecting {} SDK path for {}" , os, sdk) ) ;
2486
- let sdk_path = if let Some ( sdkroot) = env:: var_os ( "SDKROOT" ) {
2487
- sdkroot
2488
- } else {
2489
- self . apple_sdk_root ( sdk. as_str ( ) ) ?
2490
- } ;
2521
+ if !is_mac {
2522
+ self . print ( & format_args ! ( "Detecting {:?} SDK path for {}" , os, sdk) ) ;
2523
+ let sdk_path = if let Some ( sdkroot) = env:: var_os ( "SDKROOT" ) {
2524
+ sdkroot
2525
+ } else {
2526
+ self . apple_sdk_root ( sdk. as_str ( ) ) ?
2527
+ } ;
2491
2528
2492
- cmd. args . push ( "-isysroot" . into ( ) ) ;
2493
- cmd. args . push ( sdk_path) ;
2494
- // TODO: Remove this once Apple stops accepting apps built with Xcode 13
2495
- cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2529
+ cmd. args . push ( "-isysroot" . into ( ) ) ;
2530
+ cmd. args . push ( sdk_path) ;
2531
+ // TODO: Remove this once Apple stops accepting apps built with Xcode 13
2532
+ cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2533
+ }
2496
2534
2497
2535
Ok ( ( ) )
2498
2536
}
0 commit comments