@@ -2027,8 +2027,8 @@ impl Build {
20272027 }
20282028 }
20292029
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) ?;
20322032 }
20332033
20342034 if self . static_flag . unwrap_or ( false ) {
@@ -2246,34 +2246,42 @@ impl Build {
22462246 Ok ( ( ) )
22472247 }
22482248
2249- fn ios_watchos_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2249+ fn apple_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
22502250 enum ArchSpec {
22512251 Device ( & ' static str ) ,
22522252 Simulator ( & ' static str ) ,
22532253 Catalyst ( & ' static str ) ,
22542254 }
22552255
22562256 enum Os {
2257+ MacOs ,
22572258 Ios ,
22582259 WatchOs ,
22592260 }
22602261 impl Display for Os {
22612262 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
22622263 match self {
2264+ Os :: MacOs => f. write_str ( "macOS" ) ,
22632265 Os :: Ios => f. write_str ( "iOS" ) ,
22642266 Os :: WatchOs => f. write_str ( "WatchOS" ) ,
22652267 }
22662268 }
22672269 }
22682270
22692271 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" ) {
22712275 Os :: WatchOs
22722276 } else {
22732277 Os :: Ios
22742278 } ;
2279+ let is_mac = match os {
2280+ Os :: MacOs => true ,
2281+ _ => false ,
2282+ } ;
22752283
2276- let arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2284+ let arch_str = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
22772285 Error :: new (
22782286 ErrorKind :: ArchitectureInvalid ,
22792287 format ! ( "Unknown architecture for {} target." , os) ,
@@ -2290,8 +2298,19 @@ impl Build {
22902298 None => false ,
22912299 } ;
22922300
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 {
22952314 "arm64e" => ArchSpec :: Catalyst ( "arm64e" ) ,
22962315 "arm64" | "aarch64" => ArchSpec :: Catalyst ( "arm64" ) ,
22972316 "x86_64" => ArchSpec :: Catalyst ( "-m64" ) ,
@@ -2303,7 +2322,7 @@ impl Build {
23032322 }
23042323 }
23052324 } else if is_sim {
2306- match arch {
2325+ match arch_str {
23072326 "arm64" | "aarch64" => ArchSpec :: Simulator ( "arm64" ) ,
23082327 "x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
23092328 _ => {
@@ -2314,7 +2333,7 @@ impl Build {
23142333 }
23152334 }
23162335 } else {
2317- match arch {
2336+ match arch_str {
23182337 "arm" | "armv7" | "thumbv7" => ArchSpec :: Device ( "armv7" ) ,
23192338 "armv7k" => ArchSpec :: Device ( "armv7k" ) ,
23202339 "armv7s" | "thumbv7s" => ArchSpec :: Device ( "armv7s" ) ,
@@ -2333,6 +2352,18 @@ impl Build {
23332352 } ;
23342353
23352354 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+ ) ,
23362367 Os :: Ios => (
23372368 "iphone" ,
23382369 "ios-" ,
@@ -2346,6 +2377,11 @@ impl Build {
23462377 } ;
23472378
23482379 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+ }
23492385 ArchSpec :: Device ( arch) => {
23502386 cmd. args . push ( "-arch" . into ( ) ) ;
23512387 cmd. args . push ( arch. into ( ) ) ;
@@ -2368,17 +2404,19 @@ impl Build {
23682404 ArchSpec :: Catalyst ( _) => "macosx" . to_owned ( ) ,
23692405 } ;
23702406
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+ } ;
23772414
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+ }
23822420
23832421 Ok ( ( ) )
23842422 }
0 commit comments