@@ -1870,8 +1870,8 @@ impl Build {
1870
1870
}
1871
1871
}
1872
1872
1873
- if target. contains ( "apple-ios" ) || target . contains ( " apple-watchos ") {
1874
- self . ios_watchos_flags ( cmd) ?;
1873
+ if target. contains ( "- apple-" ) {
1874
+ self . apple_flags ( cmd) ?;
1875
1875
}
1876
1876
1877
1877
if self . static_flag . unwrap_or ( false ) {
@@ -2064,32 +2064,40 @@ impl Build {
2064
2064
Ok ( ( ) )
2065
2065
}
2066
2066
2067
- fn ios_watchos_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2067
+ fn apple_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2068
2068
enum ArchSpec {
2069
2069
Device ( & ' static str ) ,
2070
2070
Simulator ( & ' static str ) ,
2071
2071
Catalyst ( & ' static str ) ,
2072
2072
}
2073
2073
2074
2074
enum Os {
2075
+ MacOs ,
2075
2076
Ios ,
2076
2077
WatchOs ,
2077
2078
}
2078
2079
impl Display for Os {
2079
2080
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
2080
2081
match self {
2082
+ Os :: MacOs => f. write_str ( "macOS" ) ,
2081
2083
Os :: Ios => f. write_str ( "iOS" ) ,
2082
2084
Os :: WatchOs => f. write_str ( "WatchOS" ) ,
2083
2085
}
2084
2086
}
2085
2087
}
2086
2088
2087
2089
let target = self . get_target ( ) ?;
2088
- let os = if target. contains ( "-watchos" ) {
2090
+ let os = if target. contains ( "-darwin" ) {
2091
+ Os :: MacOs
2092
+ } else if target. contains ( "-watchos" ) {
2089
2093
Os :: WatchOs
2090
2094
} else {
2091
2095
Os :: Ios
2092
2096
} ;
2097
+ let is_mac = match os {
2098
+ Os :: MacOs => true ,
2099
+ _ => false ,
2100
+ } ;
2093
2101
2094
2102
let arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2095
2103
Error :: new (
@@ -2108,7 +2116,18 @@ impl Build {
2108
2116
None => false ,
2109
2117
} ;
2110
2118
2111
- let arch = if is_catalyst {
2119
+ let arch = if is_mac {
2120
+ match arch {
2121
+ "i686" => ArchSpec :: Device ( "-m32" ) ,
2122
+ "x86_64" | "aarch64" => ArchSpec :: Device ( "-m64" ) ,
2123
+ _ => {
2124
+ return Err ( Error :: new (
2125
+ ErrorKind :: ArchitectureInvalid ,
2126
+ "Unknown architecture for macOS target." ,
2127
+ ) ) ;
2128
+ }
2129
+ }
2130
+ } else if is_catalyst {
2112
2131
match arch {
2113
2132
"arm64e" => ArchSpec :: Catalyst ( "arm64e" ) ,
2114
2133
"arm64" | "aarch64" => ArchSpec :: Catalyst ( "arm64" ) ,
@@ -2151,6 +2170,11 @@ impl Build {
2151
2170
} ;
2152
2171
2153
2172
let ( sdk_prefix, sim_prefix, min_version) = match os {
2173
+ Os :: MacOs => (
2174
+ "macosx" ,
2175
+ "" ,
2176
+ std:: env:: var ( "MACOSX_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "10.0" . into ( ) ) ,
2177
+ ) ,
2154
2178
Os :: Ios => (
2155
2179
"iphone" ,
2156
2180
"ios-" ,
@@ -2164,6 +2188,11 @@ impl Build {
2164
2188
} ;
2165
2189
2166
2190
let sdk = match arch {
2191
+ ArchSpec :: Device ( _) if is_mac => {
2192
+ cmd. args
2193
+ . push ( format ! ( "-mmacosx-version-min={}" , min_version) . into ( ) ) ;
2194
+ "macosx" . to_owned ( )
2195
+ }
2167
2196
ArchSpec :: Device ( arch) => {
2168
2197
cmd. args . push ( "-arch" . into ( ) ) ;
2169
2198
cmd. args . push ( arch. into ( ) ) ;
@@ -2180,11 +2209,13 @@ impl Build {
2180
2209
ArchSpec :: Catalyst ( _) => "macosx" . to_owned ( ) ,
2181
2210
} ;
2182
2211
2183
- self . print ( & format ! ( "Detecting {} SDK path for {}" , os, sdk) ) ;
2184
- let sdk_path = self . apple_sdk_root ( sdk. as_str ( ) ) ?;
2185
- cmd. args . push ( "-isysroot" . into ( ) ) ;
2186
- cmd. args . push ( sdk_path) ;
2187
- cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2212
+ if !is_mac {
2213
+ self . print ( & format ! ( "Detecting {} SDK path for {}" , os, sdk) ) ;
2214
+ let sdk_path = self . apple_sdk_root ( sdk. as_str ( ) ) ?;
2215
+ cmd. args . push ( "-isysroot" . into ( ) ) ;
2216
+ cmd. args . push ( sdk_path) ;
2217
+ cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2218
+ }
2188
2219
/*
2189
2220
* TODO we probably ultimately want the -fembed-bitcode-marker flag
2190
2221
* but can't have it now because of an issue in LLVM:
0 commit comments