59
59
use std:: collections:: HashMap ;
60
60
use std:: env;
61
61
use std:: ffi:: { OsStr , OsString } ;
62
- use std:: fmt:: { self , Display } ;
62
+ use std:: fmt:: { self , Display , Formatter } ;
63
63
use std:: fs;
64
64
use std:: io:: { self , BufRead , BufReader , Read , Write } ;
65
65
use std:: path:: { Component , Path , PathBuf } ;
@@ -1864,11 +1864,11 @@ impl Build {
1864
1864
}
1865
1865
1866
1866
if target. contains ( "apple-ios" ) {
1867
- self . ios_flags ( cmd) ?;
1867
+ self . ios_watchos_flags ( cmd) ?;
1868
1868
}
1869
1869
1870
1870
if target. contains ( "apple-watchos" ) {
1871
- self . watchos_flags ( cmd) ?;
1871
+ self . ios_watchos_flags ( cmd) ?;
1872
1872
}
1873
1873
1874
1874
if self . static_flag . unwrap_or ( false ) {
@@ -2061,18 +2061,37 @@ impl Build {
2061
2061
Ok ( ( ) )
2062
2062
}
2063
2063
2064
- fn ios_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2064
+ fn ios_watchos_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2065
2065
enum ArchSpec {
2066
2066
Device ( & ' static str ) ,
2067
2067
Simulator ( & ' static str ) ,
2068
2068
Catalyst ( & ' static str ) ,
2069
2069
}
2070
2070
2071
+ enum Os {
2072
+ Ios ,
2073
+ WatchOs ,
2074
+ }
2075
+ impl Display for Os {
2076
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
2077
+ match self {
2078
+ Os :: Ios => f. write_str ( "iOS" ) ,
2079
+ Os :: WatchOs => f. write_str ( "WatchOS" ) ,
2080
+ }
2081
+ }
2082
+ }
2083
+
2071
2084
let target = self . get_target ( ) ?;
2085
+ let os = if target. contains ( "-watchos" ) {
2086
+ Os :: WatchOs
2087
+ } else {
2088
+ Os :: Ios
2089
+ } ;
2090
+
2072
2091
let arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2073
2092
Error :: new (
2074
2093
ErrorKind :: ArchitectureInvalid ,
2075
- "Unknown architecture for iOS target." ,
2094
+ format ! ( "Unknown architecture for {} target." , os ) . as_str ( ) ,
2076
2095
)
2077
2096
} ) ?;
2078
2097
@@ -2101,6 +2120,7 @@ impl Build {
2101
2120
} else if is_sim {
2102
2121
match arch {
2103
2122
"arm64" | "aarch64" => ArchSpec :: Simulator ( "-arch arm64" ) ,
2123
+ "x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2104
2124
_ => {
2105
2125
return Err ( Error :: new (
2106
2126
ErrorKind :: ArchitectureInvalid ,
@@ -2111,108 +2131,46 @@ impl Build {
2111
2131
} else {
2112
2132
match arch {
2113
2133
"arm" | "armv7" | "thumbv7" => ArchSpec :: Device ( "armv7" ) ,
2134
+ "armv7k" => ArchSpec :: Device ( "armv7k" ) ,
2114
2135
"armv7s" | "thumbv7s" => ArchSpec :: Device ( "armv7s" ) ,
2115
2136
"arm64e" => ArchSpec :: Device ( "arm64e" ) ,
2116
2137
"arm64" | "aarch64" => ArchSpec :: Device ( "arm64" ) ,
2138
+ "arm64_32" => ArchSpec :: Device ( "arm64_32" ) ,
2117
2139
"i386" | "i686" => ArchSpec :: Simulator ( "-m32" ) ,
2118
2140
"x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2119
2141
_ => {
2120
2142
return Err ( Error :: new (
2121
2143
ErrorKind :: ArchitectureInvalid ,
2122
- "Unknown architecture for iOS target." ,
2144
+ format ! ( "Unknown architecture for {} target." , os ) . as_str ( ) ,
2123
2145
) ) ;
2124
2146
}
2125
2147
}
2126
2148
} ;
2127
2149
2128
- let min_version =
2129
- std:: env:: var ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "7.0" . into ( ) ) ;
2130
-
2131
- let sdk = match arch {
2132
- ArchSpec :: Device ( arch) => {
2133
- cmd. args . push ( "-arch" . into ( ) ) ;
2134
- cmd. args . push ( arch. into ( ) ) ;
2135
- cmd. args
2136
- . push ( format ! ( "-miphoneos-version-min={}" , min_version) . into ( ) ) ;
2137
- "iphoneos"
2138
- }
2139
- ArchSpec :: Simulator ( arch) => {
2140
- cmd. args . push ( arch. into ( ) ) ;
2141
- cmd. args
2142
- . push ( format ! ( "-mios-simulator-version-min={}" , min_version) . into ( ) ) ;
2143
- "iphonesimulator"
2144
- }
2145
- ArchSpec :: Catalyst ( _) => "macosx" ,
2146
- } ;
2147
-
2148
- self . print ( & format ! ( "Detecting iOS SDK path for {}" , sdk) ) ;
2149
- let sdk_path = self . apple_sdk_root ( sdk) ?;
2150
- cmd. args . push ( "-isysroot" . into ( ) ) ;
2151
- cmd. args . push ( sdk_path) ;
2152
- cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2153
- /*
2154
- * TODO we probably ultimately want the -fembed-bitcode-marker flag
2155
- * but can't have it now because of an issue in LLVM:
2156
- * https://github.com/alexcrichton/cc-rs/issues/301
2157
- * https://github.com/rust-lang/rust/pull/48896#comment-372192660
2158
- */
2159
- /*
2160
- if self.get_opt_level()? == "0" {
2161
- cmd.args.push("-fembed-bitcode-marker".into());
2162
- }
2163
- */
2164
-
2165
- Ok ( ( ) )
2166
- }
2167
-
2168
- fn watchos_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2169
- enum ArchSpec {
2170
- Device ( & ' static str ) ,
2171
- Simulator ( & ' static str ) ,
2172
- }
2173
-
2174
- let target = self . get_target ( ) ?;
2175
- let arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2176
- Error :: new (
2177
- ErrorKind :: ArchitectureInvalid ,
2178
- "Unknown architecture for watchOS target." ,
2179
- )
2180
- } ) ?;
2181
-
2182
- let arch = match arch {
2183
- "armv7k" => ArchSpec :: Device ( "armv7k" ) ,
2184
- "arm64_32" => ArchSpec :: Device ( "arm64_32" ) ,
2185
- "i386" | "i686" => ArchSpec :: Simulator ( "-m32" ) ,
2186
- "x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2187
- _ => {
2188
- return Err ( Error :: new (
2189
- ErrorKind :: ArchitectureInvalid ,
2190
- "Unknown architecture for watchOS target." ,
2191
- ) ) ;
2192
- }
2150
+ let ( sdk_prefix, sim_prefix, min_version) = match os {
2151
+ Os :: Ios => ( "iphone" , "ios-" , std:: env:: var ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "7.0" . into ( ) ) ) ,
2152
+ Os :: WatchOs => ( "watch" , "watch" , std:: env:: var ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "2.0" . into ( ) ) ) ,
2193
2153
} ;
2194
2154
2195
- let min_version =
2196
- std:: env:: var ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "2.0" . into ( ) ) ;
2197
-
2198
2155
let sdk = match arch {
2199
2156
ArchSpec :: Device ( arch) => {
2200
2157
cmd. args . push ( "-arch" . into ( ) ) ;
2201
2158
cmd. args . push ( arch. into ( ) ) ;
2202
2159
cmd. args
2203
- . push ( format ! ( "-mwatchos -version-min={}" , min_version) . into ( ) ) ;
2204
- "watchos"
2160
+ . push ( format ! ( "-m{}os -version-min={}" , sdk_prefix , min_version) . into ( ) ) ;
2161
+ format ! ( "{}os" , sdk_prefix )
2205
2162
}
2206
2163
ArchSpec :: Simulator ( arch) => {
2207
2164
cmd. args . push ( arch. into ( ) ) ;
2208
2165
cmd. args
2209
- . push ( format ! ( "-mwatchsimulator -version-min={}" , min_version) . into ( ) ) ;
2210
- "watchsimulator"
2166
+ . push ( format ! ( "-m{}simulator -version-min={}" , sim_prefix , min_version) . into ( ) ) ;
2167
+ format ! ( "{}simulator" , sdk_prefix )
2211
2168
}
2169
+ ArchSpec :: Catalyst ( _) => "macosx" . to_owned ( ) ,
2212
2170
} ;
2213
2171
2214
- self . print ( & format ! ( "Detecting watchOS SDK path for {}" , sdk) ) ;
2215
- let sdk_path = self . apple_sdk_root ( sdk) ?;
2172
+ self . print ( & format ! ( "Detecting {} SDK path for {}" , os , sdk) ) ;
2173
+ let sdk_path = self . apple_sdk_root ( sdk. as_str ( ) ) ?;
2216
2174
cmd. args . push ( "-isysroot" . into ( ) ) ;
2217
2175
cmd. args . push ( sdk_path) ;
2218
2176
cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
0 commit comments