From b4323cbc5078de82917c00a3bae2c166e61d8995 Mon Sep 17 00:00:00 2001 From: Gurchetan Singh Date: Fri, 20 Jun 2025 11:12:03 -0700 Subject: [PATCH] rustix: on Android, support a build without linux-raw-sys Rustix support was added to Mesa3D recently, but it only works with the linux-raw-sys backend. On Linux, even the libc backend, there is a dependency on linux-raw-sys for certain ABI definitions. When updating rustix in Android to support this, I realized only the libc backend is supported in Android. This is because Android as a platform wants to discourage raw syscalls, and to be able to globally update libc. Features like fdtrack would not work with the linux-raw-sys backend: https://android.googlesource.com/platform/bionic/+/HEAD/docs/fdtrack.md Given Android wants to incentize use of libc only, this MR introduces the concept of "linux-raw-dep". This means that linux-raw-sys is present as a dependency for the user. This will be on by default even for the libc backend, but will be turned off for Android (this is reflected in the build.rs script). This will also help others who don't need all the features rustix offers on Linux, so they have one less dependency to maintain. They may append "--cfg=rustix_no_linux_raw" to Rust flags skip building the linux raw backend. Mesa3D will use this. Tested via: cargo build --target arm-linux-androideabi --features=use-libc,net,std,alloc,event,fs,mm,param,pipe,use-libc-auxv,libc_errno and on Linux with the proper RUSTFLAGS set. The Github workflows have been modified to only use the current subset of features using in AOSP: https://android.googlesource.com/platform/external/rust/android-crates-io/+/refs/heads/main/crates/rustix/Android.bp That is the source of truth for an Android integration and the CI only needs to test that. Additional features may be added as needed in the future. --- Cargo.toml | 3 +- build.rs | 9 ++++++ src/backend/libc/c.rs | 50 +++++++++++++++------------------ src/backend/libc/fs/mod.rs | 7 +++-- src/backend/libc/fs/syscalls.rs | 6 ++-- src/backend/libc/io/syscalls.rs | 6 ++-- src/backend/libc/io/types.rs | 12 ++++---- src/backend/libc/mm/types.rs | 12 ++++---- src/backend/libc/net/sockopt.rs | 6 ++-- src/fs/constants.rs | 6 ++-- src/fs/ioctl.rs | 8 +++--- src/fs/mod.rs | 6 ++-- src/fs/raw_dir.rs | 4 +++ src/io/read_write.rs | 6 ++-- src/ioctl/linux.rs | 4 +-- src/ioctl/mod.rs | 2 +- src/net/sockopt.rs | 4 +-- src/net/types.rs | 48 +++++++++++++++---------------- src/timespec.rs | 2 +- 25 files changed, 130 insertions(+), 108 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1b21e365..f7645bdc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -197,7 +197,7 @@ libc = { version = "0.2.168", default-features = false } [dev-dependencies.tempfile] version = "3.5.0" -[target.'cfg(all(any(target_os = "android", 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.linux-raw-sys] +[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.linux-raw-sys] version = "0.9.2" features = [ "general", @@ -276,6 +276,7 @@ check-cfg = [ "cfg(linux_kernel)", "cfg(linux_like)", "cfg(linux_raw)", + "cfg(linux_raw_dep)", "cfg(netbsdlike)", "cfg(rustc_attrs)", "cfg(solarish)", diff --git a/build.rs b/build.rs index 6a69dc4a..63bb2bd3 100644 --- a/build.rs +++ b/build.rs @@ -35,6 +35,10 @@ fn main() { // enable the libc backend even if rustix is depended on transitively. let cfg_use_libc = var("CARGO_CFG_RUSTIX_USE_LIBC").is_ok(); + // Check for `RUSTFLAGS=--cfg=rustix_no_linux_raw`. This allows Linux users to + // enable the libc backend without the linux raw dependency. + let cfg_no_linux_raw = var("CARGO_CFG_RUSTIX_NO_LINUX_RAW").is_ok(); + // Check for `--features=rustc-dep-of-std`. let rustc_dep_of_std = var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok(); @@ -103,10 +107,15 @@ fn main() { || arch.starts_with("mips")) && !rustix_use_experimental_asm); if libc { + if os != "android" && os == "linux" && !cfg_no_linux_raw { + use_feature("linux_raw_dep"); + } + // Use the libc backend. use_feature("libc"); } else { // Use the linux_raw backend. + use_feature("linux_raw_dep"); use_feature("linux_raw"); if rustix_use_experimental_asm { use_feature("asm_experimental_arch"); diff --git a/src/backend/libc/c.rs b/src/backend/libc/c.rs index 2f737c21..cc789794 100644 --- a/src/backend/libc/c.rs +++ b/src/backend/libc/c.rs @@ -19,49 +19,49 @@ pub(crate) const NFS_SUPER_MAGIC: u32 = 0x0000_6969; pub(crate) const EXIT_SIGNALED_SIGABRT: c_int = 128 + SIGABRT as c_int; // TODO: Upstream these. -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_TSN: c_int = linux_raw_sys::if_ether::ETH_P_TSN as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_ERSPAN2: c_int = linux_raw_sys::if_ether::ETH_P_ERSPAN2 as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_ERSPAN: c_int = linux_raw_sys::if_ether::ETH_P_ERSPAN as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_PROFINET: c_int = linux_raw_sys::if_ether::ETH_P_PROFINET as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_REALTEK: c_int = linux_raw_sys::if_ether::ETH_P_REALTEK as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_ETHERCAT: c_int = linux_raw_sys::if_ether::ETH_P_ETHERCAT as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_PREAUTH: c_int = linux_raw_sys::if_ether::ETH_P_PREAUTH as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_LLDP: c_int = linux_raw_sys::if_ether::ETH_P_LLDP as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_MRP: c_int = linux_raw_sys::if_ether::ETH_P_MRP as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_NCSI: c_int = linux_raw_sys::if_ether::ETH_P_NCSI as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_CFM: c_int = linux_raw_sys::if_ether::ETH_P_CFM as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_IBOE: c_int = linux_raw_sys::if_ether::ETH_P_IBOE as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_HSR: c_int = linux_raw_sys::if_ether::ETH_P_HSR as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_NSH: c_int = linux_raw_sys::if_ether::ETH_P_NSH as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_DSA_8021Q: c_int = linux_raw_sys::if_ether::ETH_P_DSA_8021Q as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_DSA_A5PSW: c_int = linux_raw_sys::if_ether::ETH_P_DSA_A5PSW as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_IFE: c_int = linux_raw_sys::if_ether::ETH_P_IFE as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_CAN: c_int = linux_raw_sys::if_ether::ETH_P_CAN as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_CANXL: c_int = linux_raw_sys::if_ether::ETH_P_CANXL as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_XDSA: c_int = linux_raw_sys::if_ether::ETH_P_XDSA as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_MAP: c_int = linux_raw_sys::if_ether::ETH_P_MAP as _; -#[cfg(all(linux_kernel, feature = "net"))] +#[cfg(all(linux_raw_dep, feature = "net"))] pub(crate) const ETH_P_MCTP: c_int = linux_raw_sys::if_ether::ETH_P_MCTP as _; #[cfg(all( @@ -89,7 +89,7 @@ pub(crate) const MSG_DONTWAIT: c_int = MSG_NONBLOCK; // `O_LARGEFILE` can be automatically set by the kernel on Linux: // // so libc implementations may leave it undefined or defined to zero. -#[cfg(linux_kernel)] +#[cfg(linux_raw_dep)] pub(crate) const O_LARGEFILE: c_int = linux_raw_sys::general::O_LARGEFILE as _; // Gated under `_LARGEFILE_SOURCE` but automatically set by the kernel. @@ -515,10 +515,6 @@ pub(crate) use statx_flags::*; #[cfg(target_os = "android")] pub(crate) use __fsid_t as fsid_t; -#[cfg(feature = "mm")] -#[cfg(target_os = "android")] -pub(crate) const MAP_DROPPABLE: c_int = bitcast!(linux_raw_sys::general::MAP_DROPPABLE); - #[cfg(test)] mod tests { use super::*; diff --git a/src/backend/libc/fs/mod.rs b/src/backend/libc/fs/mod.rs index 264b955c..f75c6fb7 100644 --- a/src/backend/libc/fs/mod.rs +++ b/src/backend/libc/fs/mod.rs @@ -16,9 +16,12 @@ pub(crate) mod syscalls; pub(crate) mod types; // TODO: Fix linux-raw-sys to define ioctl codes for sparc. -#[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))] +#[cfg(all(linux_raw_dep, any(target_arch = "sparc", target_arch = "sparc64")))] pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::Opcode = 0x8008_6610; -#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] +#[cfg(all( + linux_raw_dep, + not(any(target_arch = "sparc", target_arch = "sparc64")) +))] pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::Opcode = linux_raw_sys::ioctl::EXT4_IOC_RESIZE_FS as crate::ioctl::Opcode; diff --git a/src/backend/libc/fs/syscalls.rs b/src/backend/libc/fs/syscalls.rs index cb7cc32e..7de8ffb0 100644 --- a/src/backend/libc/fs/syscalls.rs +++ b/src/backend/libc/fs/syscalls.rs @@ -1837,7 +1837,7 @@ pub(crate) fn memfd_create(name: &CStr, flags: MemfdFlags) -> io::Result, path: &CStr, @@ -2050,9 +2050,9 @@ pub(crate) fn statx( // doesn't represent all the known flags. // // [it's deprecated]: https://patchwork.kernel.org/project/linux-fsdevel/patch/20200505095915.11275-7-mszeredi@redhat.com/ - #[cfg(not(any(target_os = "android", target_env = "musl")))] + #[cfg(not(target_env = "musl"))] const STATX__RESERVED: u32 = c::STATX__RESERVED as u32; - #[cfg(any(target_os = "android", target_env = "musl"))] + #[cfg(target_env = "musl")] const STATX__RESERVED: u32 = linux_raw_sys::general::STATX__RESERVED; if (mask.bits() & STATX__RESERVED) == STATX__RESERVED { return Err(io::Errno::INVAL); diff --git a/src/backend/libc/io/syscalls.rs b/src/backend/libc/io/syscalls.rs index 7ade984d..ae96b167 100644 --- a/src/backend/libc/io/syscalls.rs +++ b/src/backend/libc/io/syscalls.rs @@ -13,7 +13,7 @@ use crate::fd::{AsFd as _, BorrowedFd, OwnedFd, RawFd}; target_os = "wasi" )))] use crate::io::DupFlags; -#[cfg(linux_kernel)] +#[cfg(all(linux_kernel, not(target_os = "android")))] use crate::io::ReadWriteFlags; use crate::io::{self, FdFlags}; use crate::ioctl::{IoctlOutput, Opcode}; @@ -142,7 +142,7 @@ pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>], offset: u64) -> } } -#[cfg(linux_kernel)] +#[cfg(all(linux_kernel, not(target_os = "android")))] pub(crate) fn preadv2( fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut<'_>], @@ -162,7 +162,7 @@ pub(crate) fn preadv2( } } -#[cfg(linux_kernel)] +#[cfg(all(linux_kernel, not(target_os = "android")))] pub(crate) fn pwritev2( fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>], diff --git a/src/backend/libc/io/types.rs b/src/backend/libc/io/types.rs index 510206f9..b434b68a 100644 --- a/src/backend/libc/io/types.rs +++ b/src/backend/libc/io/types.rs @@ -17,7 +17,7 @@ bitflags! { } } -#[cfg(linux_kernel)] +#[cfg(all(linux_kernel, not(target_os = "android")))] bitflags! { /// `RWF_*` constants for use with [`preadv2`] and [`pwritev2`]. /// @@ -27,15 +27,15 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct ReadWriteFlags: u32 { /// `RWF_DSYNC` (since Linux 4.7) - const DSYNC = linux_raw_sys::general::RWF_DSYNC; + const DSYNC = libc::RWF_DSYNC as u32; /// `RWF_HIPRI` (since Linux 4.6) - const HIPRI = linux_raw_sys::general::RWF_HIPRI; + const HIPRI = libc::RWF_HIPRI as u32; /// `RWF_SYNC` (since Linux 4.7) - const SYNC = linux_raw_sys::general::RWF_SYNC; + const SYNC = libc::RWF_SYNC as u32; /// `RWF_NOWAIT` (since Linux 4.14) - const NOWAIT = linux_raw_sys::general::RWF_NOWAIT; + const NOWAIT = libc::RWF_NOWAIT as u32; /// `RWF_APPEND` (since Linux 4.16) - const APPEND = linux_raw_sys::general::RWF_APPEND; + const APPEND = libc::RWF_APPEND as u32; /// const _ = !0; diff --git a/src/backend/libc/mm/types.rs b/src/backend/libc/mm/types.rs index c25b8d09..fdca08dc 100644 --- a/src/backend/libc/mm/types.rs +++ b/src/backend/libc/mm/types.rs @@ -44,19 +44,19 @@ bitflags! { #[cfg(linux_kernel)] const GROWSDOWN = bitcast!(c::PROT_GROWSDOWN); /// `PROT_SEM` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] const SEM = linux_raw_sys::general::PROT_SEM; /// `PROT_BTI` - #[cfg(all(linux_kernel, target_arch = "aarch64"))] + #[cfg(all(linux_raw_dep, target_arch = "aarch64"))] const BTI = linux_raw_sys::general::PROT_BTI; /// `PROT_MTE` - #[cfg(all(linux_kernel, target_arch = "aarch64"))] + #[cfg(all(linux_raw_dep, target_arch = "aarch64"))] const MTE = linux_raw_sys::general::PROT_MTE; /// `PROT_SAO` - #[cfg(all(linux_kernel, any(target_arch = "powerpc", target_arch = "powerpc64")))] + #[cfg(all(linux_raw_dep, any(target_arch = "powerpc", target_arch = "powerpc64")))] const SAO = linux_raw_sys::general::PROT_SAO; /// `PROT_ADI` - #[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))] + #[cfg(all(linux_raw_dep, any(target_arch = "sparc", target_arch = "sparc64")))] const ADI = linux_raw_sys::general::PROT_ADI; /// @@ -241,7 +241,7 @@ bitflags! { #[cfg(any())] const UNINITIALIZED = bitcast!(c::MAP_UNINITIALIZED); /// `MAP_DROPPABLE` - #[cfg(linux_kernel)] + #[cfg(all(linux_kernel, not(target_os = "android")))] const DROPPABLE = bitcast!(c::MAP_DROPPABLE); /// diff --git a/src/backend/libc/net/sockopt.rs b/src/backend/libc/net/sockopt.rs index 1251c7f7..151d26c8 100644 --- a/src/backend/libc/net/sockopt.rs +++ b/src/backend/libc/net/sockopt.rs @@ -75,7 +75,7 @@ use c::TCP_KEEPALIVE as TCP_KEEPIDLE; use c::TCP_KEEPIDLE; use core::mem::{size_of, MaybeUninit}; use core::time::Duration; -#[cfg(target_os = "linux")] +#[cfg(linux_raw_dep)] use linux_raw_sys::xdp::{xdp_mmap_offsets, xdp_statistics, xdp_statistics_v1}; #[cfg(windows)] use windows_sys::Win32::Foundation::BOOL; @@ -1076,7 +1076,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(target_os = "linux")] +#[cfg(linux_raw_dep)] #[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 @@ -1163,7 +1163,7 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result } } -#[cfg(target_os = "linux")] +#[cfg(linux_raw_dep)] #[inline] pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result { let mut optlen = size_of::().try_into().unwrap(); diff --git a/src/fs/constants.rs b/src/fs/constants.rs index d5c3821f..71860a01 100644 --- a/src/fs/constants.rs +++ b/src/fs/constants.rs @@ -56,12 +56,12 @@ mod tests { #[test] fn test_layouts() { - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] assert_eq_size!(FsWord, linux_raw_sys::general::__fsword_t); // Don't test against `__kernel_mode_t` on platforms where it's a // `u16`. - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] #[cfg(not(any( target_arch = "x86", target_arch = "sparc", @@ -70,7 +70,7 @@ mod tests { )))] assert_eq_size!(RawMode, linux_raw_sys::general::__kernel_mode_t); - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] #[cfg(any( target_arch = "x86", target_arch = "sparc", diff --git a/src/fs/ioctl.rs b/src/fs/ioctl.rs index c126fdd1..16e0dda1 100644 --- a/src/fs/ioctl.rs +++ b/src/fs/ioctl.rs @@ -58,7 +58,7 @@ pub fn ioctl_ficlone(fd: Fd, src_fd: SrcFd) -> io::Result } /// `ioctl(fd, EXT4_IOC_RESIZE_FS, blocks)`—Resize ext4 filesystem on fd. -#[cfg(linux_kernel)] +#[cfg(linux_raw_dep)] #[inline] #[doc(alias = "EXT4_IOC_RESIZE_FS")] pub fn ext4_ioc_resize_fs(fd: Fd, blocks: u64) -> io::Result<()> { @@ -94,7 +94,7 @@ unsafe impl ioctl::Ioctl for Ficlone<'_> { } } -#[cfg(linux_kernel)] +#[cfg(linux_raw_dep)] bitflags! { /// `FS_*` constants for use with [`ioctl_getflags`]. /// @@ -136,7 +136,7 @@ bitflags! { /// `ioctl(fd, FS_IOC_GETFLAGS)`—Returns the [inode flags] attributes /// /// [inode flags]: https://man7.org/linux/man-pages/man2/ioctl_iflags.2.html -#[cfg(linux_kernel)] +#[cfg(linux_raw_dep)] #[inline] #[doc(alias = "FS_IOC_GETFLAGS")] pub fn ioctl_getflags(fd: Fd) -> io::Result { @@ -153,7 +153,7 @@ pub fn ioctl_getflags(fd: Fd) -> io::Result { /// `ioctl(fd, FS_IOC_SETFLAGS)`—Modify the [inode flags] attributes /// /// [inode flags]: https://man7.org/linux/man-pages/man2/ioctl_iflags.2.html -#[cfg(linux_kernel)] +#[cfg(linux_raw_dep)] #[inline] #[doc(alias = "FS_IOC_SETFLAGS")] pub fn ioctl_setflags(fd: Fd, flags: IFlags) -> io::Result<()> { diff --git a/src/fs/mod.rs b/src/fs/mod.rs index dfc431e0..7107e417 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -30,7 +30,7 @@ pub(crate) mod fd; mod getpath; #[cfg(not(target_os = "wasi"))] // WASI doesn't have get[gpu]id. mod id; -#[cfg(linux_kernel)] +#[cfg(linux_raw_dep)] pub mod inotify; #[cfg(linux_kernel)] mod ioctl; @@ -45,7 +45,7 @@ mod ioctl; mod makedev; #[cfg(any(linux_kernel, target_os = "freebsd"))] mod memfd_create; -#[cfg(linux_kernel)] +#[cfg(linux_raw_dep)] mod openat2; #[cfg(linux_kernel)] mod raw_dir; @@ -110,7 +110,7 @@ pub use ioctl::*; pub use makedev::*; #[cfg(any(linux_kernel, target_os = "freebsd"))] pub use memfd_create::memfd_create; -#[cfg(linux_kernel)] +#[cfg(linux_raw_dep)] pub use openat2::openat2; #[cfg(linux_kernel)] pub use raw_dir::{RawDir, RawDirEntry}; diff --git a/src/fs/raw_dir.rs b/src/fs/raw_dir.rs index 7fec6fd7..9691ca71 100644 --- a/src/fs/raw_dir.rs +++ b/src/fs/raw_dir.rs @@ -7,6 +7,10 @@ use crate::fs::FileType; use crate::io; use core::fmt; use core::mem::{align_of, MaybeUninit}; + +#[cfg(not(linux_raw_dep))] +use libc::dirent64 as linux_dirent64; +#[cfg(linux_raw_dep)] use linux_raw_sys::general::linux_dirent64; /// A directory iterator implemented with getdents. diff --git a/src/io/read_write.rs b/src/io/read_write.rs index ba5dd291..b5097a83 100644 --- a/src/io/read_write.rs +++ b/src/io/read_write.rs @@ -10,7 +10,7 @@ use backend::fd::AsFd; #[cfg(not(windows))] pub use crate::maybe_polyfill::io::{IoSlice, IoSliceMut}; -#[cfg(linux_kernel)] +#[cfg(all(linux_kernel, not(target_os = "android")))] pub use backend::io::types::ReadWriteFlags; /// `read(fd, buf)`—Reads from a stream. @@ -275,7 +275,7 @@ pub fn pwritev(fd: Fd, bufs: &[IoSlice<'_>], offset: u64) -> io::Resul /// /// [Linux]: https://man7.org/linux/man-pages/man2/preadv2.2.html /// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Scatter_002dGather.html#index-preadv64v2 -#[cfg(linux_kernel)] +#[cfg(all(linux_kernel, not(target_os = "android")))] #[inline] pub fn preadv2( fd: Fd, @@ -296,7 +296,7 @@ pub fn preadv2( /// /// [Linux]: https://man7.org/linux/man-pages/man2/pwritev2.2.html /// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Scatter_002dGather.html#index-pwritev64v2 -#[cfg(linux_kernel)] +#[cfg(all(linux_kernel, not(target_os = "android")))] #[inline] pub fn pwritev2( fd: Fd, diff --git a/src/ioctl/linux.rs b/src/ioctl/linux.rs index 7215228a..8d96a1b2 100644 --- a/src/ioctl/linux.rs +++ b/src/ioctl/linux.rs @@ -88,12 +88,12 @@ mod tests { #[allow(unused_imports)] use super::*; - #[cfg(not(any( + #[cfg(all(linux_raw_dep, not(any( // These have no ioctl opcodes defined in linux_raw_sys so we can't use // that as a known-good value for this test. target_arch = "sparc", target_arch = "sparc64" -)))] +))))] #[test] fn check_known_opcodes() { use crate::backend::c::{c_long, c_uint}; diff --git a/src/ioctl/mod.rs b/src/ioctl/mod.rs index 0a9d7a86..8fded0bc 100644 --- a/src/ioctl/mod.rs +++ b/src/ioctl/mod.rs @@ -343,7 +343,7 @@ type _Opcode = c::c_uint; #[cfg(windows)] type _Opcode = i32; -#[cfg(linux_kernel)] +#[cfg(linux_raw_dep)] #[cfg(not(any(target_arch = "sparc", target_arch = "sparc64")))] #[cfg(test)] mod tests { diff --git a/src/net/sockopt.rs b/src/net/sockopt.rs index 20ed3e72..c6603b59 100644 --- a/src/net/sockopt.rs +++ b/src/net/sockopt.rs @@ -1590,7 +1590,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(target_os = "linux")] +#[cfg(linux_raw_dep)] #[doc(alias = "XDP_MMAP_OFFSETS")] pub fn xdp_mmap_offsets(fd: Fd) -> io::Result { backend::net::sockopt::xdp_mmap_offsets(fd.as_fd()) @@ -1602,7 +1602,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(target_os = "linux")] +#[cfg(linux_raw_dep)] #[doc(alias = "XDP_STATISTICS")] pub fn xdp_statistics(fd: Fd) -> io::Result { backend::net::sockopt::xdp_statistics(fd.as_fd()) diff --git a/src/net/types.rs b/src/net/types.rs index 660c4088..4ed8c8ee 100644 --- a/src/net/types.rs +++ b/src/net/types.rs @@ -1279,10 +1279,10 @@ pub mod eth { #[cfg(linux_kernel)] pub const PUPAT: Protocol = Protocol(new_raw_protocol((c::ETH_P_PUPAT as u16).to_be() as u32)); /// `ETH_P_TSN` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const TSN: Protocol = Protocol(new_raw_protocol((c::ETH_P_TSN as u16).to_be() as u32)); /// `ETH_P_ERSPAN2` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const ERSPAN2: Protocol = Protocol(new_raw_protocol((c::ETH_P_ERSPAN2 as u16).to_be() as u32)); /// `ETH_P_IP` @@ -1353,7 +1353,7 @@ pub mod eth { pub const P_8021Q: Protocol = Protocol(new_raw_protocol((c::ETH_P_8021Q as u16).to_be() as u32)); /// `ETH_P_ERSPAN` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const ERSPAN: Protocol = Protocol(new_raw_protocol((c::ETH_P_ERSPAN as u16).to_be() as u32)); /// `ETH_P_IPX` @@ -1403,18 +1403,18 @@ pub mod eth { #[cfg(linux_kernel)] pub const PAE: Protocol = Protocol(new_raw_protocol((c::ETH_P_PAE as u16).to_be() as u32)); /// `ETH_P_PROFINET` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const PROFINET: Protocol = Protocol(new_raw_protocol((c::ETH_P_PROFINET as u16).to_be() as u32)); /// `ETH_P_REALTEK` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const REALTEK: Protocol = Protocol(new_raw_protocol((c::ETH_P_REALTEK as u16).to_be() as u32)); /// `ETH_P_AOE` #[cfg(linux_kernel)] pub const AOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_AOE as u16).to_be() as u32)); /// `ETH_P_ETHERCAT` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const ETHERCAT: Protocol = Protocol(new_raw_protocol((c::ETH_P_ETHERCAT as u16).to_be() as u32)); /// `ETH_P_8021AD` @@ -1426,17 +1426,17 @@ pub mod eth { pub const P_802_EX1: Protocol = Protocol(new_raw_protocol((c::ETH_P_802_EX1 as u16).to_be() as u32)); /// `ETH_P_PREAUTH` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const PREAUTH: Protocol = Protocol(new_raw_protocol((c::ETH_P_PREAUTH as u16).to_be() as u32)); /// `ETH_P_TIPC` #[cfg(linux_kernel)] pub const TIPC: Protocol = Protocol(new_raw_protocol((c::ETH_P_TIPC as u16).to_be() as u32)); /// `ETH_P_LLDP` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const LLDP: Protocol = Protocol(new_raw_protocol((c::ETH_P_LLDP as u16).to_be() as u32)); /// `ETH_P_MRP` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const MRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MRP as u16).to_be() as u32)); /// `ETH_P_MACSEC` #[cfg(linux_kernel)] @@ -1453,19 +1453,19 @@ pub mod eth { #[cfg(linux_kernel)] pub const P_1588: Protocol = Protocol(new_raw_protocol((c::ETH_P_1588 as u16).to_be() as u32)); /// `ETH_P_NCSI` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const NCSI: Protocol = Protocol(new_raw_protocol((c::ETH_P_NCSI as u16).to_be() as u32)); /// `ETH_P_PRP` #[cfg(linux_kernel)] pub const PRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_PRP as u16).to_be() as u32)); /// `ETH_P_CFM` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const CFM: Protocol = Protocol(new_raw_protocol((c::ETH_P_CFM as u16).to_be() as u32)); /// `ETH_P_FCOE` #[cfg(linux_kernel)] pub const FCOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_FCOE as u16).to_be() as u32)); /// `ETH_P_IBOE` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const IBOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_IBOE as u16).to_be() as u32)); /// `ETH_P_TDLS` #[cfg(linux_kernel)] @@ -1478,10 +1478,10 @@ pub mod eth { pub const P_80221: Protocol = Protocol(new_raw_protocol((c::ETH_P_80221 as u16).to_be() as u32)); /// `ETH_P_HSR` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const HSR: Protocol = Protocol(new_raw_protocol((c::ETH_P_HSR as u16).to_be() as u32)); /// `ETH_P_NSH` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const NSH: Protocol = Protocol(new_raw_protocol((c::ETH_P_NSH as u16).to_be() as u32)); /// `ETH_P_LOOPBACK` #[cfg(linux_kernel)] @@ -1500,15 +1500,15 @@ pub mod eth { #[cfg(linux_kernel)] pub const EDSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_EDSA as u16).to_be() as u32)); /// `ETH_P_DSA_8021Q` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const DSA_8021Q: Protocol = Protocol(new_raw_protocol((c::ETH_P_DSA_8021Q as u16).to_be() as u32)); /// `ETH_P_DSA_A5PSW` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const DSA_A5PSW: Protocol = Protocol(new_raw_protocol((c::ETH_P_DSA_A5PSW as u16).to_be() as u32)); /// `ETH_P_IFE` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const IFE: Protocol = Protocol(new_raw_protocol((c::ETH_P_IFE as u16).to_be() as u32)); /// `ETH_P_AF_IUCV` #[cfg(linux_kernel)] @@ -1526,7 +1526,7 @@ pub mod eth { #[cfg(linux_kernel)] pub const AX25: Protocol = Protocol(new_raw_protocol((c::ETH_P_AX25 as u16).to_be() as u32)); /// `ETH_P_ALL` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const ALL: Protocol = Protocol(new_raw_protocol((c::ETH_P_ALL as u16).to_be() as u32)); /// `ETH_P_802_2` #[cfg(linux_kernel)] @@ -1551,13 +1551,13 @@ pub mod eth { pub const LOCALTALK: Protocol = Protocol(new_raw_protocol((c::ETH_P_LOCALTALK as u16).to_be() as u32)); /// `ETH_P_CAN` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const CAN: Protocol = Protocol(new_raw_protocol((c::ETH_P_CAN as u16).to_be() as u32)); /// `ETH_P_CANFD` #[cfg(linux_kernel)] pub const CANFD: Protocol = Protocol(new_raw_protocol((c::ETH_P_CANFD as u16).to_be() as u32)); /// `ETH_P_CANXL` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const CANXL: Protocol = Protocol(new_raw_protocol((c::ETH_P_CANXL as u16).to_be() as u32)); /// `ETH_P_PPPTALK` #[cfg(linux_kernel)] @@ -1590,7 +1590,7 @@ pub mod eth { pub const ARCNET: Protocol = Protocol(new_raw_protocol((c::ETH_P_ARCNET as u16).to_be() as u32)); /// `ETH_P_DSA` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const DSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_DSA as u16).to_be() as u32)); /// `ETH_P_TRAILER` #[cfg(linux_kernel)] @@ -1608,13 +1608,13 @@ pub mod eth { #[cfg(linux_kernel)] pub const CAIF: Protocol = Protocol(new_raw_protocol((c::ETH_P_CAIF as u16).to_be() as u32)); /// `ETH_P_XDSA` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const XDSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_XDSA as u16).to_be() as u32)); /// `ETH_P_MAP` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const MAP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MAP as u16).to_be() as u32)); /// `ETH_P_MCTP` - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] pub const MCTP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MCTP as u16).to_be() as u32)); } diff --git a/src/timespec.rs b/src/timespec.rs index 7deb5e44..669f4494 100644 --- a/src/timespec.rs +++ b/src/timespec.rs @@ -411,7 +411,7 @@ mod tests { } // Test that `Timespec` matches Linux's `__kernel_timespec`. - #[cfg(linux_kernel)] + #[cfg(linux_raw_dep)] #[test] fn test_against_kernel_timespec() { assert_eq_size!(Timespec, linux_raw_sys::general::__kernel_timespec); -- 2.50.0.714.g196bf9f422-goog