Skip to content

Commit a0091db

Browse files
authored
Rollup merge of #98101 - vladimir-ea:stdlib_watch_os, r=thomcc
stdlib support for Apple WatchOS This is a follow-up to rust-lang/rust#95243 (Add Apple WatchOS compiler targets) that adds stdlib support for Apple WatchOS. `@deg4uss3r` `@nagisa`
2 parents 5289326 + 4147f83 commit a0091db

File tree

20 files changed

+75
-29
lines changed

20 files changed

+75
-29
lines changed

panic_unwind/src/gcc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const UNWIND_DATA_REG: (i32, i32) = (10, 11); // x10, x11
131131
// https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c
132132

133133
cfg_if::cfg_if! {
134-
if #[cfg(all(target_arch = "arm", not(target_os = "ios"), not(target_os = "netbsd")))] {
134+
if #[cfg(all(target_arch = "arm", not(target_os = "ios"), not(target_os = "watchos"), not(target_os = "netbsd")))] {
135135
// ARM EHABI personality routine.
136136
// https://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf
137137
//

std/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn main() {
1515
|| target.contains("illumos")
1616
|| target.contains("apple-darwin")
1717
|| target.contains("apple-ios")
18+
|| target.contains("apple-watchos")
1819
|| target.contains("uwp")
1920
|| target.contains("windows")
2021
|| target.contains("fuchsia")

std/src/os/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ pub mod openbsd;
141141
pub mod redox;
142142
#[cfg(target_os = "solaris")]
143143
pub mod solaris;
144-
145144
#[cfg(target_os = "solid_asp3")]
146145
pub mod solid;
147146
#[cfg(target_os = "vxworks")]

std/src/os/unix/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub mod thread;
9090
target_os = "dragonfly",
9191
target_os = "freebsd",
9292
target_os = "ios",
93+
target_os = "watchos",
9394
target_os = "macos",
9495
target_os = "netbsd",
9596
target_os = "openbsd"

std/src/os/unix/net/stream.rs

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, Owned
1212
target_os = "freebsd",
1313
target_os = "ios",
1414
target_os = "macos",
15+
target_os = "watchos",
1516
target_os = "netbsd",
1617
target_os = "openbsd"
1718
))]
@@ -30,6 +31,7 @@ use crate::time::Duration;
3031
target_os = "freebsd",
3132
target_os = "ios",
3233
target_os = "macos",
34+
target_os = "watchos",
3335
target_os = "netbsd",
3436
target_os = "openbsd"
3537
))]
@@ -238,6 +240,7 @@ impl UnixStream {
238240
target_os = "freebsd",
239241
target_os = "ios",
240242
target_os = "macos",
243+
target_os = "watchos",
241244
target_os = "netbsd",
242245
target_os = "openbsd"
243246
))]

std/src/os/unix/ucred.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub use self::impl_linux::peer_cred;
3636
))]
3737
pub use self::impl_bsd::peer_cred;
3838

39-
#[cfg(any(target_os = "macos", target_os = "ios",))]
39+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
4040
pub use self::impl_mac::peer_cred;
4141

4242
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -97,7 +97,7 @@ pub mod impl_bsd {
9797
}
9898
}
9999

