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