5959use  std:: collections:: HashMap ; 
6060use  std:: env; 
6161use  std:: ffi:: { OsStr ,  OsString } ; 
62- use  std:: fmt:: { self ,  Display } ; 
62+ use  std:: fmt:: { self ,  Display ,   Formatter } ; 
6363use  std:: fs; 
6464use  std:: io:: { self ,  BufRead ,  BufReader ,  Read ,  Write } ; 
6565use  std:: path:: { Component ,  Path ,  PathBuf } ; 
@@ -168,7 +168,7 @@ impl From<io::Error> for Error {
168168} 
169169
170170impl  Display  for  Error  { 
171-     fn  fmt ( & self ,  f :  & mut  fmt:: Formatter )  -> fmt:: Result  { 
171+     fn  fmt ( & self ,  f :  & mut  fmt:: Formatter < ' _ > )  -> fmt:: Result  { 
172172        write ! ( f,  "{:?}: {}" ,  self . kind,  self . message) 
173173    } 
174174} 
@@ -1311,6 +1311,13 @@ impl Build {
13111311        if  self . cuda  && self . files . len ( )  > 1  { 
13121312            cmd. arg ( "--device-c" ) ; 
13131313        } 
1314+         if  compiler. family  == ( ToolFamily :: Msvc  {  clang_cl :  true  } )  { 
1315+             // #513: For `clang-cl`, separate flags/options from the input file. 
1316+             // When cross-compiling macOS -> Windows, this avoids interpreting 
1317+             // common `/Users/...` paths as the `/U` flag and triggering 
1318+             // `-Wslash-u-filename` warning. 
1319+             cmd. arg ( "--" ) ; 
1320+         } 
13141321        cmd. arg ( & obj. src ) ; 
13151322        if  cfg ! ( target_os = "macos" )  { 
13161323            self . fix_env_for_apple_os ( & mut  cmd) ?; 
@@ -1522,7 +1529,7 @@ impl Build {
15221529                    cmd. push_opt_unless_duplicate ( "-DANDROID" . into ( ) ) ; 
15231530                } 
15241531
1525-                 if  !target. contains ( "apple-ios" )  { 
1532+                 if  !target. contains ( "apple-ios" )  && !target . contains ( "apple-watchos" )   { 
15261533                    cmd. push_cc_arg ( "-ffunction-sections" . into ( ) ) ; 
15271534                    cmd. push_cc_arg ( "-fdata-sections" . into ( ) ) ; 
15281535                } 
@@ -1590,6 +1597,20 @@ impl Build {
15901597                                . into ( ) , 
15911598                            ) ; 
15921599                        } 
1600+                     }  else  if  target. contains ( "watchos-sim" )  { 
1601+                         if  let  Some ( arch)  =
1602+                             map_darwin_target_from_rust_to_compiler_architecture ( target) 
1603+                         { 
1604+                             let  deployment_target = env:: var ( "WATCHOS_DEPLOYMENT_TARGET" ) 
1605+                                 . unwrap_or_else ( |_| "5.0" . into ( ) ) ; 
1606+                             cmd. args . push ( 
1607+                                 format ! ( 
1608+                                     "--target={}-apple-watchos{}-simulator" , 
1609+                                     arch,  deployment_target
1610+                                 ) 
1611+                                 . into ( ) , 
1612+                             ) ; 
1613+                         } 
15931614                    }  else  if  target. starts_with ( "riscv64gc-" )  { 
15941615                        cmd. args . push ( 
15951616                            format ! ( "--target={}" ,  target. replace( "riscv64gc" ,  "riscv64" ) ) . into ( ) , 
@@ -1849,8 +1870,8 @@ impl Build {
18491870            } 
18501871        } 
18511872
1852-         if  target. contains ( "apple-ios" )  { 
1853-             self . ios_flags ( cmd) ?; 
1873+         if  target. contains ( "apple-ios" )  || target . contains ( "apple-watchos" )   { 
1874+             self . ios_watchos_flags ( cmd) ?; 
18541875        } 
18551876
18561877        if  self . static_flag . unwrap_or ( false )  { 
@@ -2043,18 +2064,37 @@ impl Build {
20432064        Ok ( ( ) ) 
20442065    } 
20452066
2046-     fn  ios_flags ( & self ,  cmd :  & mut  Tool )  -> Result < ( ) ,  Error >  { 
2067+     fn  ios_watchos_flags ( & self ,  cmd :  & mut  Tool )  -> Result < ( ) ,  Error >  { 
20472068        enum  ArchSpec  { 
20482069            Device ( & ' static  str ) , 
20492070            Simulator ( & ' static  str ) , 
20502071            Catalyst ( & ' static  str ) , 
20512072        } 
20522073
2074+         enum  Os  { 
2075+             Ios , 
2076+             WatchOs , 
2077+         } 
2078+         impl  Display  for  Os  { 
2079+             fn  fmt ( & self ,  f :  & mut  Formatter < ' _ > )  -> fmt:: Result  { 
2080+                 match  self  { 
2081+                     Os :: Ios  => f. write_str ( "iOS" ) , 
2082+                     Os :: WatchOs  => f. write_str ( "WatchOS" ) , 
2083+                 } 
2084+             } 
2085+         } 
2086+ 
20532087        let  target = self . get_target ( ) ?; 
2088+         let  os = if  target. contains ( "-watchos" )  { 
2089+             Os :: WatchOs 
2090+         }  else  { 
2091+             Os :: Ios 
2092+         } ; 
2093+ 
20542094        let  arch = target. split ( '-' ) . nth ( 0 ) . ok_or_else ( || { 
20552095            Error :: new ( 
20562096                ErrorKind :: ArchitectureInvalid , 
2057-                 "Unknown architecture for iOS  target." , 
2097+                 format ! ( "Unknown architecture for {}  target." ,  os ) . as_str ( ) , 
20582098            ) 
20592099        } ) ?; 
20602100
@@ -2083,6 +2123,7 @@ impl Build {
20832123        }  else  if  is_sim { 
20842124            match  arch { 
20852125                "arm64"  | "aarch64"  => ArchSpec :: Simulator ( "-arch arm64" ) , 
2126+                 "x86_64"  => ArchSpec :: Simulator ( "-m64" ) , 
20862127                _ => { 
20872128                    return  Err ( Error :: new ( 
20882129                        ErrorKind :: ArchitectureInvalid , 
@@ -2093,46 +2134,59 @@ impl Build {
20932134        }  else  { 
20942135            match  arch { 
20952136                "arm"  | "armv7"  | "thumbv7"  => ArchSpec :: Device ( "armv7" ) , 
2137+                 "armv7k"  => ArchSpec :: Device ( "armv7k" ) , 
20962138                "armv7s"  | "thumbv7s"  => ArchSpec :: Device ( "armv7s" ) , 
20972139                "arm64e"  => ArchSpec :: Device ( "arm64e" ) , 
20982140                "arm64"  | "aarch64"  => ArchSpec :: Device ( "arm64" ) , 
2141+                 "arm64_32"  => ArchSpec :: Device ( "arm64_32" ) , 
20992142                "i386"  | "i686"  => ArchSpec :: Simulator ( "-m32" ) , 
21002143                "x86_64"  => ArchSpec :: Simulator ( "-m64" ) , 
21012144                _ => { 
21022145                    return  Err ( Error :: new ( 
21032146                        ErrorKind :: ArchitectureInvalid , 
2104-                         "Unknown architecture for iOS  target." , 
2147+                         format ! ( "Unknown architecture for {}  target." ,  os ) . as_str ( ) , 
21052148                    ) ) ; 
21062149                } 
21072150            } 
21082151        } ; 
21092152
2110-         let  min_version =
2111-             std:: env:: var ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "7.0" . into ( ) ) ; 
2153+         let  ( sdk_prefix,  sim_prefix,  min_version)  = match  os { 
2154+             Os :: Ios  => ( 
2155+                 "iphone" , 
2156+                 "ios-" , 
2157+                 std:: env:: var ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "7.0" . into ( ) ) , 
2158+             ) , 
2159+             Os :: WatchOs  => ( 
2160+                 "watch" , 
2161+                 "watch" , 
2162+                 std:: env:: var ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "2.0" . into ( ) ) , 
2163+             ) , 
2164+         } ; 
21122165
21132166        let  sdk = match  arch { 
21142167            ArchSpec :: Device ( arch)  => { 
21152168                cmd. args . push ( "-arch" . into ( ) ) ; 
21162169                cmd. args . push ( arch. into ( ) ) ; 
21172170                cmd. args 
2118-                     . push ( format ! ( "-miphoneos -version-min={}" ,  min_version) . into ( ) ) ; 
2119-                 "iphoneos" 
2171+                     . push ( format ! ( "-m{}os -version-min={}" ,  sdk_prefix ,  min_version) . into ( ) ) ; 
2172+                 format ! ( "{}os" ,  sdk_prefix ) 
21202173            } 
21212174            ArchSpec :: Simulator ( arch)  => { 
21222175                cmd. args . push ( arch. into ( ) ) ; 
21232176                cmd. args 
2124-                     . push ( format ! ( "-mios- simulator-version-min={}" ,  min_version) . into ( ) ) ; 
2125-                 "iphonesimulator" 
2177+                     . push ( format ! ( "-m{} simulator-version-min={}" ,  sim_prefix ,  min_version) . into ( ) ) ; 
2178+                 format ! ( "{}simulator" ,  sdk_prefix ) 
21262179            } 
2127-             ArchSpec :: Catalyst ( _)  => "macosx" , 
2180+             ArchSpec :: Catalyst ( _)  => "macosx" . to_owned ( ) , 
21282181        } ; 
21292182
2130-         self . print ( & format ! ( "Detecting iOS  SDK path for {}" ,  sdk) ) ; 
2183+         self . print ( & format ! ( "Detecting {}  SDK path for {}" ,  os ,  sdk) ) ; 
21312184        let  sdk_path = if  let  Some ( sdkroot)  = env:: var_os ( "SDKROOT" )  { 
21322185            sdkroot
21332186        }  else  { 
2134-             self . apple_sdk_root ( sdk) ?
2187+             self . apple_sdk_root ( sdk. as_str ( ) ) ?
21352188        } ; 
2189+ 
21362190        cmd. args . push ( "-isysroot" . into ( ) ) ; 
21372191        cmd. args . push ( sdk_path) ; 
21382192        cmd. args . push ( "-fembed-bitcode" . into ( ) ) ; 
@@ -2234,6 +2288,8 @@ impl Build {
22342288                    } 
22352289                }  else  if  target. contains ( "apple-ios" )  { 
22362290                    clang. to_string ( ) 
2291+                 }  else  if  target. contains ( "apple-watchos" )  { 
2292+                     clang. to_string ( ) 
22372293                }  else  if  target. contains ( "android" )  { 
22382294                    autodetect_android_compiler ( & target,  & host,  gnu,  clang) 
22392295                }  else  if  target. contains ( "cloudabi" )  { 
@@ -2810,7 +2866,7 @@ impl Build {
28102866            Err ( _)  => { 
28112867                return  Err ( Error :: new ( 
28122868                    ErrorKind :: IOError , 
2813-                     "Unable to determine iOS  SDK path." , 
2869+                     "Unable to determine Apple  SDK path." , 
28142870                ) ) ; 
28152871            } 
28162872        } ; 
0 commit comments