@@ -1887,8 +1887,8 @@ impl Build {
1887
1887
}
1888
1888
}
1889
1889
1890
- if target. contains ( "apple-ios" ) || target . contains ( " apple-watchos ") {
1891
- self . ios_watchos_flags ( cmd) ?;
1890
+ if target. contains ( "- apple-" ) {
1891
+ self . apple_flags ( cmd) ?;
1892
1892
}
1893
1893
1894
1894
if self . static_flag . unwrap_or ( false ) {
@@ -2081,34 +2081,42 @@ impl Build {
2081
2081
Ok ( ( ) )
2082
2082
}
2083
2083
2084
- fn ios_watchos_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2084
+ fn apple_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2085
2085
enum ArchSpec {
2086
2086
Device ( & ' static str ) ,
2087
2087
Simulator ( & ' static str ) ,
2088
2088
Catalyst ( & ' static str ) ,
2089
2089
}
2090
2090
2091
2091
enum Os {
2092
+ MacOs ,
2092
2093
Ios ,
2093
2094
WatchOs ,
2094
2095
}
2095
2096
impl Display for Os {
2096
2097
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
2097
2098
match self {
2099
+ Os :: MacOs => f. write_str ( "macOS" ) ,
2098
2100
Os :: Ios => f. write_str ( "iOS" ) ,
2099
2101
Os :: WatchOs => f. write_str ( "WatchOS" ) ,
2100
2102
}
2101
2103
}
2102
2104
}
2103
2105
2104
2106
let target = self . get_target ( ) ?;
2105
- let os = if target. contains ( "-watchos" ) {
2107
+ let os = if target. contains ( "-darwin" ) {
2108
+ Os :: MacOs
2109
+ } else if target. contains ( "-watchos" ) {
2106
2110
Os :: WatchOs
2107
2111
} else {
2108
2112
Os :: Ios
2109
2113
} ;
2114
+ let is_mac = match os {
2115
+ Os :: MacOs => true ,
2116
+ _ => false ,
2117
+ } ;
2110
2118
2111
- let arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2119
+ let arch_str = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2112
2120
Error :: new (
2113
2121
ErrorKind :: ArchitectureInvalid ,
2114
2122
format ! ( "Unknown architecture for {} target." , os) . as_str ( ) ,
@@ -2125,8 +2133,19 @@ impl Build {
2125
2133
None => false ,
2126
2134
} ;
2127
2135
2128
- let arch = if is_catalyst {
2129
- match arch {
2136
+ let arch = if is_mac {
2137
+ match arch_str {
2138
+ "i686" => ArchSpec :: Device ( "-m32" ) ,
2139
+ "x86_64" | "aarch64" => ArchSpec :: Device ( "-m64" ) ,
2140
+ _ => {
2141
+ return Err ( Error :: new (
2142
+ ErrorKind :: ArchitectureInvalid ,
2143
+ "Unknown architecture for macOS target." ,
2144
+ ) ) ;
2145
+ }
2146
+ }
2147
+ } else if is_catalyst {
2148
+ match arch_str {
2130
2149
"arm64e" => ArchSpec :: Catalyst ( "arm64e" ) ,
2131
2150
"arm64" | "aarch64" => ArchSpec :: Catalyst ( "arm64" ) ,
2132
2151
"x86_64" => ArchSpec :: Catalyst ( "-m64" ) ,
@@ -2138,7 +2157,7 @@ impl Build {
2138
2157
}
2139
2158
}
2140
2159
} else if is_sim {
2141
- match arch {
2160
+ match arch_str {
2142
2161
"arm64" | "aarch64" => ArchSpec :: Simulator ( "-arch arm64" ) ,
2143
2162
"x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2144
2163
_ => {
@@ -2149,7 +2168,7 @@ impl Build {
2149
2168
}
2150
2169
}
2151
2170
} else {
2152
- match arch {
2171
+ match arch_str {
2153
2172
"arm" | "armv7" | "thumbv7" => ArchSpec :: Device ( "armv7" ) ,
2154
2173
"armv7k" => ArchSpec :: Device ( "armv7k" ) ,
2155
2174
"armv7s" | "thumbv7s" => ArchSpec :: Device ( "armv7s" ) ,
@@ -2168,6 +2187,18 @@ impl Build {
2168
2187
} ;
2169
2188
2170
2189
let ( sdk_prefix, sim_prefix, min_version) = match os {
2190
+ Os :: MacOs => (
2191
+ "macosx" ,
2192
+ "" ,
2193
+ std:: env:: var ( "MACOSX_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| {
2194
+ ( if arch_str == "aarch64" {
2195
+ "11.0"
2196
+ } else {
2197
+ "10.7"
2198
+ } )
2199
+ . into ( )
2200
+ } ) ,
2201
+ ) ,
2171
2202
Os :: Ios => (
2172
2203
"iphone" ,
2173
2204
"ios-" ,
@@ -2181,6 +2212,11 @@ impl Build {
2181
2212
} ;
2182
2213
2183
2214
let sdk = match arch {
2215
+ ArchSpec :: Device ( _) if is_mac => {
2216
+ cmd. args
2217
+ . push ( format ! ( "-mmacosx-version-min={}" , min_version) . into ( ) ) ;
2218
+ "macosx" . to_owned ( )
2219
+ }
2184
2220
ArchSpec :: Device ( arch) => {
2185
2221
cmd. args . push ( "-arch" . into ( ) ) ;
2186
2222
cmd. args . push ( arch. into ( ) ) ;
@@ -2197,16 +2233,17 @@ impl Build {
2197
2233
ArchSpec :: Catalyst ( _) => "macosx" . to_owned ( ) ,
2198
2234
} ;
2199
2235
2200
- self . print ( & format ! ( "Detecting {} SDK path for {}" , os, sdk) ) ;
2201
- let sdk_path = if let Some ( sdkroot) = env:: var_os ( "SDKROOT" ) {
2202
- sdkroot
2203
- } else {
2204
- self . apple_sdk_root ( sdk. as_str ( ) ) ?
2205
- } ;
2206
-
2207
- cmd. args . push ( "-isysroot" . into ( ) ) ;
2208
- cmd. args . push ( sdk_path) ;
2209
- cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2236
+ if !is_mac {
2237
+ self . print ( & format ! ( "Detecting {} SDK path for {}" , os, sdk) ) ;
2238
+ let sdk_path = if let Some ( sdkroot) = env:: var_os ( "SDKROOT" ) {
2239
+ sdkroot
2240
+ } else {
2241
+ self . apple_sdk_root ( sdk. as_str ( ) ) ?
2242
+ } ;
2243
+ cmd. args . push ( "-isysroot" . into ( ) ) ;
2244
+ cmd. args . push ( sdk_path) ;
2245
+ cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2246
+ }
2210
2247
/*
2211
2248
* TODO we probably ultimately want the -fembed-bitcode-marker flag
2212
2249
* but can't have it now because of an issue in LLVM:
0 commit comments