From 439d64a83c84fe36befacc4af867eaadb96589d5 Mon Sep 17 00:00:00 2001 From: Vladimir Michael Eatwell Date: Wed, 23 Mar 2022 16:05:01 +0000 Subject: [PATCH] Library changes for Apple WatchOS --- library/panic_unwind/src/gcc.rs | 2 +- library/std/build.rs | 1 + library/std/src/os/mod.rs | 1 - library/std/src/os/unix/mod.rs | 1 + library/std/src/os/unix/net/stream.rs | 3 +++ library/std/src/os/unix/ucred.rs | 4 +-- library/std/src/os/unix/ucred/tests.rs | 3 ++- library/std/src/sys/unix/args.rs | 4 +-- library/std/src/sys/unix/env.rs | 11 ++++++++ library/std/src/sys/unix/fd.rs | 4 ++- library/std/src/sys/unix/fs.rs | 25 +++++++++++++------ .../std/src/sys/unix/locks/pthread_condvar.rs | 4 +++ library/std/src/sys/unix/mod.rs | 3 ++- library/std/src/sys/unix/os.rs | 6 +++-- library/std/src/sys/unix/rand.rs | 3 ++- library/std/src/sys/unix/thread.rs | 2 +- library/std/src/sys/unix/thread_parker.rs | 15 +++++++++-- library/std/src/sys/unix/time.rs | 4 +-- library/std/src/sys_common/net.rs | 2 +- library/unwind/src/libunwind.rs | 6 ++--- 20 files changed, 75 insertions(+), 29 deletions(-) diff --git a/library/panic_unwind/src/gcc.rs b/library/panic_unwind/src/gcc.rs index a0297b4b2f524..057e47bfdd18a 100644 --- a/library/panic_unwind/src/gcc.rs +++ b/library/panic_unwind/src/gcc.rs @@ -131,7 +131,7 @@ const UNWIND_DATA_REG: (i32, i32) = (10, 11); // x10, x11 // https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c cfg_if::cfg_if! { - if #[cfg(all(target_arch = "arm", not(target_os = "ios"), not(target_os = "netbsd")))] { + if #[cfg(all(target_arch = "arm", not(target_os = "ios"), not(target_os = "watchos"), not(target_os = "netbsd")))] { // ARM EHABI personality routine. // https://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf // diff --git a/library/std/build.rs b/library/std/build.rs index bffbe802fd01e..8b1a06ee750fb 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -15,6 +15,7 @@ fn main() { || target.contains("illumos") || target.contains("apple-darwin") || target.contains("apple-ios") + || target.contains("apple-watchos") || target.contains("uwp") || target.contains("windows") || target.contains("fuchsia") diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index a1df72a8a0480..6fbaa42c76846 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -141,7 +141,6 @@ pub mod openbsd; pub mod redox; #[cfg(target_os = "solaris")] pub mod solaris; - #[cfg(target_os = "solid_asp3")] pub mod solid; #[cfg(target_os = "vxworks")] diff --git a/library/std/src/os/unix/mod.rs b/library/std/src/os/unix/mod.rs index cef546487f327..411cc0925c4b0 100644 --- a/library/std/src/os/unix/mod.rs +++ b/library/std/src/os/unix/mod.rs @@ -90,6 +90,7 @@ pub mod thread; target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "watchos", target_os = "macos", target_os = "netbsd", target_os = "openbsd" diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 1d6083e66e172..cc3a885879345 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -12,6 +12,7 @@ use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, Owned target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "watchos", target_os = "netbsd", target_os = "openbsd" ))] @@ -30,6 +31,7 @@ use crate::time::Duration; target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "watchos", target_os = "netbsd", target_os = "openbsd" ))] @@ -238,6 +240,7 @@ impl UnixStream { target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "watchos", target_os = "netbsd", target_os = "openbsd" ))] diff --git a/library/std/src/os/unix/ucred.rs b/library/std/src/os/unix/ucred.rs index 32e6430d3f627..ae4faf27b4d39 100644 --- a/library/std/src/os/unix/ucred.rs +++ b/library/std/src/os/unix/ucred.rs @@ -36,7 +36,7 @@ pub use self::impl_linux::peer_cred; ))] pub use self::impl_bsd::peer_cred; -#[cfg(any(target_os = "macos", target_os = "ios",))] +#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))] pub use self::impl_mac::peer_cred; #[cfg(any(target_os = "linux", target_os = "android"))] @@ -97,7 +97,7 @@ pub mod impl_bsd { } } -#[cfg(any(target_os = "macos", target_os = "ios",))] +#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))] pub mod impl_mac { use super::UCred; use crate::os::unix::io::AsRawFd; diff --git a/library/std/src/os/unix/ucred/tests.rs b/library/std/src/os/unix/ucred/tests.rs index 42d79418cf78f..e63a2fc248eb0 100644 --- a/library/std/src/os/unix/ucred/tests.rs +++ b/library/std/src/os/unix/ucred/tests.rs @@ -9,6 +9,7 @@ use libc::{getegid, geteuid, getpid}; target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "watchos", target_os = "openbsd" ))] fn test_socket_pair() { @@ -25,7 +26,7 @@ fn test_socket_pair() { } #[test] -#[cfg(any(target_os = "linux", target_os = "ios", target_os = "macos",))] +#[cfg(any(target_os = "linux", target_os = "ios", target_os = "macos", target_os = "watchos"))] fn test_socket_pair_pids(arg: Type) -> RetType { // Create two connected sockets and get their peer credentials. let (sock_a, sock_b) = UnixStream::pair().unwrap(); diff --git a/library/std/src/sys/unix/args.rs b/library/std/src/sys/unix/args.rs index 79964e2b2385f..a342f0f5e8597 100644 --- a/library/std/src/sys/unix/args.rs +++ b/library/std/src/sys/unix/args.rs @@ -151,7 +151,7 @@ mod imp { } } -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))] mod imp { use super::Args; use crate::ffi::CStr; @@ -192,7 +192,7 @@ mod imp { // for i in (0..[args count]) // res.push([args objectAtIndex:i]) // res - #[cfg(target_os = "ios")] + #[cfg(any(target_os = "ios", target_os = "watchos"))] pub fn args() -> Args { use crate::ffi::OsString; use crate::mem; diff --git a/library/std/src/sys/unix/env.rs b/library/std/src/sys/unix/env.rs index 4d8391656a4dd..c9ba661c829fa 100644 --- a/library/std/src/sys/unix/env.rs +++ b/library/std/src/sys/unix/env.rs @@ -31,6 +31,17 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } +#[cfg(target_os = "watchos")] +pub mod os { + pub const FAMILY: &str = "unix"; + pub const OS: &str = "watchos"; + pub const DLL_PREFIX: &str = "lib"; + pub const DLL_SUFFIX: &str = ".dylib"; + pub const DLL_EXTENSION: &str = "dylib"; + pub const EXE_SUFFIX: &str = ""; + pub const EXE_EXTENSION: &str = ""; +} + #[cfg(target_os = "freebsd")] pub mod os { pub const FAMILY: &str = "unix"; diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index 137ca3a763368..30812dabb4e0d 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -47,6 +47,7 @@ const READ_LIMIT: usize = libc::ssize_t::MAX as usize; target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "watchos", ))] const fn max_iov() -> usize { libc::IOV_MAX as usize @@ -67,7 +68,8 @@ const fn max_iov() -> usize { target_os = "macos", target_os = "netbsd", target_os = "openbsd", - target_os = "horizon" + target_os = "horizon", + target_os = "watchos", )))] const fn max_iov() -> usize { 16 // The minimum value required by POSIX. diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index 8b0bbd6a55c6b..7c8824694408c 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -17,6 +17,7 @@ use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; all(target_os = "linux", target_env = "gnu"), target_os = "macos", target_os = "ios", + target_os = "watchos", ))] use crate::sys::weak::syscall; #[cfg(target_os = "macos")] @@ -27,6 +28,7 @@ use libc::{c_int, mode_t}; #[cfg(any( target_os = "macos", target_os = "ios", + target_os = "watchos", all(target_os = "linux", target_env = "gnu") ))] use libc::c_char; @@ -443,7 +445,8 @@ impl FileAttr { target_os = "freebsd", target_os = "openbsd", target_os = "macos", - target_os = "ios" + target_os = "ios", + target_os = "watchos", ))] pub fn created(&self) -> io::Result { Ok(SystemTime::new(self.stat.st_birthtime as i64, self.stat.st_birthtime_nsec as i64)) @@ -453,7 +456,8 @@ impl FileAttr { target_os = "freebsd", target_os = "openbsd", target_os = "macos", - target_os = "ios" + target_os = "ios", + target_os = "watchos", )))] pub fn created(&self) -> io::Result { cfg_has_statx! { @@ -707,6 +711,7 @@ impl DirEntry { #[cfg(any( target_os = "macos", target_os = "ios", + target_os = "watchos", target_os = "linux", target_os = "emscripten", target_os = "android", @@ -737,6 +742,7 @@ impl DirEntry { #[cfg(any( target_os = "macos", target_os = "ios", + target_os = "watchos", target_os = "netbsd", target_os = "openbsd", target_os = "freebsd", @@ -754,6 +760,7 @@ impl DirEntry { #[cfg(not(any( target_os = "macos", target_os = "ios", + target_os = "watchos", target_os = "netbsd", target_os = "openbsd", target_os = "freebsd", @@ -911,11 +918,11 @@ impl File { cvt_r(|| unsafe { os_fsync(self.as_raw_fd()) })?; return Ok(()); - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))] unsafe fn os_fsync(fd: c_int) -> c_int { libc::fcntl(fd, libc::F_FULLFSYNC) } - #[cfg(not(any(target_os = "macos", target_os = "ios")))] + #[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "watchos")))] unsafe fn os_fsync(fd: c_int) -> c_int { libc::fsync(fd) } @@ -925,7 +932,7 @@ impl File { cvt_r(|| unsafe { os_datasync(self.as_raw_fd()) })?; return Ok(()); - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))] unsafe fn os_datasync(fd: c_int) -> c_int { libc::fcntl(fd, libc::F_FULLFSYNC) } @@ -946,7 +953,8 @@ impl File { target_os = "linux", target_os = "macos", target_os = "netbsd", - target_os = "openbsd" + target_os = "openbsd", + target_os = "watchos", )))] unsafe fn os_datasync(fd: c_int) -> c_int { libc::fsync(fd) @@ -1396,7 +1404,8 @@ fn open_to_and_set_permissions( target_os = "linux", target_os = "android", target_os = "macos", - target_os = "ios" + target_os = "ios", + target_os = "watchos", )))] pub fn copy(from: &Path, to: &Path) -> io::Result { let (mut reader, reader_metadata) = open_from(from)?; @@ -1423,7 +1432,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result { } } -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))] pub fn copy(from: &Path, to: &Path) -> io::Result { use crate::sync::atomic::{AtomicBool, Ordering}; diff --git a/library/std/src/sys/unix/locks/pthread_condvar.rs b/library/std/src/sys/unix/locks/pthread_condvar.rs index 78f10f0534c03..abf27e7db78c7 100644 --- a/library/std/src/sys/unix/locks/pthread_condvar.rs +++ b/library/std/src/sys/unix/locks/pthread_condvar.rs @@ -37,6 +37,7 @@ impl Condvar { #[cfg(any( target_os = "macos", target_os = "ios", + target_os = "watchos", target_os = "l4re", target_os = "android", target_os = "redox" @@ -58,6 +59,7 @@ impl Condvar { #[cfg(not(any( target_os = "macos", target_os = "ios", + target_os = "watchos", target_os = "l4re", target_os = "android", target_os = "redox", @@ -102,6 +104,7 @@ impl Condvar { #[cfg(not(any( target_os = "macos", target_os = "ios", + target_os = "watchos", target_os = "android", target_os = "espidf", target_os = "horizon" @@ -135,6 +138,7 @@ impl Condvar { #[cfg(any( target_os = "macos", target_os = "ios", + target_os = "watchos", target_os = "android", target_os = "espidf", target_os = "horizon" diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index 34a023b02c4fe..3d0d91460f706 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -86,6 +86,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) { // The poll on Darwin doesn't set POLLNVAL for closed fds. target_os = "macos", target_os = "ios", + target_os = "watchos", target_os = "redox", target_os = "l4re", target_os = "horizon", @@ -329,7 +330,7 @@ cfg_if::cfg_if! { // See #41582 and https://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html #[link(name = "resolv")] extern "C" {} - } else if #[cfg(target_os = "ios")] { + } else if #[cfg(any(target_os = "ios", target_os = "watchos"))] { #[link(name = "System")] #[link(name = "objc")] #[link(name = "Security", kind = "framework")] diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 7252ad321844b..46545a0839fe8 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -61,7 +61,7 @@ extern "C" { )] #[cfg_attr(any(target_os = "solaris", target_os = "illumos"), link_name = "___errno")] #[cfg_attr( - any(target_os = "macos", target_os = "ios", target_os = "freebsd"), + any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "watchos"), link_name = "__error" )] #[cfg_attr(target_os = "haiku", link_name = "_errnop")] @@ -361,7 +361,7 @@ pub fn current_exe() -> io::Result { } } -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))] pub fn current_exe() -> io::Result { unsafe { let mut sz: u32 = 0; @@ -598,6 +598,7 @@ pub fn home_dir() -> Option { #[cfg(any( target_os = "android", target_os = "ios", + target_os = "watchos", target_os = "emscripten", target_os = "redox", target_os = "vxworks", @@ -610,6 +611,7 @@ pub fn home_dir() -> Option { #[cfg(not(any( target_os = "android", target_os = "ios", + target_os = "watchos", target_os = "emscripten", target_os = "redox", target_os = "vxworks", diff --git a/library/std/src/sys/unix/rand.rs b/library/std/src/sys/unix/rand.rs index 56d01074c20ed..bf49204881d16 100644 --- a/library/std/src/sys/unix/rand.rs +++ b/library/std/src/sys/unix/rand.rs @@ -14,6 +14,7 @@ pub fn hashmap_random_keys() -> (u64, u64) { unix, not(target_os = "macos"), not(target_os = "ios"), + not(target_os = "watchos"), not(target_os = "openbsd"), not(target_os = "freebsd"), not(target_os = "netbsd"), @@ -195,7 +196,7 @@ mod imp { // once per thread in `hashmap_random_keys`. Therefore `SecRandomCopyBytes` is // only used on iOS where direct access to `/dev/urandom` is blocked by the // sandbox. -#[cfg(target_os = "ios")] +#[cfg(any(target_os = "ios", target_os = "watchos"))] mod imp { use crate::io; use crate::ptr; diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs index d191e1fe7a650..6533625876f89 100644 --- a/library/std/src/sys/unix/thread.rs +++ b/library/std/src/sys/unix/thread.rs @@ -139,7 +139,7 @@ impl Thread { } } - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))] pub fn set_name(name: &CStr) { unsafe { libc::pthread_setname_np(name.as_ptr()); diff --git a/library/std/src/sys/unix/thread_parker.rs b/library/std/src/sys/unix/thread_parker.rs index 76278ae30f1af..f244f64dab336 100644 --- a/library/std/src/sys/unix/thread_parker.rs +++ b/library/std/src/sys/unix/thread_parker.rs @@ -51,7 +51,12 @@ unsafe fn wait_timeout( ) { // Use the system clock on systems that do not support pthread_condattr_setclock. // This unfortunately results in problems when the system time changes. - #[cfg(any(target_os = "macos", target_os = "ios", target_os = "espidf"))] + #[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "watchos", + target_os = "espidf" + ))] let (now, dur) = { use super::time::SystemTime; use crate::cmp::min; @@ -72,7 +77,12 @@ unsafe fn wait_timeout( (now, dur) }; // Use the monotonic clock on other systems. - #[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "espidf")))] + #[cfg(not(any( + target_os = "macos", + target_os = "ios", + target_os = "watchos", + target_os = "espidf" + )))] let (now, dur) = { use super::time::Timespec; @@ -110,6 +120,7 @@ impl Parker { if #[cfg(any( target_os = "macos", target_os = "ios", + target_os = "watchos", target_os = "l4re", target_os = "android", target_os = "redox" diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index d114af49d26c7..dff973f59d1a7 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -141,7 +141,7 @@ impl From for Timespec { } } -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))] mod inner { use crate::sync::atomic::{AtomicU64, Ordering}; use crate::sys::cvt; @@ -257,7 +257,7 @@ mod inner { } } -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "watchos")))] mod inner { use crate::fmt; use crate::mem::MaybeUninit; diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index f5730a2cea52b..c13bda3282320 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -18,7 +18,7 @@ use libc::{c_int, c_void}; cfg_if::cfg_if! { if #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", target_os = "macos", + target_os = "ios", target_os = "macos", target_os = "watchos", target_os = "openbsd", target_os = "netbsd", target_os = "illumos", target_os = "solaris", target_os = "haiku", target_os = "l4re"))] { use crate::sys::net::netc::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP; diff --git a/library/unwind/src/libunwind.rs b/library/unwind/src/libunwind.rs index 7b78bda424bb0..a5b6193b086fb 100644 --- a/library/unwind/src/libunwind.rs +++ b/library/unwind/src/libunwind.rs @@ -30,10 +30,10 @@ pub const unwinder_private_data_size: usize = 5; #[cfg(target_arch = "x86_64")] pub const unwinder_private_data_size: usize = 6; -#[cfg(all(target_arch = "arm", not(target_os = "ios")))] +#[cfg(all(target_arch = "arm", not(any(target_os = "ios", target_os = "watchos"))))] pub const unwinder_private_data_size: usize = 20; -#[cfg(all(target_arch = "arm", target_os = "ios"))] +#[cfg(all(target_arch = "arm", any(target_os = "ios", target_os = "watchos")))] pub const unwinder_private_data_size: usize = 5; #[cfg(all(target_arch = "aarch64", target_pointer_width = "64"))] @@ -105,7 +105,7 @@ extern "C" { } cfg_if::cfg_if! { -if #[cfg(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm")))] { +if #[cfg(any(target_os = "ios", target_os = "watchos", target_os = "netbsd", not(target_arch = "arm")))] { // Not ARM EHABI #[repr(C)] #[derive(Copy, Clone, PartialEq)]