@@ -2027,8 +2027,8 @@ impl Build {
2027
2027
}
2028
2028
}
2029
2029
2030
- if target. contains ( "apple-ios" ) || target . contains ( " apple-watchos ") {
2031
- self . ios_watchos_flags ( cmd) ?;
2030
+ if target. contains ( "- apple-" ) {
2031
+ self . apple_flags ( cmd) ?;
2032
2032
}
2033
2033
2034
2034
if self . static_flag . unwrap_or ( false ) {
@@ -2246,34 +2246,42 @@ impl Build {
2246
2246
Ok ( ( ) )
2247
2247
}
2248
2248
2249
- fn ios_watchos_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2249
+ fn apple_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2250
2250
enum ArchSpec {
2251
2251
Device ( & ' static str ) ,
2252
2252
Simulator ( & ' static str ) ,
2253
2253
Catalyst ( & ' static str ) ,
2254
2254
}
2255
2255
2256
2256
enum Os {
2257
+ MacOs ,
2257
2258
Ios ,
2258
2259
WatchOs ,
2259
2260
}
2260
2261
impl Display for Os {
2261
2262
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
2262
2263
match self {
2264
+ Os :: MacOs => f. write_str ( "macOS" ) ,
2263
2265
Os :: Ios => f. write_str ( "iOS" ) ,
2264
2266
Os :: WatchOs => f. write_str ( "WatchOS" ) ,
2265
2267
}
2266
2268
}
2267
2269
}
2268
2270
2269
2271
let target = self . get_target ( ) ?;
2270
- let os = if target. contains ( "-watchos" ) {
2272
+ let os = if target. contains ( "-darwin" ) {
2273
+ Os :: MacOs
2274
+ } else if target. contains ( "-watchos" ) {
2271
2275
Os :: WatchOs
2272
2276
} else {
2273
2277
Os :: Ios
2274
2278
} ;
2279
+ let is_mac = match os {
2280
+ Os :: MacOs => true ,
2281
+ _ => false ,
2282
+ } ;
2275
2283
2276
- let arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2284
+ let arch_str = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2277
2285
Error :: new (
2278
2286
ErrorKind :: ArchitectureInvalid ,
2279
2287
format ! ( "Unknown architecture for {} target." , os) ,
@@ -2290,8 +2298,19 @@ impl Build {
2290
2298
None => false ,
2291
2299
} ;
2292
2300
2293
- let arch = if is_catalyst {
2294
- match arch {
2301
+ let arch = if is_mac {
2302
+ match arch_str {
2303
+ "i686" => ArchSpec :: Device ( "-m32" ) ,
2304
+ "x86_64" | "aarch64" => ArchSpec :: Device ( "-m64" ) ,
2305
+ _ => {
2306
+ return Err ( Error :: new (
2307
+ ErrorKind :: ArchitectureInvalid ,
2308
+ "Unknown architecture for macOS target." ,
2309
+ ) ) ;
2310
+ }
2311
+ }
2312
+ } else if is_catalyst {
2313
+ match arch_str {
2295
2314
"arm64e" => ArchSpec :: Catalyst ( "arm64e" ) ,
2296
2315
"arm64" | "aarch64" => ArchSpec :: Catalyst ( "arm64" ) ,
2297
2316
"x86_64" => ArchSpec :: Catalyst ( "-m64" ) ,
@@ -2303,7 +2322,7 @@ impl Build {
2303
2322
}
2304
2323
}
2305
2324
} else if is_sim {
2306
- match arch {
2325
+ match arch_str {
2307
2326
"arm64" | "aarch64" => ArchSpec :: Simulator ( "arm64" ) ,
2308
2327
"x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2309
2328
_ => {
@@ -2314,7 +2333,7 @@ impl Build {
2314
2333
}
2315
2334
}
2316
2335
} else {
2317
- match arch {
2336
+ match arch_str {
2318
2337
"arm" | "armv7" | "thumbv7" => ArchSpec :: Device ( "armv7" ) ,
2319
2338
"armv7k" => ArchSpec :: Device ( "armv7k" ) ,
2320
2339
"armv7s" | "thumbv7s" => ArchSpec :: Device ( "armv7s" ) ,
@@ -2333,6 +2352,18 @@ impl Build {
2333
2352
} ;
2334
2353
2335
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
+ ) ,
2336
2367
Os :: Ios => (
2337
2368
"iphone" ,
2338
2369
"ios-" ,
@@ -2346,6 +2377,11 @@ impl Build {
2346
2377
} ;
2347
2378
2348
2379
let sdk = match arch {
2380
+ ArchSpec :: Device ( _) if is_mac => {
2381
+ cmd. args
2382
+ . push ( format ! ( "-mmacosx-version-min={}" , min_version) . into ( ) ) ;
2383
+ "macosx" . to_owned ( )
2384
+ }
2349
2385
ArchSpec :: Device ( arch) => {
2350
2386
cmd. args . push ( "-arch" . into ( ) ) ;
2351
2387
cmd. args . push ( arch. into ( ) ) ;
@@ -2368,17 +2404,19 @@ impl Build {
2368
2404
ArchSpec :: Catalyst ( _) => "macosx" . to_owned ( ) ,
2369
2405
} ;
2370
2406
2371
- self . print ( & format_args ! ( "Detecting {} SDK path for {}" , os, sdk) ) ;
2372
- let sdk_path = if let Some ( sdkroot) = env:: var_os ( "SDKROOT" ) {
2373
- sdkroot
2374
- } else {
2375
- self . apple_sdk_root ( sdk. as_str ( ) ) ?
2376
- } ;
2407
+ if !is_mac {
2408
+ self . print ( & format_args ! ( "Detecting {} SDK path for {}" , os, sdk) ) ;
2409
+ let sdk_path = if let Some ( sdkroot) = env:: var_os ( "SDKROOT" ) {
2410
+ sdkroot
2411
+ } else {
2412
+ self . apple_sdk_root ( sdk. as_str ( ) ) ?
2413
+ } ;
2377
2414
2378
- cmd. args . push ( "-isysroot" . into ( ) ) ;
2379
- cmd. args . push ( sdk_path) ;
2380
- // TODO: Remove this once Apple stops accepting apps built with Xcode 13
2381
- cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2415
+ cmd. args . push ( "-isysroot" . into ( ) ) ;
2416
+ cmd. args . push ( sdk_path) ;
2417
+ // TODO: Remove this once Apple stops accepting apps built with Xcode 13
2418
+ cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2419
+ }
2382
2420
2383
2421
Ok ( ( ) )
2384
2422
}
0 commit comments