Skip to content

Commit

Permalink
Rollup merge of rust-lang#98101 - vladimir-ea:stdlib_watch_os, r=thomcc
Browse files Browse the repository at this point in the history
stdlib support for Apple WatchOS

This is a follow-up to rust-lang#95243 (Add Apple WatchOS compiler targets) that adds stdlib support for Apple WatchOS.

`@deg4uss3r`
`@nagisa`
  • Loading branch information
Dylan-DPC authored Jul 20, 2022
2 parents 748cb1f + 439d64a commit 90c59e7
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 29 deletions.
2 changes: 1 addition & 1 deletion library/panic_unwind/src/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
1 change: 1 addition & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion library/std/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/os/unix/net/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
))]
Expand All @@ -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"
))]
Expand Down Expand Up @@ -238,6 +240,7 @@ impl UnixStream {
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "watchos",
target_os = "netbsd",
target_os = "openbsd"
))]
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/os/unix/ucred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/unix/ucred/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/unix/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions library/std/src/sys/unix/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 3 additions & 1 deletion library/std/src/sys/unix/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
25 changes: 17 additions & 8 deletions library/std/src/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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;
Expand Down Expand Up @@ -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<SystemTime> {
Ok(SystemTime::new(self.stat.st_birthtime as i64, self.stat.st_birthtime_nsec as i64))
Expand All @@ -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<SystemTime> {
cfg_has_statx! {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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<u64> {
let (mut reader, reader_metadata) = open_from(from)?;
Expand All @@ -1423,7 +1432,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
}
}

#[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<u64> {
use crate::sync::atomic::{AtomicBool, Ordering};

Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/unix/locks/pthread_condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")]
Expand Down
6 changes: 4 additions & 2 deletions library/std/src/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -361,7 +361,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
}
}

#[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<PathBuf> {
unsafe {
let mut sz: u32 = 0;
Expand Down Expand Up @@ -598,6 +598,7 @@ pub fn home_dir() -> Option<PathBuf> {
#[cfg(any(
target_os = "android",
target_os = "ios",
target_os = "watchos",
target_os = "emscripten",
target_os = "redox",
target_os = "vxworks",
Expand All @@ -610,6 +611,7 @@ pub fn home_dir() -> Option<PathBuf> {
#[cfg(not(any(
target_os = "android",
target_os = "ios",
target_os = "watchos",
target_os = "emscripten",
target_os = "redox",
target_os = "vxworks",
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/sys/unix/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading

0 comments on commit 90c59e7

Please sign in to comment.