Skip to content

Add support for visionos, watchos, and tvos. #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cap-net-ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)))]
{
Expand All @@ -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 {
Expand All @@ -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)?;
Expand All @@ -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 => (),
Expand Down
21 changes: 18 additions & 3 deletions cap-primitives/src/rustix/fs/copy_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions cap-primitives/src/rustix/fs/dir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion cap-primitives/src/rustix/fs/metadata_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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,
Expand Down
21 changes: 18 additions & 3 deletions cap-primitives/src/rustix/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions cap-primitives/src/rustix/fs/oflags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub(in super::super) fn compute_oflags(options: &OpenOptions) -> io::Result<OFla
#[cfg(not(any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
target_os = "freebsd",
target_os = "fuchsia"
)))]
Expand Down
8 changes: 7 additions & 1 deletion cap-primitives/src/rustix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@

pub(crate) mod fs;

#[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",
))]
mod darwin;
#[cfg(target_os = "freebsd")]
mod freebsd;
Expand Down
11 changes: 10 additions & 1 deletion tests/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,16 @@ fn file_test_io_read_write_at() {
// following symlinks.
#[test]
#[cfg(unix)]
#[cfg_attr(any(target_os = "macos", target_os = "ios"), ignore)]
#[cfg_attr(
any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
),
ignore
)]
fn set_get_unix_permissions() {
use cap_std::fs::PermissionsExt;

Expand Down
30 changes: 27 additions & 3 deletions tests/fs_additional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,16 @@ fn file_with_trailing_slashdot_ambient() {
assert!(Dir::open_ambient_dir(dir.path().join("file/..."), ambient_authority()).is_err());
}

#[cfg(all(unix, not(any(target_os = "ios", target_os = "macos"))))]
#[cfg(all(
unix,
not(any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
))
))]
#[test]
fn dir_searchable_unreadable() {
use cap_std::fs::{DirBuilder, DirBuilderExt};
Expand All @@ -593,7 +602,16 @@ fn dir_searchable_unreadable() {
/// This test is the same as `dir_searchable_unreadable` but uses `std::fs`'
/// ambient API instead of `cap_std`. The purpose of this test is to
/// confirm fundamentally OS-specific differences.
#[cfg(all(unix, not(any(target_os = "ios", target_os = "macos"))))]
#[cfg(all(
unix,
not(any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
))
))]
#[test]
fn dir_searchable_unreadable_ambient() {
use std::fs;
Expand All @@ -615,7 +633,13 @@ fn dir_searchable_unreadable_ambient() {

/// On Darwin, we don't have a race-free way to create a subdirectory within
/// a directory that we don't have read access to.
#[cfg(any(target_os = "ios", target_os = "macos"))]
#[cfg(any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
))]
#[test]
fn dir_searchable_unreadable() {
use cap_std::fs::{DirBuilder, DirBuilderExt};
Expand Down
11 changes: 10 additions & 1 deletion tests/fs_utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,16 @@ fn file_test_io_read_write_at() {
// following symlinks.
#[test]
#[cfg(unix)]
#[cfg_attr(any(target_os = "macos", target_os = "ios"), ignore)]
#[cfg_attr(
any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
),
ignore
)]
fn set_get_unix_permissions() {
use cap_std::fs::PermissionsExt;

Expand Down
12 changes: 11 additions & 1 deletion tests/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ fn no_such_file_or_directory() -> 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()
}
Expand Down
16 changes: 14 additions & 2 deletions tests/sys/unix/weak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsafe extern "C" fn($($t),*) -> $ret> = {
Expand All @@ -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<F> {
Expand Down
Loading