From fa07b646fc47b572e730777975081473ffca7403 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 21 Mar 2025 08:56:39 -0700 Subject: [PATCH] Add support for visionos, watchos, and tvos. This patch just adds these `target_os` values to all places that use `target_os = "ios"`. --- cap-net-ext/src/lib.rs | 8 ++++-- cap-primitives/src/rustix/fs/copy_impl.rs | 21 ++++++++++++-- cap-primitives/src/rustix/fs/dir_utils.rs | 3 ++ cap-primitives/src/rustix/fs/metadata_ext.rs | 8 +++++- cap-primitives/src/rustix/fs/mod.rs | 21 ++++++++++++-- cap-primitives/src/rustix/fs/oflags.rs | 3 ++ cap-primitives/src/rustix/mod.rs | 8 +++++- tests/fs.rs | 11 ++++++- tests/fs_additional.rs | 30 ++++++++++++++++++-- tests/fs_utf8.rs | 11 ++++++- tests/rename.rs | 12 +++++++- tests/sys/unix/weak.rs | 16 +++++++++-- 12 files changed, 134 insertions(+), 18 deletions(-) diff --git a/cap-net-ext/src/lib.rs b/cap-net-ext/src/lib.rs index 96f12ddf..4b7f4528 100644 --- a/cap-net-ext/src/lib.rs +++ b/cap-net-ext/src/lib.rs @@ -655,6 +655,7 @@ fn socket_flags(blocking: Blocking) -> rustix::net::SocketFlags { target_os = "ios", target_os = "tvos", target_os = "watchos", + target_os = "visionos", target_os = "haiku" )))] { @@ -668,6 +669,7 @@ fn socket_flags(blocking: Blocking) -> rustix::net::SocketFlags { target_os = "ios", target_os = "tvos", target_os = "watchos", + target_os = "visionos", target_os = "haiku" )))] match blocking { @@ -688,7 +690,8 @@ fn set_socket_flags(fd: &OwnedFd, blocking: Blocking) -> io::Result<()> { target_os = "macos", target_os = "ios", target_os = "tvos", - target_os = "watchos" + target_os = "watchos", + target_os = "visionos", ))] { rustix::io::ioctl_fioclex(fd)?; @@ -699,7 +702,8 @@ fn set_socket_flags(fd: &OwnedFd, blocking: Blocking) -> io::Result<()> { target_os = "macos", target_os = "ios", target_os = "tvos", - target_os = "watchos" + target_os = "watchos", + target_os = "visionos" ))] match blocking { Blocking::Yes => (), diff --git a/cap-primitives/src/rustix/fs/copy_impl.rs b/cap-primitives/src/rustix/fs/copy_impl.rs index ee86961d..c4e5be75 100644 --- a/cap-primitives/src/rustix/fs/copy_impl.rs +++ b/cap-primitives/src/rustix/fs/copy_impl.rs @@ -5,7 +5,13 @@ use crate::fs::{open, OpenOptions}; #[cfg(any(target_os = "android", target_os = "linux"))] use rustix::fs::copy_file_range; -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", +))] use rustix::fs::{ copyfile_state_alloc, copyfile_state_free, copyfile_state_get_copied, copyfile_state_t, fclonefileat, fcopyfile, CloneFlags, CopyfileFlags, @@ -78,7 +84,10 @@ fn open_to_and_set_permissions( target_os = "linux", target_os = "android", target_os = "macos", - target_os = "ios" + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", )))] pub(crate) fn copy_impl( from_start: &fs::File, @@ -159,7 +168,13 @@ pub(crate) fn copy_impl( Ok(written) } -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", +))] #[allow(non_upper_case_globals)] #[allow(unsafe_code)] pub(crate) fn copy_impl( diff --git a/cap-primitives/src/rustix/fs/dir_utils.rs b/cap-primitives/src/rustix/fs/dir_utils.rs index 5e29133a..1093fac4 100644 --- a/cap-primitives/src/rustix/fs/dir_utils.rs +++ b/cap-primitives/src/rustix/fs/dir_utils.rs @@ -140,6 +140,9 @@ pub(crate) const fn target_o_path() -> OFlags { target_os = "dragonfly", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", target_os = "netbsd", target_os = "openbsd", target_os = "wasi", diff --git a/cap-primitives/src/rustix/fs/metadata_ext.rs b/cap-primitives/src/rustix/fs/metadata_ext.rs index 5330637d..0e9920e6 100644 --- a/cap-primitives/src/rustix/fs/metadata_ext.rs +++ b/cap-primitives/src/rustix/fs/metadata_ext.rs @@ -144,7 +144,10 @@ impl ImplMetadataExt { target_os = "freebsd", target_os = "openbsd", target_os = "macos", - target_os = "ios" + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", ))] created: system_time_from_rustix( stat.st_birthtime.try_into().unwrap(), @@ -163,6 +166,9 @@ impl ImplMetadataExt { target_os = "openbsd", target_os = "macos", target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", target_os = "netbsd" )))] created: None, diff --git a/cap-primitives/src/rustix/fs/mod.rs b/cap-primitives/src/rustix/fs/mod.rs index a872b0a7..b6a0def2 100644 --- a/cap-primitives/src/rustix/fs/mod.rs +++ b/cap-primitives/src/rustix/fs/mod.rs @@ -42,7 +42,13 @@ pub(crate) mod errors; // // On FreeBSD, use optimized implementations based on // `O_RESOLVE_BENEATH`/`AT_RESOLVE_BENEATH` and `O_PATH` when available. -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", +))] pub(crate) use crate::rustix::darwin::fs::*; #[cfg(target_os = "freebsd")] pub(crate) use crate::rustix::freebsd::fs::*; @@ -57,13 +63,22 @@ pub(crate) use crate::fs::{ manually::canonicalize as canonicalize_impl, via_parent::set_times_nofollow as set_times_nofollow_impl, }; -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", +))] pub(super) use file_path::file_path_by_ttyname_or_seaching; #[cfg(not(any( target_os = "android", target_os = "linux", target_os = "macos", - target_os = "ios" + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", )))] pub(crate) use file_path::file_path_by_ttyname_or_seaching as file_path; #[cfg(not(any( diff --git a/cap-primitives/src/rustix/fs/oflags.rs b/cap-primitives/src/rustix/fs/oflags.rs index 211c29bf..d9349673 100644 --- a/cap-primitives/src/rustix/fs/oflags.rs +++ b/cap-primitives/src/rustix/fs/oflags.rs @@ -27,6 +27,9 @@ pub(in super::super) fn compute_oflags(options: &OpenOptions) -> io::Result String { /* // TODO: Platform-specific error code. cfg_if::cfg_if! { - if #[cfg(any(target_os = "macos", target_os = "netbsd", target_os = "freebsd", target_os = "openbsd", target_os = "ios", target_os = "dragonfly"))] { + if #[cfg(any( + target_os = "macos", + target_os = "netbsd", + target_os = "freebsd", + target_os = "openbsd", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", + target_os = "dragonfly" + ))] { fn rename_file_over_dir() -> String { rustix::io::Errno::ISDIR.into().to_string() } diff --git a/tests/sys/unix/weak.rs b/tests/sys/unix/weak.rs index 030e818a..ecc58eef 100644 --- a/tests/sys/unix/weak.rs +++ b/tests/sys/unix/weak.rs @@ -33,7 +33,13 @@ use std::sync::atomic::{self, AtomicUsize, Ordering}; // We can use true weak linkage on ELF targets. #[macro_export] -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", +)))] macro_rules! weak { (fn $name:ident($($t:ty),*) -> $ret:ty) => ( let ref $name: ExternWeak $ret> = { @@ -48,7 +54,13 @@ macro_rules! weak { } // On non-ELF targets, use the dlsym approximation of weak linkage. -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", +))] pub(crate) use crate::dlsym as weak; pub(crate) struct ExternWeak {