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 } ;
@@ -168,7 +168,7 @@ impl From<io::Error> for Error {
168
168
}
169
169
170
170
impl Display for Error {
171
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
171
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
172
172
write ! ( f, "{:?}: {}" , self . kind, self . message)
173
173
}
174
174
}
@@ -1529,7 +1529,7 @@ impl Build {
1529
1529
cmd. push_opt_unless_duplicate ( "-DANDROID" . into ( ) ) ;
1530
1530
}
1531
1531
1532
- if !target. contains ( "apple-ios" ) {
1532
+ if !target. contains ( "apple-ios" ) && !target . contains ( "apple-watchos" ) {
1533
1533
cmd. push_cc_arg ( "-ffunction-sections" . into ( ) ) ;
1534
1534
cmd. push_cc_arg ( "-fdata-sections" . into ( ) ) ;
1535
1535
}
@@ -1597,6 +1597,20 @@ impl Build {
1597
1597
. into ( ) ,
1598
1598
) ;
1599
1599
}
1600
+ } else if target. contains ( "watchos-sim" ) {
1601
+ if let Some ( arch) =
1602
+ map_darwin_target_from_rust_to_compiler_architecture ( target)
1603
+ {
1604
+ let deployment_target = env:: var ( "WATCHOS_DEPLOYMENT_TARGET" )
1605
+ . unwrap_or_else ( |_| "5.0" . into ( ) ) ;
1606
+ cmd. args . push (
1607
+ format ! (
1608
+ "--target={}-apple-watchos{}-simulator" ,
1609
+ arch, deployment_target
1610
+ )
1611
+ . into ( ) ,
1612
+ ) ;
1613
+ }
1600
1614
} else if target. starts_with ( "riscv64gc-" ) {
1601
1615
cmd. args . push (
1602
1616
format ! ( "--target={}" , target. replace( "riscv64gc" , "riscv64" ) ) . into ( ) ,
@@ -1856,8 +1870,8 @@ impl Build {
1856
1870
}
1857
1871
}
1858
1872
1859
- if target. contains ( "apple-ios" ) {
1860
- self . ios_flags ( cmd) ?;
1873
+ if target. contains ( "apple-ios" ) || target . contains ( "apple-watchos" ) {
1874
+ self . ios_watchos_flags ( cmd) ?;
1861
1875
}
1862
1876
1863
1877
if self . static_flag . unwrap_or ( false ) {
@@ -2050,18 +2064,37 @@ impl Build {
2050
2064
Ok ( ( ) )
2051
2065
}
2052
2066
2053
- fn ios_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2067
+ fn ios_watchos_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2054
2068
enum ArchSpec {
2055
2069
Device ( & ' static str ) ,
2056
2070
Simulator ( & ' static str ) ,
2057
2071
Catalyst ( & ' static str ) ,
2058
2072
}
2059
2073
2074
+ enum Os {
2075
+ Ios ,
2076
+ WatchOs ,
2077
+ }
2078
+ impl Display for Os {
2079
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
2080
+ match self {
2081
+ Os :: Ios => f. write_str ( "iOS" ) ,
2082
+ Os :: WatchOs => f. write_str ( "WatchOS" ) ,
2083
+ }
2084
+ }
2085
+ }
2086
+
2060
2087
let target = self . get_target ( ) ?;
2088
+ let os = if target. contains ( "-watchos" ) {
2089
+ Os :: WatchOs
2090
+ } else {
2091
+ Os :: Ios
2092
+ } ;
2093
+
2061
2094
let arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2062
2095
Error :: new (
2063
2096
ErrorKind :: ArchitectureInvalid ,
2064
- "Unknown architecture for iOS target." ,
2097
+ format ! ( "Unknown architecture for {} target." , os ) . as_str ( ) ,
2065
2098
)
2066
2099
} ) ?;
2067
2100
@@ -2090,6 +2123,7 @@ impl Build {
2090
2123
} else if is_sim {
2091
2124
match arch {
2092
2125
"arm64" | "aarch64" => ArchSpec :: Simulator ( "-arch arm64" ) ,
2126
+ "x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2093
2127
_ => {
2094
2128
return Err ( Error :: new (
2095
2129
ErrorKind :: ArchitectureInvalid ,
@@ -2100,42 +2134,54 @@ impl Build {
2100
2134
} else {
2101
2135
match arch {
2102
2136
"arm" | "armv7" | "thumbv7" => ArchSpec :: Device ( "armv7" ) ,
2137
+ "armv7k" => ArchSpec :: Device ( "armv7k" ) ,
2103
2138
"armv7s" | "thumbv7s" => ArchSpec :: Device ( "armv7s" ) ,
2104
2139
"arm64e" => ArchSpec :: Device ( "arm64e" ) ,
2105
2140
"arm64" | "aarch64" => ArchSpec :: Device ( "arm64" ) ,
2141
+ "arm64_32" => ArchSpec :: Device ( "arm64_32" ) ,
2106
2142
"i386" | "i686" => ArchSpec :: Simulator ( "-m32" ) ,
2107
2143
"x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2108
2144
_ => {
2109
2145
return Err ( Error :: new (
2110
2146
ErrorKind :: ArchitectureInvalid ,
2111
- "Unknown architecture for iOS target." ,
2147
+ format ! ( "Unknown architecture for {} target." , os ) . as_str ( ) ,
2112
2148
) ) ;
2113
2149
}
2114
2150
}
2115
2151
} ;
2116
2152
2117
- let min_version =
2118
- std:: env:: var ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "7.0" . into ( ) ) ;
2153
+ let ( sdk_prefix, sim_prefix, min_version) = match os {
2154
+ Os :: Ios => (
2155
+ "iphone" ,
2156
+ "ios-" ,
2157
+ std:: env:: var ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "7.0" . into ( ) ) ,
2158
+ ) ,
2159
+ Os :: WatchOs => (
2160
+ "watch" ,
2161
+ "watch" ,
2162
+ std:: env:: var ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "2.0" . into ( ) ) ,
2163
+ ) ,
2164
+ } ;
2119
2165
2120
2166
let sdk = match arch {
2121
2167
ArchSpec :: Device ( arch) => {
2122
2168
cmd. args . push ( "-arch" . into ( ) ) ;
2123
2169
cmd. args . push ( arch. into ( ) ) ;
2124
2170
cmd. args
2125
- . push ( format ! ( "-miphoneos -version-min={}" , min_version) . into ( ) ) ;
2126
- "iphoneos"
2171
+ . push ( format ! ( "-m{}os -version-min={}" , sdk_prefix , min_version) . into ( ) ) ;
2172
+ format ! ( "{}os" , sdk_prefix )
2127
2173
}
2128
2174
ArchSpec :: Simulator ( arch) => {
2129
2175
cmd. args . push ( arch. into ( ) ) ;
2130
2176
cmd. args
2131
- . push ( format ! ( "-mios- simulator-version-min={}" , min_version) . into ( ) ) ;
2132
- "iphonesimulator"
2177
+ . push ( format ! ( "-m{} simulator-version-min={}" , sim_prefix , min_version) . into ( ) ) ;
2178
+ format ! ( "{}simulator" , sdk_prefix )
2133
2179
}
2134
- ArchSpec :: Catalyst ( _) => "macosx" ,
2180
+ ArchSpec :: Catalyst ( _) => "macosx" . to_owned ( ) ,
2135
2181
} ;
2136
2182
2137
- self . print ( & format ! ( "Detecting iOS SDK path for {}" , sdk) ) ;
2138
- let sdk_path = self . apple_sdk_root ( sdk) ?;
2183
+ self . print ( & format ! ( "Detecting {} SDK path for {}" , os , sdk) ) ;
2184
+ let sdk_path = self . apple_sdk_root ( sdk. as_str ( ) ) ?;
2139
2185
cmd. args . push ( "-isysroot" . into ( ) ) ;
2140
2186
cmd. args . push ( sdk_path) ;
2141
2187
cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
@@ -2237,6 +2283,8 @@ impl Build {
2237
2283
}
2238
2284
} else if target. contains ( "apple-ios" ) {
2239
2285
clang. to_string ( )
2286
+ } else if target. contains ( "apple-watchos" ) {
2287
+ clang. to_string ( )
2240
2288
} else if target. contains ( "android" ) {
2241
2289
autodetect_android_compiler ( & target, & host, gnu, clang)
2242
2290
} else if target. contains ( "cloudabi" ) {
@@ -2813,7 +2861,7 @@ impl Build {
2813
2861
Err ( _) => {
2814
2862
return Err ( Error :: new (
2815
2863
ErrorKind :: IOError ,
2816
- "Unable to determine iOS SDK path." ,
2864
+ "Unable to determine Apple SDK path." ,
2817
2865
) ) ;
2818
2866
}
2819
2867
} ;
0 commit comments