100-
#[cfg(any(target_os = "macos", target_os = "ios",))]
100+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
101101
pub mod impl_mac {
102102
use super::UCred;
103103
use crate::os::unix::io::AsRawFd;

std/src/os/unix/ucred/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use libc::{getegid, geteuid, getpid};
99
target_os = "freebsd",
1010
target_os = "ios",
1111
target_os = "macos",
12+
target_os = "watchos",
1213
target_os = "openbsd"
1314
))]
1415
fn test_socket_pair() {
@@ -25,7 +26,7 @@ fn test_socket_pair() {
2526
}
2627

2728
#[test]
28-
#[cfg(any(target_os = "linux", target_os = "ios", target_os = "macos",))]
29+
#[cfg(any(target_os = "linux", target_os = "ios", target_os = "macos", target_os = "watchos"))]
2930
fn test_socket_pair_pids(arg: Type) -> RetType {
3031
// Create two connected sockets and get their peer credentials.
3132
let (sock_a, sock_b) = UnixStream::pair().unwrap();

std/src/sys/unix/args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ mod imp {
151151
}
152152
}
153153

154-
#[cfg(any(target_os = "macos", target_os = "ios"))]
154+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
155155
mod imp {
156156
use super::Args;
157157
use crate::ffi::CStr;
@@ -192,7 +192,7 @@ mod imp {
192192
// for i in (0..[args count])
193193
// res.push([args objectAtIndex:i])
194194
// res
195-
#[cfg(target_os = "ios")]
195+
#[cfg(any(target_os = "ios", target_os = "watchos"))]
196196
pub fn args() -> Args {
197197
use crate::ffi::OsString;
198198
use crate::mem;

std/src/sys/unix/env.rs

+11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ pub mod os {
3131
pub const EXE_EXTENSION: &str = "";
3232
}
3333

34+
#[cfg(target_os = "watchos")]
35+
pub mod os {
36+
pub const FAMILY: &str = "unix";
37+
pub const OS: &str = "watchos";
38+
pub const DLL_PREFIX: &str = "lib";
39+
pub const DLL_SUFFIX: &str = ".dylib";
40+
pub const DLL_EXTENSION: &str = "dylib";
41+
pub const EXE_SUFFIX: &str = "";
42+
pub const EXE_EXTENSION: &str = "";
43+
}
44+
3445
#[cfg(target_os = "freebsd")]
3546
pub mod os {
3647
pub const FAMILY: &str = "unix";

std/src/sys/unix/fd.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const READ_LIMIT: usize = libc::ssize_t::MAX as usize;
4747
target_os = "macos",
4848
target_os = "netbsd",
4949
target_os = "openbsd",
50+
target_os = "watchos",
5051
))]
5152
const fn max_iov() -> usize {
5253
libc::IOV_MAX as usize
@@ -67,7 +68,8 @@ const fn max_iov() -> usize {
6768
target_os = "macos",
6869
target_os = "netbsd",
6970
target_os = "openbsd",
70-
target_os = "horizon"
71+
target_os = "horizon",
72+
target_os = "watchos",
7173
)))]
7274
const fn max_iov() -> usize {
7375
16 // The minimum value required by POSIX.

std/src/sys/unix/fs.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
1717
all(target_os = "linux", target_env = "gnu"),
1818
target_os = "macos",
1919
target_os = "ios",
20+
target_os = "watchos",
2021
))]
2122
use crate::sys::weak::syscall;
2223
#[cfg(target_os = "macos")]
@@ -27,6 +28,7 @@ use libc::{c_int, mode_t};
2728
#[cfg(any(
2829
target_os = "macos",
2930
target_os = "ios",
31+
target_os = "watchos",
3032
all(target_os = "linux", target_env = "gnu")
3133
))]
3234
use libc::c_char;
@@ -443,7 +445,8 @@ impl FileAttr {
443445
target_os = "freebsd",
444446
target_os = "openbsd",
445447
target_os = "macos",
446-
target_os = "ios"
448+
target_os = "ios",
449+
target_os = "watchos",
447450
))]
448451
pub fn created(&self) -> io::Result<SystemTime> {
449452
Ok(SystemTime::new(self.stat.st_birthtime as i64, self.stat.st_birthtime_nsec as i64))
@@ -453,7 +456,8 @@ impl FileAttr {
453456
target_os = "freebsd",
454457
target_os = "openbsd",
455458
target_os = "macos",
456-
target_os = "ios"
459+
target_os = "ios",
460+
target_os = "watchos",
457461
)))]
458462
pub fn created(&self) -> io::Result<SystemTime> {
459463
cfg_has_statx! {
@@ -707,6 +711,7 @@ impl DirEntry {
707711
#[cfg(any(
708712
target_os = "macos",
709713
target_os = "ios",
714+
target_os = "watchos",
710715
target_os = "linux",
711716
target_os = "emscripten",
712717
target_os = "android",
@@ -737,6 +742,7 @@ impl DirEntry {
737742
#[cfg(any(
738743
target_os = "macos",
739744
target_os = "ios",
745+
target_os = "watchos",
740746
target_os = "netbsd",
741747
target_os = "openbsd",
742748
target_os = "freebsd",
@@ -754,6 +760,7 @@ impl DirEntry {
754760
#[cfg(not(any(
755761
target_os = "macos",
756762
target_os = "ios",
763+
target_os = "watchos",
757764
target_os = "netbsd",
758765
target_os = "openbsd",
759766
target_os = "freebsd",
@@ -911,11 +918,11 @@ impl File {
911918
cvt_r(|| unsafe { os_fsync(self.as_raw_fd()) })?;
912919
return Ok(());
913920

914-
#[cfg(any(target_os = "macos", target_os = "ios"))]
921+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
915922
unsafe fn os_fsync(fd: c_int) -> c_int {
916923
libc::fcntl(fd, libc::F_FULLFSYNC)
917924
}
918-
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
925+
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "watchos")))]
919926
unsafe fn os_fsync(fd: c_int) -> c_int {
920927
libc::fsync(fd)
921928
}
@@ -925,7 +932,7 @@ impl File {
925932
cvt_r(|| unsafe { os_datasync(self.as_raw_fd()) })?;
926933
return Ok(());
927934

928-
#[cfg(any(target_os = "macos", target_os = "ios"))]
935+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
929936
unsafe fn os_datasync(fd: c_int) -> c_int {
930937
libc::fcntl(fd, libc::F_FULLFSYNC)
931938
}
@@ -946,7 +953,8 @@ impl File {
946953
target_os = "linux",
947954
target_os = "macos",
948955
target_os = "netbsd",
949-
target_os = "openbsd"
956+
target_os = "openbsd",
957+
target_os = "watchos",
950958
)))]
951959
unsafe fn os_datasync(fd: c_int) -> c_int {
952960
libc::fsync(fd)
@@ -1396,7 +1404,8 @@ fn open_to_and_set_permissions(
13961404
target_os = "linux",
13971405
target_os = "android",
13981406
target_os = "macos",
1399-
target_os = "ios"
1407+
target_os = "ios",
1408+
target_os = "watchos",
14001409
)))]
14011410
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
14021411
let (mut reader, reader_metadata) = open_from(from)?;
@@ -1423,7 +1432,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
14231432
}
14241433
}
14251434

