From d5dc1113734100e73d328ad7ba0a6079d8c953e4 Mon Sep 17 00:00:00 2001 From: Quentin Perez Date: Mon, 8 Apr 2024 12:05:45 +0200 Subject: [PATCH] Add Apple visionOS support --- .github/workflows/ci.yml | 2 +- Makefile | 2 +- src/interest.rs | 2 ++ src/sys/unix/net.rs | 4 ++++ src/sys/unix/pipe.rs | 2 ++ src/sys/unix/selector/kqueue.rs | 42 +++++++++++++++++++++++++++++++++ src/sys/unix/selector/mod.rs | 2 ++ src/sys/unix/tcp.rs | 1 + src/sys/unix/uds/listener.rs | 2 ++ src/sys/unix/uds/mod.rs | 2 ++ src/sys/unix/waker.rs | 4 ++++ tests/interest.rs | 1 + tests/tcp_stream.rs | 2 ++ tests/unix_stream.rs | 3 +++ tests/util/mod.rs | 2 ++ 15 files changed, 71 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5aa58b1d4..4b0c2c79a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -142,7 +142,7 @@ jobs: strategy: fail-fast: false matrix: - target: ["aarch64-apple-ios", "aarch64-apple-tvos", "aarch64-unknown-openbsd", "arm64_32-apple-watchos", "armv7-sony-vita-newlibeabihf", "sparcv9-sun-solaris", "x86_64-pc-solaris", "x86_64-unknown-dragonfly", "x86_64-unknown-openbsd"] + target: ["aarch64-apple-ios", "aarch64-apple-visionos", "aarch64-apple-tvos", "aarch64-unknown-openbsd", "arm64_32-apple-watchos", "armv7-sony-vita-newlibeabihf", "sparcv9-sun-solaris", "x86_64-pc-solaris", "x86_64-unknown-dragonfly", "x86_64-unknown-openbsd"] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly diff --git a/Makefile b/Makefile index 85de1ee74..31c3c089b 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Targets available via Rustup that are supported. -TARGETS ?= aarch64-apple-darwin aarch64-apple-ios aarch64-linux-android arm-linux-androideabi i686-unknown-linux-gnu wasm32-wasi x86_64-apple-darwin x86_64-apple-ios x86_64-pc-windows-gnu x86_64-pc-windows-msvc x86_64-unknown-freebsd x86_64-unknown-illumos x86_64-unknown-linux-gnu x86_64-unknown-linux-musl x86_64-unknown-netbsd x86_64-unknown-redox +TARGETS ?= aarch64-apple-darwin aarch64-apple-ios aarch64-apple-visionos aarch64-linux-android arm-linux-androideabi i686-unknown-linux-gnu wasm32-wasi x86_64-apple-darwin x86_64-apple-ios x86_64-pc-windows-gnu x86_64-pc-windows-msvc x86_64-unknown-freebsd x86_64-unknown-illumos x86_64-unknown-linux-gnu x86_64-unknown-linux-musl x86_64-unknown-netbsd x86_64-unknown-redox # Example value: `nightly-x86_64-apple-darwin`. RUSTUP_TOOLCHAIN ?= $(shell rustup show active-toolchain | cut -d' ' -f1) # Architecture target. Example value: `x86_64-apple-darwin`. diff --git a/src/interest.rs b/src/interest.rs index 2bab78690..b4584c692 100644 --- a/src/interest.rs +++ b/src/interest.rs @@ -36,6 +36,7 @@ impl Interest { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -161,6 +162,7 @@ impl fmt::Debug for Interest { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", diff --git a/src/sys/unix/net.rs b/src/sys/unix/net.rs index 5a473bd2d..b7513088c 100644 --- a/src/sys/unix/net.rs +++ b/src/sys/unix/net.rs @@ -33,6 +33,7 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R // Mimick `libstd` and set `SO_NOSIGPIPE` on apple systems. #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -51,6 +52,7 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R // Darwin (and others) doesn't have SOCK_NONBLOCK or SOCK_CLOEXEC. #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -112,6 +114,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_ target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "netbsd", target_os = "openbsd", @@ -145,6 +148,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_ target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "netbsd", target_os = "openbsd", diff --git a/src/sys/unix/pipe.rs b/src/sys/unix/pipe.rs index c44106a29..fe5733d6c 100644 --- a/src/sys/unix/pipe.rs +++ b/src/sys/unix/pipe.rs @@ -29,6 +29,7 @@ pub(crate) fn new_raw() -> io::Result<[RawFd; 2]> { #[cfg(any( target_os = "aix", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -62,6 +63,7 @@ pub(crate) fn new_raw() -> io::Result<[RawFd; 2]> { target_os = "freebsd", target_os = "illumos", target_os = "ios", + target_os = "visionos", target_os = "linux", target_os = "macos", target_os = "netbsd", diff --git a/src/sys/unix/selector/kqueue.rs b/src/sys/unix/selector/kqueue.rs index 0a2a24a57..6e829d282 100644 --- a/src/sys/unix/selector/kqueue.rs +++ b/src/sys/unix/selector/kqueue.rs @@ -22,6 +22,7 @@ type Count = libc::size_t; type Filter = libc::c_short; #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -35,6 +36,7 @@ type Filter = u32; type Flags = libc::c_ushort; #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -211,6 +213,7 @@ impl Selector { #[cfg(any( target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -237,6 +240,7 @@ impl Selector { #[cfg(any( target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -374,6 +378,7 @@ pub mod event { #[cfg(any( target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -387,6 +392,7 @@ pub mod event { #[cfg(not(any( target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -427,6 +433,7 @@ pub mod event { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -438,6 +445,7 @@ pub mod event { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -476,6 +484,7 @@ pub mod event { target_os = "freebsd", target_os = "dragonfly", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -487,6 +496,7 @@ pub mod event { target_os = "freebsd", target_os = "dragonfly", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -500,6 +510,7 @@ pub mod event { libc::EVFILT_EXCEPT, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -507,6 +518,7 @@ pub mod event { libc::EVFILT_MACHPORT, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -537,6 +549,7 @@ pub mod event { libc::EV_SYSFLAGS, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -544,6 +557,7 @@ pub mod event { libc::EV_FLAG0, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -551,6 +565,7 @@ pub mod event { libc::EV_POLL, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -571,6 +586,7 @@ pub mod event { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -580,6 +596,7 @@ pub mod event { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -589,6 +606,7 @@ pub mod event { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -598,6 +616,7 @@ pub mod event { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -607,6 +626,7 @@ pub mod event { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -616,6 +636,7 @@ pub mod event { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -625,6 +646,7 @@ pub mod event { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -639,6 +661,7 @@ pub mod event { libc::NOTE_EOF, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -650,6 +673,7 @@ pub mod event { libc::NOTE_REVOKE, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -662,6 +686,7 @@ pub mod event { libc::NOTE_EXEC, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -669,6 +694,7 @@ pub mod event { libc::NOTE_SIGNAL, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -676,6 +702,7 @@ pub mod event { libc::NOTE_EXITSTATUS, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -706,6 +733,7 @@ pub mod event { libc::NOTE_CHILD, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -713,6 +741,7 @@ pub mod event { libc::NOTE_EXIT_DETAIL_MASK, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -720,6 +749,7 @@ pub mod event { libc::NOTE_EXIT_DECRYPTFAIL, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -727,6 +757,7 @@ pub mod event { libc::NOTE_EXIT_MEMORY, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -734,6 +765,7 @@ pub mod event { libc::NOTE_EXIT_CSERROR, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -741,6 +773,7 @@ pub mod event { libc::NOTE_VM_PRESSURE, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -748,6 +781,7 @@ pub mod event { libc::NOTE_VM_PRESSURE_TERMINATE, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -755,6 +789,7 @@ pub mod event { libc::NOTE_VM_PRESSURE_SUDDEN_TERMINATE, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -763,6 +798,7 @@ pub mod event { #[cfg(any( target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -773,6 +809,7 @@ pub mod event { #[cfg(any( target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -781,6 +818,7 @@ pub mod event { #[cfg(any( target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -788,6 +826,7 @@ pub mod event { libc::NOTE_NSECONDS, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -795,6 +834,7 @@ pub mod event { libc::NOTE_ABSOLUTE, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -802,6 +842,7 @@ pub mod event { libc::NOTE_LEEWAY, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" @@ -809,6 +850,7 @@ pub mod event { libc::NOTE_CRITICAL, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos" diff --git a/src/sys/unix/selector/mod.rs b/src/sys/unix/selector/mod.rs index 619a7e529..293bb3ad8 100644 --- a/src/sys/unix/selector/mod.rs +++ b/src/sys/unix/selector/mod.rs @@ -47,6 +47,7 @@ cfg_io_source! { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "netbsd", target_os = "openbsd", @@ -62,6 +63,7 @@ mod kqueue; target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "netbsd", target_os = "openbsd", diff --git a/src/sys/unix/tcp.rs b/src/sys/unix/tcp.rs index a8d8d0b46..a60c775b6 100644 --- a/src/sys/unix/tcp.rs +++ b/src/sys/unix/tcp.rs @@ -88,6 +88,7 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, #[cfg(any( target_os = "aix", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "redox", target_os = "tvos", diff --git a/src/sys/unix/uds/listener.rs b/src/sys/unix/uds/listener.rs index b94243720..89c93d9bf 100644 --- a/src/sys/unix/uds/listener.rs +++ b/src/sys/unix/uds/listener.rs @@ -46,6 +46,7 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So #[cfg(not(any( target_os = "aix", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "netbsd", target_os = "redox", @@ -72,6 +73,7 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So #[cfg(any( target_os = "aix", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "netbsd", target_os = "redox", diff --git a/src/sys/unix/uds/mod.rs b/src/sys/unix/uds/mod.rs index 20367fd09..99b64c0be 100644 --- a/src/sys/unix/uds/mod.rs +++ b/src/sys/unix/uds/mod.rs @@ -77,6 +77,7 @@ cfg_os_poll! { #[cfg(not(any( target_os = "aix", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -101,6 +102,7 @@ cfg_os_poll! { #[cfg(any( target_os = "aix", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", diff --git a/src/sys/unix/waker.rs b/src/sys/unix/waker.rs index 0101ebeed..cc6a59fcd 100644 --- a/src/sys/unix/waker.rs +++ b/src/sys/unix/waker.rs @@ -5,6 +5,7 @@ any( target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -58,6 +59,7 @@ mod fdbased { any( target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -164,6 +166,7 @@ pub(crate) use self::eventfd::WakerInternal; any( target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -205,6 +208,7 @@ mod kqueue { any( target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", diff --git a/tests/interest.rs b/tests/interest.rs index f477d59c3..a0a7c5723 100644 --- a/tests/interest.rs +++ b/tests/interest.rs @@ -29,6 +29,7 @@ fn fmt_debug() { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", diff --git a/tests/tcp_stream.rs b/tests/tcp_stream.rs index b307a2ad6..9f6dbce1d 100644 --- a/tests/tcp_stream.rs +++ b/tests/tcp_stream.rs @@ -294,6 +294,7 @@ fn shutdown_read() { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "netbsd", target_os = "openbsd", @@ -384,6 +385,7 @@ fn shutdown_both() { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "netbsd", target_os = "openbsd", diff --git a/tests/unix_stream.rs b/tests/unix_stream.rs index 9098b7d17..5f8c9b232 100644 --- a/tests/unix_stream.rs +++ b/tests/unix_stream.rs @@ -227,6 +227,7 @@ fn unix_stream_shutdown_read() { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "netbsd", target_os = "openbsd", @@ -276,6 +277,7 @@ fn unix_stream_shutdown_write() { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "netbsd", target_os = "openbsd", @@ -342,6 +344,7 @@ fn unix_stream_shutdown_both() { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "iovisionos", target_os = "macos", target_os = "netbsd", target_os = "openbsd", diff --git a/tests/util/mod.rs b/tests/util/mod.rs index 7a192d9b0..76c8df733 100644 --- a/tests/util/mod.rs +++ b/tests/util/mod.rs @@ -251,6 +251,7 @@ pub fn set_linger_zero(socket: &TcpStream) { libc::SOL_SOCKET, #[cfg(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", @@ -258,6 +259,7 @@ pub fn set_linger_zero(socket: &TcpStream) { libc::SO_LINGER_SEC, #[cfg(not(any( target_os = "ios", + target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos",