@@ -2253,31 +2253,16 @@ impl Build {
2253
2253
Catalyst ( & ' static str ) ,
2254
2254
}
2255
2255
2256
- enum Os {
2257
- MacOs ,
2258
- Ios ,
2259
- WatchOs ,
2260
- }
2261
- impl Display for Os {
2262
- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
2263
- match self {
2264
- Os :: MacOs => f. write_str ( "macOS" ) ,
2265
- Os :: Ios => f. write_str ( "iOS" ) ,
2266
- Os :: WatchOs => f. write_str ( "WatchOS" ) ,
2267
- }
2268
- }
2269
- }
2270
-
2271
2256
let target = self . get_target ( ) ?;
2272
2257
let os = if target. contains ( "-darwin" ) {
2273
- Os :: MacOs
2258
+ AppleOs :: MacOs
2274
2259
} else if target. contains ( "-watchos" ) {
2275
- Os :: WatchOs
2260
+ AppleOs :: WatchOs
2276
2261
} else {
2277
- Os :: Ios
2262
+ AppleOs :: Ios
2278
2263
} ;
2279
2264
let is_mac = match os {
2280
- Os :: MacOs => true ,
2265
+ AppleOs :: MacOs => true ,
2281
2266
_ => false ,
2282
2267
} ;
2283
2268
@@ -2351,29 +2336,11 @@ impl Build {
2351
2336
}
2352
2337
} ;
2353
2338
2354
- let ( sdk_prefix, sim_prefix, min_version) = match os {
2355
- Os :: MacOs => (
2356
- "macosx" ,
2357
- "" ,
2358
- std:: env:: var ( "MACOSX_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| {
2359
- ( if arch_str == "aarch64" {
2360
- "11.0"
2361
- } else {
2362
- "10.7"
2363
- } )
2364
- . into ( )
2365
- } ) ,
2366
- ) ,
2367
- Os :: Ios => (
2368
- "iphone" ,
2369
- "ios-" ,
2370
- std:: env:: var ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "7.0" . into ( ) ) ,
2371
- ) ,
2372
- Os :: WatchOs => (
2373
- "watch" ,
2374
- "watch" ,
2375
- std:: env:: var ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "2.0" . into ( ) ) ,
2376
- ) ,
2339
+ let min_version = self . apple_deployment_version ( os, & target, arch_str) ;
2340
+ let ( sdk_prefix, sim_prefix) = match os {
2341
+ AppleOs :: MacOs => ( "macosx" , "" ) ,
2342
+ AppleOs :: Ios => ( "iphone" , "ios-" ) ,
2343
+ AppleOs :: WatchOs => ( "watch" , "watch" ) ,
2377
2344
} ;
2378
2345
2379
2346
let sdk = match arch {
@@ -3323,6 +3290,61 @@ impl Build {
3323
3290
Ok ( ret)
3324
3291
}
3325
3292
3293
+ fn apple_deployment_version ( & self , os : AppleOs , target : & str , arch_str : & str ) -> String {
3294
+ fn rustc_provided_target ( rustc : Option < & str > , target : & str ) -> Option < String > {
3295
+ let rustc = rustc?;
3296
+ let output = Command :: new ( rustc)
3297
+ . stderr ( Stdio :: piped ( ) )
3298
+ . stdout ( Stdio :: piped ( ) )
3299
+ . args ( & [ "--target" , target] )
3300
+ . args ( & [ "--print" , "deployment-target" ] )
3301
+ . output ( )
3302
+ . ok ( ) ?;
3303
+
3304
+ if output. status . success ( ) {
3305
+ std:: str:: from_utf8 ( & output. stdout )
3306
+ . unwrap ( )
3307
+ . split ( '=' )
3308
+ . last ( )
3309
+ . map ( |v| v. trim ( ) )
3310
+ . map ( ToString :: to_string)
3311
+ } else {
3312
+ // rustc is < 1.71
3313
+ None
3314
+ }
3315
+ }
3316
+
3317
+ let rustc = self . getenv ( "RUSTC" ) ;
3318
+ let rustc = rustc. as_deref ( ) ;
3319
+ // note the hardcoded minimums here are subject to change in a future compiler release,
3320
+ // so the ones rustc knows about are preferred. For any compiler version that has bumped them
3321
+ // though, `--print deployment-target` will be present and the fallbacks won't be used.
3322
+ //
3323
+ // the ordering of env -> rustc -> old defaults is intentional for performance when using
3324
+ // an explicit target
3325
+ match os {
3326
+ AppleOs :: MacOs => env:: var ( "MACOSX_DEPLOYMENT_TARGET" )
3327
+ . ok ( )
3328
+ . or_else ( || rustc_provided_target ( rustc, target) )
3329
+ . unwrap_or_else ( || {
3330
+ if arch_str == "aarch64" {
3331
+ "11.0"
3332
+ } else {
3333
+ "10.7"
3334
+ }
3335
+ . into ( )
3336
+ } ) ,
3337
+ AppleOs :: Ios => env:: var ( "IPHONEOS_DEPLOYMENT_TARGET" )
3338
+ . ok ( )
3339
+ . or_else ( || rustc_provided_target ( rustc, target) )
3340
+ . unwrap_or_else ( || "7.0" . into ( ) ) ,
3341
+ AppleOs :: WatchOs => env:: var ( "WATCHOS_DEPLOYMENT_TARGET" )
3342
+ . ok ( )
3343
+ . or_else ( || rustc_provided_target ( rustc, target) )
3344
+ . unwrap_or_else ( || "2.0" . into ( ) ) ,
3345
+ }
3346
+ }
3347
+
3326
3348
fn cuda_file_count ( & self ) -> usize {
3327
3349
self . files
3328
3350
. iter ( )
@@ -3676,6 +3698,22 @@ fn command_add_output_file(
3676
3698
}
3677
3699
}
3678
3700
3701
+ #[ derive( Clone , Copy ) ]
3702
+ enum AppleOs {
3703
+ MacOs ,
3704
+ Ios ,
3705
+ WatchOs ,
3706
+ }
3707
+ impl Display for AppleOs {
3708
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
3709
+ match self {
3710
+ AppleOs :: MacOs => f. write_str ( "macOS" ) ,
3711
+ AppleOs :: Ios => f. write_str ( "iOS" ) ,
3712
+ AppleOs :: WatchOs => f. write_str ( "WatchOS" ) ,
3713
+ }
3714
+ }
3715
+ }
3716
+
3679
3717
// Use by default minimum available API level
3680
3718
// See note about naming here
3681
3719
// https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r21/docs/BuildSystemMaintainers.md#Clang
0 commit comments