@@ -1611,6 +1611,20 @@ impl Build {
16111611 . into ( ) ,
16121612 ) ;
16131613 }
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+ }
16141628 } else if target. starts_with ( "riscv64gc-" ) {
16151629 cmd. args . push (
16161630 format ! ( "--target={}" , target. replace( "riscv64gc" , "riscv64" ) ) . into ( ) ,
@@ -1870,8 +1884,11 @@ impl Build {
18701884 }
18711885 }
18721886
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+ }
18751892 }
18761893
18771894 if self . static_flag . unwrap_or ( false ) {
@@ -2064,32 +2081,44 @@ impl Build {
20642081 Ok ( ( ) )
20652082 }
20662083
2067- fn ios_watchos_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2084+ fn apple_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
20682085 enum ArchSpec {
20692086 Device ( & ' static str ) ,
20702087 Simulator ( & ' static str ) ,
20712088 Catalyst ( & ' static str ) ,
20722089 }
20732090
20742091 enum Os {
2092+ MacOs ,
20752093 Ios ,
20762094 WatchOs ,
2095+ TvOs ,
20772096 }
20782097 impl Display for Os {
20792098 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
20802099 match self {
2100+ Os :: MacOs => f. write_str ( "macOS" ) ,
20812101 Os :: Ios => f. write_str ( "iOS" ) ,
20822102 Os :: WatchOs => f. write_str ( "WatchOS" ) ,
2103+ Os :: TvOs => f. write_str ( "tvOS" ) ,
20832104 }
20842105 }
20852106 }
20862107
20872108 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" ) {
20892112 Os :: WatchOs
2113+ } else if target. contains ( "-tvos" ) {
2114+ Os :: TvOs
20902115 } else {
20912116 Os :: Ios
20922117 } ;
2118+ let is_mac = match os {
2119+ Os :: MacOs => true ,
2120+ _ => false ,
2121+ } ;
20932122
20942123 let arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
20952124 Error :: new (
@@ -2103,12 +2132,23 @@ impl Build {
21032132 None => false ,
21042133 } ;
21052134
2106- let is_sim = match target. split ( '-' ) . nth ( 3 ) {
2135+ let is_arm_sim = match target. split ( '-' ) . nth ( 3 ) {
21072136 Some ( v) => v == "sim" ,
21082137 None => false ,
21092138 } ;
21102139
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 {
21122152 match arch {
21132153 "arm64e" => ArchSpec :: Catalyst ( "arm64e" ) ,
21142154 "arm64" | "aarch64" => ArchSpec :: Catalyst ( "arm64" ) ,
@@ -2120,14 +2160,14 @@ impl Build {
21202160 ) ) ;
21212161 }
21222162 }
2123- } else if is_sim {
2163+ } else if is_arm_sim {
21242164 match arch {
21252165 "arm64" | "aarch64" => ArchSpec :: Simulator ( "-arch arm64" ) ,
21262166 "x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
21272167 _ => {
21282168 return Err ( Error :: new (
21292169 ErrorKind :: ArchitectureInvalid ,
2130- "Unknown architecture for iOS simulator target." ,
2170+ "Unknown architecture for simulator target." ,
21312171 ) ) ;
21322172 }
21332173 }
@@ -2151,6 +2191,11 @@ impl Build {
21512191 } ;
21522192
21532193 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+ ) ,
21542199 Os :: Ios => (
21552200 "iphone" ,
21562201 "ios-" ,
@@ -2161,9 +2206,20 @@ impl Build {
21612206 "watch" ,
21622207 std:: env:: var ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "2.0" . into ( ) ) ,
21632208 ) ,
2209+ Os :: TvOs => (
2210+ "tv" ,
2211+ "tv" ,
2212+ std:: env:: var ( "TVOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "9.0" . into ( ) ) ,
2213+ ) ,
21642214 } ;
21652215
21662216 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+ }
21672223 ArchSpec :: Device ( arch) => {
21682224 cmd. args . push ( "-arch" . into ( ) ) ;
21692225 cmd. args . push ( arch. into ( ) ) ;
@@ -2184,7 +2240,9 @@ impl Build {
21842240 let sdk_path = self . apple_sdk_root ( sdk. as_str ( ) ) ?;
21852241 cmd. args . push ( "-isysroot" . into ( ) ) ;
21862242 cmd. args . push ( sdk_path) ;
2187- cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2243+ if !is_mac {
2244+ cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2245+ }
21882246 /*
21892247 * TODO we probably ultimately want the -fembed-bitcode-marker flag
21902248 * but can't have it now because of an issue in LLVM:
@@ -3080,6 +3138,25 @@ impl Tool {
30803138 self . family == ToolFamily :: Clang
30813139 }
30823140
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+
30833160 /// Whether the tool is MSVC-like.
30843161 pub fn is_like_msvc ( & self ) -> bool {
30853162 match self . family {
0 commit comments