@@ -1994,8 +1994,8 @@ impl Build {
1994
1994
}
1995
1995
}
1996
1996
1997
- if target. contains ( "apple-ios" ) || target . contains ( " apple-watchos ") {
1998
- self . ios_watchos_flags ( cmd) ?;
1997
+ if target. contains ( "- apple-" ) {
1998
+ self . apple_flags ( cmd) ?;
1999
1999
}
2000
2000
2001
2001
if self . static_flag . unwrap_or ( false ) {
@@ -2205,34 +2205,42 @@ impl Build {
2205
2205
Ok ( ( ) )
2206
2206
}
2207
2207
2208
- fn ios_watchos_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2208
+ fn apple_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2209
2209
enum ArchSpec {
2210
2210
Device ( & ' static str ) ,
2211
2211
Simulator ( & ' static str ) ,
2212
2212
Catalyst ( & ' static str ) ,
2213
2213
}
2214
2214
2215
2215
enum Os {
2216
+ MacOs ,
2216
2217
Ios ,
2217
2218
WatchOs ,
2218
2219
}
2219
2220
impl Display for Os {
2220
2221
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
2221
2222
match self {
2223
+ Os :: MacOs => f. write_str ( "macOS" ) ,
2222
2224
Os :: Ios => f. write_str ( "iOS" ) ,
2223
2225
Os :: WatchOs => f. write_str ( "WatchOS" ) ,
2224
2226
}
2225
2227
}
2226
2228
}
2227
2229
2228
2230
let target = self . get_target ( ) ?;
2229
- let os = if target. contains ( "-watchos" ) {
2231
+ let os = if target. contains ( "-darwin" ) {
2232
+ Os :: MacOs
2233
+ } else if target. contains ( "-watchos" ) {
2230
2234
Os :: WatchOs
2231
2235
} else {
2232
2236
Os :: Ios
2233
2237
} ;
2238
+ let is_mac = match os {
2239
+ Os :: MacOs => true ,
2240
+ _ => false ,
2241
+ } ;
2234
2242
2235
- let arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2243
+ let arch_str = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2236
2244
Error :: new (
2237
2245
ErrorKind :: ArchitectureInvalid ,
2238
2246
format ! ( "Unknown architecture for {} target." , os) . as_str ( ) ,
@@ -2249,8 +2257,19 @@ impl Build {
2249
2257
None => false ,
2250
2258
} ;
2251
2259
2252
- let arch = if is_catalyst {
2253
- match arch {
2260
+ let arch = if is_mac {
2261
+ match arch_str {
2262
+ "i686" => ArchSpec :: Device ( "-m32" ) ,
2263
+ "x86_64" | "aarch64" => ArchSpec :: Device ( "-m64" ) ,
2264
+ _ => {
2265
+ return Err ( Error :: new (
2266
+ ErrorKind :: ArchitectureInvalid ,
2267
+ "Unknown architecture for macOS target." ,
2268
+ ) ) ;
2269
+ }
2270
+ }
2271
+ } else if is_catalyst {
2272
+ match arch_str {
2254
2273
"arm64e" => ArchSpec :: Catalyst ( "arm64e" ) ,
2255
2274
"arm64" | "aarch64" => ArchSpec :: Catalyst ( "arm64" ) ,
2256
2275
"x86_64" => ArchSpec :: Catalyst ( "-m64" ) ,
@@ -2262,7 +2281,7 @@ impl Build {
2262
2281
}
2263
2282
}
2264
2283
} else if is_sim {
2265
- match arch {
2284
+ match arch_str {
2266
2285
"arm64" | "aarch64" => ArchSpec :: Simulator ( "arm64" ) ,
2267
2286
"x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2268
2287
_ => {
@@ -2273,7 +2292,7 @@ impl Build {
2273
2292
}
2274
2293
}
2275
2294
} else {
2276
- match arch {
2295
+ match arch_str {
2277
2296
"arm" | "armv7" | "thumbv7" => ArchSpec :: Device ( "armv7" ) ,
2278
2297
"armv7k" => ArchSpec :: Device ( "armv7k" ) ,
2279
2298
"armv7s" | "thumbv7s" => ArchSpec :: Device ( "armv7s" ) ,
@@ -2292,6 +2311,18 @@ impl Build {
2292
2311
} ;
2293
2312
2294
2313
let ( sdk_prefix, sim_prefix, min_version) = match os {
2314
+ Os :: MacOs => (
2315
+ "macosx" ,
2316
+ "" ,
2317
+ std:: env:: var ( "MACOSX_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| {
2318
+ ( if arch_str == "aarch64" {
2319
+ "11.0"
2320
+ } else {
2321
+ "10.7"
2322
+ } )
2323
+ . into ( )
2324
+ } ) ,
2325
+ ) ,
2295
2326
Os :: Ios => (
2296
2327
"iphone" ,
2297
2328
"ios-" ,
@@ -2305,6 +2336,11 @@ impl Build {
2305
2336
} ;
2306
2337
2307
2338
let sdk = match arch {
2339
+ ArchSpec :: Device ( _) if is_mac => {
2340
+ cmd. args
2341
+ . push ( format ! ( "-mmacosx-version-min={}" , min_version) . into ( ) ) ;
2342
+ "macosx" . to_owned ( )
2343
+ }
2308
2344
ArchSpec :: Device ( arch) => {
2309
2345
cmd. args . push ( "-arch" . into ( ) ) ;
2310
2346
cmd. args . push ( arch. into ( ) ) ;
@@ -2327,17 +2363,19 @@ impl Build {
2327
2363
ArchSpec :: Catalyst ( _) => "macosx" . to_owned ( ) ,
2328
2364
} ;
2329
2365
2330
- self . print ( & format ! ( "Detecting {} SDK path for {}" , os, sdk) ) ;
2331
- let sdk_path = if let Some ( sdkroot) = env:: var_os ( "SDKROOT" ) {
2332
- sdkroot
2333
- } else {
2334
- self . apple_sdk_root ( sdk. as_str ( ) ) ?
2335
- } ;
2366
+ if !is_mac {
2367
+ self . print ( & format ! ( "Detecting {} SDK path for {}" , os, sdk) ) ;
2368
+ let sdk_path = if let Some ( sdkroot) = env:: var_os ( "SDKROOT" ) {
2369
+ sdkroot
2370
+ } else {
2371
+ self . apple_sdk_root ( sdk. as_str ( ) ) ?
2372
+ } ;
2336
2373
2337
- cmd. args . push ( "-isysroot" . into ( ) ) ;
2338
- cmd. args . push ( sdk_path) ;
2339
- // TODO: Remove this once Apple stops accepting apps built with Xcode 13
2340
- cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2374
+ cmd. args . push ( "-isysroot" . into ( ) ) ;
2375
+ cmd. args . push ( sdk_path) ;
2376
+ // TODO: Remove this once Apple stops accepting apps built with Xcode 13
2377
+ cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2378
+ }
2341
2379
2342
2380
Ok ( ( ) )
2343
2381
}
0 commit comments