@@ -2367,31 +2367,16 @@ impl Build {
2367
2367
Catalyst ( & ' static str ) ,
2368
2368
}
2369
2369
2370
- enum Os {
2371
- MacOs ,
2372
- Ios ,
2373
- WatchOs ,
2374
- }
2375
- impl std:: fmt:: Debug for Os {
2376
- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
2377
- match self {
2378
- Os :: MacOs => f. write_str ( "macOS" ) ,
2379
- Os :: Ios => f. write_str ( "iOS" ) ,
2380
- Os :: WatchOs => f. write_str ( "WatchOS" ) ,
2381
- }
2382
- }
2383
- }
2384
-
2385
2370
let target = self . get_target ( ) ?;
2386
2371
let os = if target. contains ( "-darwin" ) {
2387
- Os :: MacOs
2372
+ AppleOs :: MacOs
2388
2373
} else if target. contains ( "-watchos" ) {
2389
- Os :: WatchOs
2374
+ AppleOs :: WatchOs
2390
2375
} else {
2391
- Os :: Ios
2376
+ AppleOs :: Ios
2392
2377
} ;
2393
2378
let is_mac = match os {
2394
- Os :: MacOs => true ,
2379
+ AppleOs :: MacOs => true ,
2395
2380
_ => false ,
2396
2381
} ;
2397
2382
@@ -2465,29 +2450,11 @@ impl Build {
2465
2450
}
2466
2451
} ;
2467
2452
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
- ) ,
2481
- Os :: Ios => (
2482
- "iphone" ,
2483
- "ios-" ,
2484
- std:: env:: var ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "7.0" . into ( ) ) ,
2485
- ) ,
2486
- Os :: WatchOs => (
2487
- "watch" ,
2488
- "watch" ,
2489
- std:: env:: var ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "2.0" . into ( ) ) ,
2490
- ) ,
2453
+ let min_version = self . apple_deployment_version ( os, & target, arch_str) ;
2454
+ let ( sdk_prefix, sim_prefix) = match os {
2455
+ AppleOs :: MacOs => ( "macosx" , "" ) ,
2456
+ AppleOs :: Ios => ( "iphone" , "ios-" ) ,
2457
+ AppleOs :: WatchOs => ( "watch" , "watch" ) ,
2491
2458
} ;
2492
2459
2493
2460
let sdk = match arch {
@@ -3437,6 +3404,58 @@ impl Build {
3437
3404
Ok ( ret)
3438
3405
}
3439
3406
3407
+ fn apple_deployment_version ( & self , os : AppleOs , target : & str , arch_str : & str ) -> String {
3408
+ fn rustc_provided_target ( rustc : Option < & str > , target : & str ) -> Option < String > {
3409
+ let rustc = rustc?;
3410
+ let output = Command :: new ( rustc)
3411
+ . args ( & [ "--target" , target] )
3412
+ . args ( & [ "--print" , "deployment-target" ] )
3413
+ . output ( )
3414
+ . ok ( ) ?;
3415
+
3416
+ if output. status . success ( ) {
3417
+ std:: str:: from_utf8 ( & output. stdout )
3418
+ . unwrap ( )
3419
+ . strip_prefix ( "deployment_target=" )
3420
+ . map ( |v| v. trim ( ) )
3421
+ . map ( ToString :: to_string)
3422
+ } else {
3423
+ // rustc is < 1.71
3424
+ None
3425
+ }
3426
+ }
3427
+
3428
+ let rustc = self . getenv ( "RUSTC" ) ;
3429
+ let rustc = rustc. as_deref ( ) ;
3430
+ // note the hardcoded minimums here are subject to change in a future compiler release,
3431
+ // so the ones rustc knows about are preferred. For any compiler version that has bumped them
3432
+ // though, `--print deployment-target` will be present and the fallbacks won't be used.
3433
+ //
3434
+ // the ordering of env -> rustc -> old defaults is intentional for performance when using
3435
+ // an explicit target
3436
+ match os {
3437
+ AppleOs :: MacOs => env:: var ( "MACOSX_DEPLOYMENT_TARGET" )
3438
+ . ok ( )
3439
+ . or_else ( || rustc_provided_target ( rustc, target) )
3440
+ . unwrap_or_else ( || {
3441
+ if arch_str == "aarch64" {
3442
+ "11.0"
3443
+ } else {
3444
+ "10.7"
3445
+ }
3446
+ . into ( )
3447
+ } ) ,
3448
+ AppleOs :: Ios => env:: var ( "IPHONEOS_DEPLOYMENT_TARGET" )
3449
+ . ok ( )
3450
+ . or_else ( || rustc_provided_target ( rustc, target) )
3451
+ . unwrap_or_else ( || "7.0" . into ( ) ) ,
3452
+ AppleOs :: WatchOs => env:: var ( "WATCHOS_DEPLOYMENT_TARGET" )
3453
+ . ok ( )
3454
+ . or_else ( || rustc_provided_target ( rustc, target) )
3455
+ . unwrap_or_else ( || "2.0" . into ( ) ) ,
3456
+ }
3457
+ }
3458
+
3440
3459
fn cuda_file_count ( & self ) -> usize {
3441
3460
self . files
3442
3461
. iter ( )
@@ -3824,6 +3843,22 @@ fn command_add_output_file(
3824
3843
}
3825
3844
}
3826
3845
3846
+ #[ derive( Clone , Copy ) ]
3847
+ enum AppleOs {
3848
+ MacOs ,
3849
+ Ios ,
3850
+ WatchOs ,
3851
+ }
3852
+ impl std:: fmt:: Debug for AppleOs {
3853
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
3854
+ match self {
3855
+ AppleOs :: MacOs => f. write_str ( "macOS" ) ,
3856
+ AppleOs :: Ios => f. write_str ( "iOS" ) ,
3857
+ AppleOs :: WatchOs => f. write_str ( "WatchOS" ) ,
3858
+ }
3859
+ }
3860
+ }
3861
+
3827
3862
// Use by default minimum available API level
3828
3863
// See note about naming here
3829
3864
// https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r21/docs/BuildSystemMaintainers.md#Clang
0 commit comments