@@ -1611,6 +1611,20 @@ impl Build {
1611
1611
. into ( ) ,
1612
1612
) ;
1613
1613
}
1614
+ } else if target. contains ( "tvos-sim" ) {
1615
+ if let Some ( arch) =
1616
+ map_darwin_target_from_rust_to_compiler_architecture ( target)
1617
+ {
1618
+ let deployment_target =
1619
+ env:: var ( "TVOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "9.0" . into ( ) ) ;
1620
+ cmd. args . push (
1621
+ format ! (
1622
+ "--target={}-apple-tvos{}-simulator" ,
1623
+ arch, deployment_target
1624
+ )
1625
+ . into ( ) ,
1626
+ ) ;
1627
+ }
1614
1628
} else if target. starts_with ( "riscv64gc-" ) {
1615
1629
cmd. args . push (
1616
1630
format ! ( "--target={}" , target. replace( "riscv64gc" , "riscv64" ) ) . into ( ) ,
@@ -1870,8 +1884,8 @@ impl Build {
1870
1884
}
1871
1885
}
1872
1886
1873
- if target. contains ( "apple-ios" ) || target . contains ( " apple-watchos ") {
1874
- self . ios_watchos_flags ( cmd) ?;
1887
+ if target. contains ( "- apple-" ) {
1888
+ self . apple_flags ( cmd) ?;
1875
1889
}
1876
1890
1877
1891
if self . static_flag . unwrap_or ( false ) {
@@ -2064,32 +2078,44 @@ impl Build {
2064
2078
Ok ( ( ) )
2065
2079
}
2066
2080
2067
- fn ios_watchos_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2081
+ fn apple_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2068
2082
enum ArchSpec {
2069
2083
Device ( & ' static str ) ,
2070
2084
Simulator ( & ' static str ) ,
2071
2085
Catalyst ( & ' static str ) ,
2072
2086
}
2073
2087
2074
2088
enum Os {
2089
+ MacOs ,
2075
2090
Ios ,
2076
2091
WatchOs ,
2092
+ TvOs ,
2077
2093
}
2078
2094
impl Display for Os {
2079
2095
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
2080
2096
match self {
2097
+ Os :: MacOs => f. write_str ( "macOS" ) ,
2081
2098
Os :: Ios => f. write_str ( "iOS" ) ,
2082
2099
Os :: WatchOs => f. write_str ( "WatchOS" ) ,
2100
+ Os :: TvOs => f. write_str ( "tvOS" ) ,
2083
2101
}
2084
2102
}
2085
2103
}
2086
2104
2087
2105
let target = self . get_target ( ) ?;
2088
- let os = if target. contains ( "-watchos" ) {
2106
+ let os = if target. contains ( "-darwin" ) {
2107
+ Os :: MacOs
2108
+ } else if target. contains ( "-watchos" ) {
2089
2109
Os :: WatchOs
2110
+ } else if target. contains ( "-tvos" ) {
2111
+ Os :: TvOs
2090
2112
} else {
2091
2113
Os :: Ios
2092
2114
} ;
2115
+ let is_mac = match os {
2116
+ Os :: MacOs => true ,
2117
+ _ => false ,
2118
+ } ;
2093
2119
2094
2120
let arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2095
2121
Error :: new (
@@ -2103,12 +2129,23 @@ impl Build {
2103
2129
None => false ,
2104
2130
} ;
2105
2131
2106
- let is_sim = match target. split ( '-' ) . nth ( 3 ) {
2132
+ let is_arm_sim = match target. split ( '-' ) . nth ( 3 ) {
2107
2133
Some ( v) => v == "sim" ,
2108
2134
None => false ,
2109
2135
} ;
2110
2136
2111
- let arch = if is_catalyst {
2137
+ let arch = if is_mac {
2138
+ match arch {
2139
+ "i686" => ArchSpec :: Device ( "-m32" ) ,
2140
+ "x86_64" | "aarch64" => ArchSpec :: Device ( "-m64" ) ,
2141
+ _ => {
2142
+ return Err ( Error :: new (
2143
+ ErrorKind :: ArchitectureInvalid ,
2144
+ "Unknown architecture for macOS target." ,
2145
+ ) ) ;
2146
+ }
2147
+ }
2148
+ } else if is_catalyst {
2112
2149
match arch {
2113
2150
"arm64e" => ArchSpec :: Catalyst ( "arm64e" ) ,
2114
2151
"arm64" | "aarch64" => ArchSpec :: Catalyst ( "arm64" ) ,
@@ -2120,14 +2157,14 @@ impl Build {
2120
2157
) ) ;
2121
2158
}
2122
2159
}
2123
- } else if is_sim {
2160
+ } else if is_arm_sim {
2124
2161
match arch {
2125
2162
"arm64" | "aarch64" => ArchSpec :: Simulator ( "-arch arm64" ) ,
2126
2163
"x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2127
2164
_ => {
2128
2165
return Err ( Error :: new (
2129
2166
ErrorKind :: ArchitectureInvalid ,
2130
- "Unknown architecture for iOS simulator target." ,
2167
+ "Unknown architecture for simulator target." ,
2131
2168
) ) ;
2132
2169
}
2133
2170
}
@@ -2151,6 +2188,11 @@ impl Build {
2151
2188
} ;
2152
2189
2153
2190
let ( sdk_prefix, sim_prefix, min_version) = match os {
2191
+ Os :: MacOs => (
2192
+ "macosx" ,
2193
+ "" ,
2194
+ std:: env:: var ( "MACOSX_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "10.0" . into ( ) ) ,
2195
+ ) ,
2154
2196
Os :: Ios => (
2155
2197
"iphone" ,
2156
2198
"ios-" ,
@@ -2161,9 +2203,20 @@ impl Build {
2161
2203
"watch" ,
2162
2204
std:: env:: var ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "2.0" . into ( ) ) ,
2163
2205
) ,
2206
+ Os :: TvOs => (
2207
+ "tv" ,
2208
+ "tv" ,
2209
+ std:: env:: var ( "TVOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "9.0" . into ( ) ) ,
2210
+ ) ,
2164
2211
} ;
2165
2212
2166
2213
let sdk = match arch {
2214
+ ArchSpec :: Device ( arch) if is_mac => {
2215
+ cmd. args . push ( arch. into ( ) ) ;
2216
+ cmd. args
2217
+ . push ( format ! ( "-mmacosx-version-min={}" , min_version) . into ( ) ) ;
2218
+ "macosx" . to_owned ( )
2219
+ }
2167
2220
ArchSpec :: Device ( arch) => {
2168
2221
cmd. args . push ( "-arch" . into ( ) ) ;
2169
2222
cmd. args . push ( arch. into ( ) ) ;
@@ -2180,11 +2233,17 @@ impl Build {
2180
2233
ArchSpec :: Catalyst ( _) => "macosx" . to_owned ( ) ,
2181
2234
} ;
2182
2235
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 ( ) ) ;
2236
+ // AppleClang sometimes needs sysroot even for darwin
2237
+ if cmd. check_apple_clang ( ) || !target. ends_with ( "-darwin" ) {
2238
+ self . print ( & format ! ( "Detecting {} SDK path for {}" , os, sdk) ) ;
2239
+ let sdk_path = self . apple_sdk_root ( sdk. as_str ( ) ) ?;
2240
+ cmd. args . push ( "-isysroot" . into ( ) ) ;
2241
+ cmd. args . push ( sdk_path) ;
2242
+ }
2243
+
2244
+ if !is_mac {
2245
+ cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2246
+ }
2188
2247
/*
2189
2248
* TODO we probably ultimately want the -fembed-bitcode-marker flag
2190
2249
* but can't have it now because of an issue in LLVM:
@@ -3080,6 +3139,25 @@ impl Tool {
3080
3139
self . family == ToolFamily :: Clang
3081
3140
}
3082
3141
3142
+ /// Whether the tool is AppleClang.
3143
+ #[ cfg( target_os = "macos" ) ]
3144
+ fn check_apple_clang ( & self ) -> bool {
3145
+ if self . family != ToolFamily :: Clang {
3146
+ return false ;
3147
+ }
3148
+ let output = std:: process:: Command :: new ( & self . path )
3149
+ . arg ( "--version" )
3150
+ . output ( ) ;
3151
+ match output {
3152
+ Ok ( output) => String :: from_utf8_lossy ( & output. stdout ) . contains ( "Apple clang" ) ,
3153
+ Err ( _) => false ,
3154
+ }
3155
+ }
3156
+ #[ cfg( not( target_os = "macos" ) ) ]
3157
+ fn check_apple_clang ( & self ) -> bool {
3158
+ false
3159
+ }
3160
+
3083
3161
/// Whether the tool is MSVC-like.
3084
3162
pub fn is_like_msvc ( & self ) -> bool {
3085
3163
match self . family {
0 commit comments