@@ -1416,7 +1416,7 @@ impl Build {
1416
1416
cmd. push_opt_unless_duplicate ( "-DANDROID" . into ( ) ) ;
1417
1417
}
1418
1418
1419
- if !target. contains ( "apple-ios" ) {
1419
+ if !target. contains ( "apple-ios" ) && !target . contains ( "apple-watchos" ) {
1420
1420
cmd. push_cc_arg ( "-ffunction-sections" . into ( ) ) ;
1421
1421
cmd. push_cc_arg ( "-fdata-sections" . into ( ) ) ;
1422
1422
}
@@ -1484,6 +1484,19 @@ impl Build {
1484
1484
. into ( ) ,
1485
1485
) ;
1486
1486
}
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
+ }
1487
1500
} else if target. starts_with ( "riscv64gc-" ) {
1488
1501
cmd. args . push (
1489
1502
format ! ( "--target={}" , target. replace( "riscv64gc" , "riscv64" ) ) . into ( ) ,
@@ -1720,6 +1733,10 @@ impl Build {
1720
1733
self . ios_flags ( cmd) ?;
1721
1734
}
1722
1735
1736
+ if target. contains ( "apple-watchos" ) {
1737
+ self . watchos_flags ( cmd) ?;
1738
+ }
1739
+
1723
1740
if self . static_flag . unwrap_or ( false ) {
1724
1741
cmd. args . push ( "-static" . into ( ) ) ;
1725
1742
}
@@ -1984,6 +2001,74 @@ impl Build {
1984
2001
Ok ( ( ) )
1985
2002
}
1986
2003
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
+
1987
2072
fn cmd < P : AsRef < OsStr > > ( & self , prog : P ) -> Command {
1988
2073
let mut cmd = Command :: new ( prog) ;
1989
2074
for & ( ref a, ref b) in self . env . iter ( ) {
@@ -2067,6 +2152,8 @@ impl Build {
2067
2152
}
2068
2153
} else if target. contains ( "apple-ios" ) {
2069
2154
clang. to_string ( )
2155
+ } else if target. contains ( "apple-watchos" ) {
2156
+ clang. to_string ( )
2070
2157
} else if target. contains ( "android" ) {
2071
2158
autodetect_android_compiler ( & target, & host, gnu, clang)
2072
2159
} else if target. contains ( "cloudabi" ) {
@@ -2630,7 +2717,7 @@ impl Build {
2630
2717
Err ( _) => {
2631
2718
return Err ( Error :: new (
2632
2719
ErrorKind :: IOError ,
2633
- "Unable to determine iOS SDK path." ,
2720
+ "Unable to determine Apple SDK path." ,
2634
2721
) ) ;
2635
2722
}
2636
2723
} ;
0 commit comments