@@ -1416,7 +1416,7 @@ impl Build {
14161416 cmd. push_opt_unless_duplicate ( "-DANDROID" . into ( ) ) ;
14171417 }
14181418
1419- if !target. contains ( "apple-ios" ) {
1419+ if !target. contains ( "apple-ios" ) && !target . contains ( "apple-watchos" ) {
14201420 cmd. push_cc_arg ( "-ffunction-sections" . into ( ) ) ;
14211421 cmd. push_cc_arg ( "-fdata-sections" . into ( ) ) ;
14221422 }
@@ -1484,6 +1484,19 @@ impl Build {
14841484 . into ( ) ,
14851485 ) ;
14861486 }
1487+ } else if target. contains ( "watchos-sim" ) {
1488+ if let Some ( arch) =
1489+ map_darwin_target_from_rust_to_compiler_architecture ( target)
1490+ {
1491+ let deployment_target = env:: var ( "WATCHOS_DEPLOYMENT_TARGET" )
1492+ . unwrap_or_else ( |_| "5.0" . into ( ) ) ;
1493+ cmd. args . push (
1494+ format ! (
1495+ "--target={}-apple-watchos{}-simulator" ,
1496+ arch, deployment_target
1497+ ) . into ( ) ,
1498+ ) ;
1499+ }
14871500 } else if target. starts_with ( "riscv64gc-" ) {
14881501 cmd. args . push (
14891502 format ! ( "--target={}" , target. replace( "riscv64gc" , "riscv64" ) ) . into ( ) ,
@@ -1720,6 +1733,10 @@ impl Build {
17201733 self . ios_flags ( cmd) ?;
17211734 }
17221735
1736+ if target. contains ( "apple-watchos" ) {
1737+ self . watchos_flags ( cmd) ?;
1738+ }
1739+
17231740 if self . static_flag . unwrap_or ( false ) {
17241741 cmd. args . push ( "-static" . into ( ) ) ;
17251742 }
@@ -1984,6 +2001,74 @@ impl Build {
19842001 Ok ( ( ) )
19852002 }
19862003
2004+ fn watchos_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
2005+ enum ArchSpec {
2006+ Device ( & ' static str ) ,
2007+ Simulator ( & ' static str ) ,
2008+ }
2009+
2010+ let target = self . get_target ( ) ?;
2011+ let arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || {
2012+ Error :: new (
2013+ ErrorKind :: ArchitectureInvalid ,
2014+ "Unknown architecture for watchOS target." ,
2015+ )
2016+ } ) ?;
2017+
2018+ let arch = match arch {
2019+ "armv7k" => ArchSpec :: Device ( "armv7k" ) ,
2020+ "arm64_32" => ArchSpec :: Device ( "arm64_32" ) ,
2021+ "i386" | "i686" => ArchSpec :: Simulator ( "-m32" ) ,
2022+ "x86_64" => ArchSpec :: Simulator ( "-m64" ) ,
2023+ _ => {
2024+ return Err ( Error :: new (
2025+ ErrorKind :: ArchitectureInvalid ,
2026+ "Unknown architecture for watchOS target." ,
2027+ ) ) ;
2028+ }
2029+
2030+ } ;
2031+
2032+ let min_version =
2033+ std:: env:: var ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "2.0" . into ( ) ) ;
2034+
2035+
2036+ let sdk = match arch {
2037+ ArchSpec :: Device ( arch) => {
2038+ cmd. args . push ( "-arch" . into ( ) ) ;
2039+ cmd. args . push ( arch. into ( ) ) ;
2040+ cmd. args
2041+ . push ( format ! ( "-mwatchos-version-min={}" , min_version) . into ( ) ) ;
2042+ "watchos"
2043+ }
2044+ ArchSpec :: Simulator ( arch) => {
2045+ cmd. args . push ( arch. into ( ) ) ;
2046+ cmd. args
2047+ . push ( format ! ( "-mwatch-simulator-version-min={}" , min_version) . into ( ) ) ;
2048+ "watchsimulator"
2049+ }
2050+ } ;
2051+
2052+ self . print ( & format ! ( "Detecting watchOS SDK path for {}" , sdk) ) ;
2053+ let sdk_path = self . apple_sdk_root ( sdk) ?;
2054+ cmd. args . push ( "-isysroot" . into ( ) ) ;
2055+ cmd. args . push ( sdk_path) ;
2056+ cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2057+ /*
2058+ * TODO we probably ultimately want the -fembed-bitcode-marker flag
2059+ * but can't have it now because of an issue in LLVM:
2060+ * https://github.com/alexcrichton/cc-rs/issues/301
2061+ * https://github.com/rust-lang/rust/pull/48896#comment-372192660
2062+ */
2063+ /*
2064+ if self.get_opt_level()? == "0" {
2065+ cmd.args.push("-fembed-bitcode-marker".into());
2066+ }
2067+ */
2068+
2069+ Ok ( ( ) )
2070+ }
2071+
19872072 fn cmd < P : AsRef < OsStr > > ( & self , prog : P ) -> Command {
19882073 let mut cmd = Command :: new ( prog) ;
19892074 for & ( ref a, ref b) in self . env . iter ( ) {
@@ -2067,6 +2152,8 @@ impl Build {
20672152 }
20682153 } else if target. contains ( "apple-ios" ) {
20692154 clang. to_string ( )
2155+ } else if target. contains ( "apple-watchos" ) {
2156+ clang. to_string ( )
20702157 } else if target. contains ( "android" ) {
20712158 autodetect_android_compiler ( & target, & host, gnu, clang)
20722159 } else if target. contains ( "cloudabi" ) {
@@ -2630,7 +2717,7 @@ impl Build {
26302717 Err ( _) => {
26312718 return Err ( Error :: new (
26322719 ErrorKind :: IOError ,
2633- "Unable to determine iOS SDK path." ,
2720+ "Unable to determine Apple SDK path." ,
26342721 ) ) ;
26352722 }
26362723 } ;
0 commit comments