diff --git a/Cargo.toml b/Cargo.toml index 18579fcf4..b952d6706 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,11 +45,11 @@ libc = { version = "0.2.171", default-features = false, optional = true } libc_errno = { package = "errno", version = "0.3.10", default-features = false } libc = { version = "0.2.171", default-features = false } -# Additional dependencies for Linux with the libc backend: +# Additional dependencies for Linux and Android with the libc backend: # # Some syscalls do not have libc wrappers, such as in `io_uring`. For these, # the libc backend uses the linux-raw-sys ABI and `libc::syscall`. -[target.'cfg(all(any(target_os = "linux"), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies] +[target.'cfg(all(any(target_os = "linux", target_os = "android"), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies] linux-raw-sys = { version = "0.11.0", default-features = false, features = ["general", "ioctl", "no_std"] } # For the libc backend on Windows, use the Winsock API in windows-sys. diff --git a/build.rs b/build.rs index 155141952..76002fc11 100644 --- a/build.rs +++ b/build.rs @@ -116,7 +116,7 @@ fn main() { || arch.starts_with("mips")) && !rustix_use_experimental_asm); if libc { - if os != "android" && os == "linux" && !cfg_no_linux_raw { + if (os == "linux" || os == "android") && !cfg_no_linux_raw { use_feature("linux_raw_dep"); } diff --git a/src/backend/libc/c.rs b/src/backend/libc/c.rs index 7e7fd75f3..3f3652360 100644 --- a/src/backend/libc/c.rs +++ b/src/backend/libc/c.rs @@ -516,6 +516,7 @@ mod statx_flags { linux_like, linux_raw_dep, not(any( + target_os = "android", target_os = "emscripten", target_env = "gnu", all(target_arch = "loongarch64", target_env = "musl") diff --git a/src/backend/libc/mod.rs b/src/backend/libc/mod.rs index ca8afbb30..b4fd3ef46 100644 --- a/src/backend/libc/mod.rs +++ b/src/backend/libc/mod.rs @@ -109,7 +109,7 @@ pub(crate) mod event; #[cfg(feature = "fs")] pub(crate) mod fs; pub(crate) mod io; -#[cfg(linux_kernel)] +#[cfg(all(linux_kernel, not(target_os = "android")))] #[cfg(feature = "io_uring")] pub(crate) mod io_uring; #[cfg(not(any( diff --git a/src/backend/libc/net/sockopt.rs b/src/backend/libc/net/sockopt.rs index 2320255d7..0a8541461 100644 --- a/src/backend/libc/net/sockopt.rs +++ b/src/backend/libc/net/sockopt.rs @@ -82,7 +82,7 @@ use c::TCP_KEEPALIVE as TCP_KEEPIDLE; use c::TCP_KEEPIDLE; use core::mem::{size_of, MaybeUninit}; use core::time::Duration; -#[cfg(linux_raw_dep)] +#[cfg(all(linux_raw_dep, target_os = "linux"))] use linux_raw_sys::xdp::{xdp_mmap_offsets, xdp_statistics, xdp_statistics_v1}; #[inline] @@ -1153,7 +1153,7 @@ pub(crate) fn set_xdp_rx_ring_size(fd: BorrowedFd<'_>, value: u32) -> io::Result setsockopt(fd, c::SOL_XDP, c::XDP_RX_RING, value) } -#[cfg(linux_raw_dep)] +#[cfg(all(linux_raw_dep, target_os = "linux"))] #[inline] pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result { // The kernel will write `xdp_mmap_offsets` or `xdp_mmap_offsets_v1` to the @@ -1240,7 +1240,7 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result } } -#[cfg(linux_raw_dep)] +#[cfg(all(linux_raw_dep, target_os = "linux"))] #[inline] pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result { let mut optlen = size_of::().try_into().unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 77f8a2158..e764201b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -224,7 +224,7 @@ pub mod ffi; #[cfg_attr(docsrs, doc(cfg(feature = "fs")))] pub mod fs; pub mod io; -#[cfg(linux_kernel)] +#[cfg(all(linux_kernel, not(target_os = "android")))] #[cfg(feature = "io_uring")] #[cfg_attr(docsrs, doc(cfg(feature = "io_uring")))] pub mod io_uring; diff --git a/src/net/sockopt.rs b/src/net/sockopt.rs index a3f3ed59d..796a114be 100644 --- a/src/net/sockopt.rs +++ b/src/net/sockopt.rs @@ -1774,7 +1774,7 @@ pub fn set_xdp_rx_ring_size(fd: Fd, value: u32) -> io::Result<()> { /// - [Linux] /// /// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html -#[cfg(linux_raw_dep)] +#[cfg(all(linux_raw_dep, target_os = "linux"))] #[doc(alias = "XDP_MMAP_OFFSETS")] pub fn xdp_mmap_offsets(fd: Fd) -> io::Result { backend::net::sockopt::xdp_mmap_offsets(fd.as_fd()) @@ -1786,7 +1786,7 @@ pub fn xdp_mmap_offsets(fd: Fd) -> io::Result { /// - [Linux] /// /// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-statistics-getsockopt -#[cfg(linux_raw_dep)] +#[cfg(all(linux_raw_dep, target_os = "linux"))] #[doc(alias = "XDP_STATISTICS")] pub fn xdp_statistics(fd: Fd) -> io::Result { backend::net::sockopt::xdp_statistics(fd.as_fd()) diff --git a/tests/io/read_write.rs b/tests/io/read_write.rs index 04ebc9e78..be3b047d5 100644 --- a/tests/io/read_write.rs +++ b/tests/io/read_write.rs @@ -202,7 +202,7 @@ fn test_rwf_values() { ); } -#[cfg(linux_raw_dep)] +#[cfg(all(linux_raw_dep, not(target_os = "android")))] #[cfg(feature = "fs")] #[test] fn test_pwritev2() { @@ -256,7 +256,7 @@ fn test_pwritev2() { assert_eq!(&buf, b"world"); } -#[cfg(linux_raw_dep)] +#[cfg(all(linux_raw_dep, not(target_os = "android")))] #[cfg(all(feature = "net", feature = "pipe"))] #[test] fn test_preadv2_nowait() { @@ -308,7 +308,7 @@ fn test_preadv2_nowait() { fn test_p_offsets() { use rustix::fs::{openat, Mode, OFlags, CWD}; use rustix::io::{pread, preadv, pwrite, pwritev}; - #[cfg(linux_raw_dep)] + #[cfg(all(linux_raw_dep, not(target_os = "android")))] use rustix::io::{preadv2, pwritev2, ReadWriteFlags}; let mut buf = [0_u8; 5]; @@ -343,7 +343,7 @@ fn test_p_offsets() { Ok(_) => {} Err(e) => panic!("pwritev failed with an unexpected error: {:?}", e), } - #[cfg(linux_raw_dep)] + #[cfg(all(linux_raw_dep, not(target_os = "android")))] { match preadv2( &f, @@ -393,7 +393,7 @@ fn test_p_offsets() { Err(e) => panic!("pwritev failed with an unexpected error: {:?}", e), } } - #[cfg(linux_raw_dep)] + #[cfg(all(linux_raw_dep, not(target_os = "android")))] { match preadv2( &f,