1426-
#[cfg(any(target_os = "macos", target_os = "ios"))]
1435+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
14271436
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
14281437
use crate::sync::atomic::{AtomicBool, Ordering};
14291438

std/src/sys/unix/locks/pthread_condvar.rs

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl Condvar {
3737
#[cfg(any(
3838
target_os = "macos",
3939
target_os = "ios",
40+
target_os = "watchos",
4041
target_os = "l4re",
4142
target_os = "android",
4243
target_os = "redox"
@@ -58,6 +59,7 @@ impl Condvar {
5859
#[cfg(not(any(
5960
target_os = "macos",
6061
target_os = "ios",
62+
target_os = "watchos",
6163
target_os = "l4re",
6264
target_os = "android",
6365
target_os = "redox",
@@ -102,6 +104,7 @@ impl Condvar {
102104
#[cfg(not(any(
103105
target_os = "macos",
104106
target_os = "ios",
107+
target_os = "watchos",
105108
target_os = "android",
106109
target_os = "espidf",
107110
target_os = "horizon"
@@ -135,6 +138,7 @@ impl Condvar {
135138
#[cfg(any(
136139
target_os = "macos",
137140
target_os = "ios",
141+
target_os = "watchos",
138142
target_os = "android",
139143
target_os = "espidf",
140144
target_os = "horizon"

std/src/sys/unix/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) {
8686
// The poll on Darwin doesn't set POLLNVAL for closed fds.
8787
target_os = "macos",
8888
target_os = "ios",
89+
target_os = "watchos",
8990
target_os = "redox",
9091
target_os = "l4re",
9192
target_os = "horizon",
@@ -329,7 +330,7 @@ cfg_if::cfg_if! {
329330
// See #41582 and https://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html
330331
#[link(name = "resolv")]
331332
extern "C" {}
332-
} else if #[cfg(target_os = "ios")] {
333+
} else if #[cfg(any(target_os = "ios", target_os = "watchos"))] {
333334
#[link(name = "System")]
334335
#[link(name = "objc")]
335336
#[link(name = "Security", kind = "framework")]

std/src/sys/unix/os.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern "C" {
6161
)]
6262
#[cfg_attr(any(target_os = "solaris", target_os = "illumos"), link_name = "___errno")]
6363
#[cfg_attr(
64-
any(target_os = "macos", target_os = "ios", target_os = "freebsd"),
64+
any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "watchos"),
6565
link_name = "__error"
6666
)]
6767
#[cfg_attr(target_os = "haiku", link_name = "_errnop")]
@@ -361,7 +361,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
361361
}
362362
}
363363

364-
#[cfg(any(target_os = "macos", target_os = "ios"))]
364+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
365365
pub fn current_exe() -> io::Result<PathBuf> {
366366
unsafe {
367367
let mut sz: u32 = 0;
@@ -598,6 +598,7 @@ pub fn home_dir() -> Option<PathBuf> {
598598
#[cfg(any(
599599
target_os = "android",
600600
target_os = "ios",
601+
target_os = "watchos",
601602
target_os = "emscripten",
602603
target_os = "redox",
603604
target_os = "vxworks",
@@ -610,6 +611,7 @@ pub fn home_dir() -> Option<PathBuf> {
610611
#[cfg(not(any(
611612
target_os = "android",
612613
target_os = "ios",
614+
target_os = "watchos",
613615
target_os = "emscripten",
614616
target_os = "redox",
615617
target_os = "vxworks",

std/src/sys/unix/rand.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub fn hashmap_random_keys() -> (u64, u64) {
1414
unix,
1515
not(target_os = "macos"),
1616
not(target_os = "ios"),
17+
not(target_os = "watchos"),
1718
not(target_os = "openbsd"),
1819
not(target_os = "freebsd"),
1920
not(target_os = "netbsd"),
@@ -195,7 +196,7 @@ mod imp {
195196
// once per thread in `hashmap_random_keys`. Therefore `SecRandomCopyBytes` is
196197
// only used on iOS where direct access to `/dev/urandom` is blocked by the
197198
// sandbox.
198-
#[cfg(target_os = "ios")]
199+
#[cfg(any(target_os = "ios", target_os = "watchos"))]
199200
mod imp {
200201
use crate::io;
201202
use crate::ptr;

std/src/sys/unix/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl Thread {
139139
}
140140
}
141141

142-
#[cfg(any(target_os = "macos", target_os = "ios"))]
142+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
143143
pub fn set_name(name: &CStr) {
144144
unsafe {
145145
libc::pthread_setname_np(name.as_ptr());

0 commit comments

Comments
 (0)