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
}
@@ -1311,6 +1311,13 @@ impl Build {
1311
1311
if self . cuda && self . files . len ( ) > 1 {
1312
1312
cmd. arg ( "--device-c" ) ;
1313
1313
}
1314
+ if compiler. family == ( ToolFamily :: Msvc { clang_cl : true } ) {
1315
+ // #513: For `clang-cl`, separate flags/options from the input file.
1316
+ // When cross-compiling macOS -> Windows, this avoids interpreting
1317
+ // common `/Users/...` paths as the `/U` flag and triggering
1318
+ // `-Wslash-u-filename` warning.
1319
+ cmd. arg ( "--" ) ;
1320
+ }
1314
1321
cmd. arg ( & obj. src ) ;
1315
1322
if cfg ! ( target_os = "macos" ) {
1316
1323
self . fix_env_for_apple_os ( & mut cmd) ?;
@@ -1522,7 +1529,7 @@ impl Build {
1522
1529
cmd. push_opt_unless_duplicate ( "-DANDROID" . into ( ) ) ;
1523
1530
}
1524
1531
1525
- if !target. contains ( "apple-ios" ) {
1532
+ if !target. contains ( "apple-ios" ) && !target . contains ( "apple-watchos" ) {
1526
1533
cmd. push_cc_arg ( "-ffunction-sections" . into ( ) ) ;
1527
1534
cmd. push_cc_arg ( "-fdata-sections" . into ( ) ) ;
1528
1535
}
@@ -1590,6 +1597,20 @@ impl Build {
1590
1597
. into ( ) ,
1591
1598
) ;
1592
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
+ }
1593
1614
} else if target. starts_with ( "riscv64gc-" ) {
1594
1615
cmd. args . push (
1595
1616
format ! ( "--target={}" , target. replace( "riscv64gc" , "riscv64" ) ) . into ( ) ,
@@ -1849,8 +1870,8 @@ impl Build {
1849
1870
}
1850
1871
}
1851
1872
1852
- if target. contains ( "apple-ios" ) {
1853
- self . ios_flags ( cmd) ?;
1873
+ if target. contains ( "apple-ios" ) || target . contains ( "apple-watchos" ) {
1874
+ self . ios_watchos_flags ( cmd) ?;
1854
1875
}
1855
1876
1856
1877
if self . static_flag . unwrap_or ( false ) {
@@ -2043,18 +2064,37 @@ impl Build {
2043
2064
Ok ( ( ) )
2044
2065
}
2045
2066
2046
- fn ios_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2067
+ fn ios_watchos_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2047
2068
enum ArchSpec {
2048
2069
Device ( & ' static str ) ,
2049
2070
Simulator ( & ' static str ) ,
2050
2071
Catalyst ( & ' static str ) ,
2051
2072
}
2052
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
+
2053
2087
let target = self . get_target ( ) ?;
2088
+ let os = if target. contains ( "-watchos" ) {
2089
+ Os :: WatchOs
2090
+ } else {
2091
+ Os :: Ios
2092
+ } ;
2093
+
2054
2094
let arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2055
2095
Error :: new (
2056
2096
ErrorKind :: ArchitectureInvalid ,
2057
- "Unknown architecture for iOS target." ,
2097
+ format ! ( "Unknown architecture for {} target." , os ) . as_str ( ) ,
2058
2098
)
2059
2099
} ) ?;
2060
2100
@@ -2083,6 +2123,7 @@ impl Build {
2083
2123
} else if is_sim {
2084
2124
match arch {
2085
2125
"arm64" | "aarch64" => ArchSpec :: Simulator ( "-arch arm64" ) ,
2126
+ "x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2086
2127
_ => {
2087
2128
return Err ( Error :: new (
2088
2129
ErrorKind :: ArchitectureInvalid ,
@@ -2093,46 +2134,59 @@ impl Build {
2093
2134
} else {
2094
2135
match arch {
2095
2136
"arm" | "armv7" | "thumbv7" => ArchSpec :: Device ( "armv7" ) ,
2137
+ "armv7k" => ArchSpec :: Device ( "armv7k" ) ,
2096
2138
"armv7s" | "thumbv7s" => ArchSpec :: Device ( "armv7s" ) ,
2097
2139
"arm64e" => ArchSpec :: Device ( "arm64e" ) ,
2098
2140
"arm64" | "aarch64" => ArchSpec :: Device ( "arm64" ) ,
2141
+ "arm64_32" => ArchSpec :: Device ( "arm64_32" ) ,
2099
2142
"i386" | "i686" => ArchSpec :: Simulator ( "-m32" ) ,
2100
2143
"x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2101
2144
_ => {
2102
2145
return Err ( Error :: new (
2103
2146
ErrorKind :: ArchitectureInvalid ,
2104
- "Unknown architecture for iOS target." ,
2147
+ format ! ( "Unknown architecture for {} target." , os ) . as_str ( ) ,
2105
2148
) ) ;
2106
2149
}
2107
2150
}
2108
2151
} ;
2109
2152
2110
- let min_version =
2111
- 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
+ } ;
2112
2165
2113
2166
let sdk = match arch {
2114
2167
ArchSpec :: Device ( arch) => {
2115
2168
cmd. args . push ( "-arch" . into ( ) ) ;
2116
2169
cmd. args . push ( arch. into ( ) ) ;
2117
2170
cmd. args
2118
- . push ( format ! ( "-miphoneos -version-min={}" , min_version) . into ( ) ) ;
2119
- "iphoneos"
2171
+ . push ( format ! ( "-m{}os -version-min={}" , sdk_prefix , min_version) . into ( ) ) ;
2172
+ format ! ( "{}os" , sdk_prefix )
2120
2173
}
2121
2174
ArchSpec :: Simulator ( arch) => {
2122
2175
cmd. args . push ( arch. into ( ) ) ;
2123
2176
cmd. args
2124
- . push ( format ! ( "-mios- simulator-version-min={}" , min_version) . into ( ) ) ;
2125
- "iphonesimulator"
2177
+ . push ( format ! ( "-m{} simulator-version-min={}" , sim_prefix , min_version) . into ( ) ) ;
2178
+ format ! ( "{}simulator" , sdk_prefix )
2126
2179
}
2127
- ArchSpec :: Catalyst ( _) => "macosx" ,
2180
+ ArchSpec :: Catalyst ( _) => "macosx" . to_owned ( ) ,
2128
2181
} ;
2129
2182
2130
- self . print ( & format ! ( "Detecting iOS SDK path for {}" , sdk) ) ;
2183
+ self . print ( & format ! ( "Detecting {} SDK path for {}" , os , sdk) ) ;
2131
2184
let sdk_path = if let Some ( sdkroot) = env:: var_os ( "SDKROOT" ) {
2132
2185
sdkroot
2133
2186
} else {
2134
- self . apple_sdk_root ( sdk) ?
2187
+ self . apple_sdk_root ( sdk. as_str ( ) ) ?
2135
2188
} ;
2189
+
2136
2190
cmd. args . push ( "-isysroot" . into ( ) ) ;
2137
2191
cmd. args . push ( sdk_path) ;
2138
2192
cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
@@ -2234,6 +2288,8 @@ impl Build {
2234
2288
}
2235
2289
} else if target. contains ( "apple-ios" ) {
2236
2290
clang. to_string ( )
2291
+ } else if target. contains ( "apple-watchos" ) {
2292
+ clang. to_string ( )
2237
2293
} else if target. contains ( "android" ) {
2238
2294
autodetect_android_compiler ( & target, & host, gnu, clang)
2239
2295
} else if target. contains ( "cloudabi" ) {
@@ -2810,7 +2866,7 @@ impl Build {
2810
2866
Err ( _) => {
2811
2867
return Err ( Error :: new (
2812
2868
ErrorKind :: IOError ,
2813
- "Unable to determine iOS SDK path." ,
2869
+ "Unable to determine Apple SDK path." ,
2814
2870
) ) ;
2815
2871
}
2816
2872
} ;
0 commit comments