Debian Codegraph @

subprojects/packagefiles/rustix-1-rs/0001-BACKPORT-rustix-on-Linux-support-a-build-without-lin.patch

raw
1 From bd19d4b3d439cfdf4f3882e1fe72691c0005fb9d Mon Sep 17 00:00:00 2001
2 From: gurchetansingh <[email protected]>
3 Date: Mon, 14 Jul 2025 08:08:17 -0700
4 Subject: [PATCH] BACKPORT: rustix: on Linux, support a build without
5 linux-raw-sys (#1478)
6
7 * rustix: on Android, support a build without linux-raw-sys
8
9 Rustix support was added to Mesa3D recently, but it only works
10 with the linux-raw-sys backend. On Linux, even the libc
11 backend, there is a dependency on linux-raw-sys for certain ABI
12 definitions.
13
14 When updating rustix in Android to support this, I realized only
15 the libc backend is supported in Android. This is because
16 Android as a platform wants to discourage raw syscalls, and to
17 be able to globally update libc.
18
19 Features like fdtrack would not work with the linux-raw-sys backend:
20
21 https://android.googlesource.com/platform/bionic/+/HEAD/docs/fdtrack.md
22
23 Given Android wants to incentize use of libc only, this MR introduces
24 the concept of "linux-raw-dep". This means that linux-raw-sys is
25 present as a dependency for the user. This will be on by default
26 even for the libc backend, but will be turned off for Android (this
27 is reflected in the build.rs script).
28
29 This will also help others who don't need all the features rustix
30 offers on Linux, so they have one less dependency to maintain. They
31 may append "--cfg=rustix_no_linux_raw" to Rust flags skip building
32 the linux raw backend. Mesa3D will use this.
33
34 Tested via:
35
36 cargo build --target arm-linux-androideabi --features=use-libc,net,std,alloc,event,fs,mm,param,pipe,use-libc-auxv,libc_errno
37
38 and on Linux with the proper RUSTFLAGS set. The Github workflows have
39 been modified to only use the current subset of features using in AOSP:
40
41 https://android.googlesource.com/platform/external/rust/android-crates-io/+/refs/heads/main/crates/rustix/Android.bp
42
43 That is the source of truth for an Android integration and the CI only
44 needs to test that. Additional features may be added as needed in the
45 future.
46
47 * rustix: fixes for Android musl build
48
49 Android doesn't only have a bionic toolchain, but musl
50 toolchain for components built on the build workstation.
51
52 ---------
53
54 Co-authored-by: Gurchetan Singh <[email protected]>
55 ---
56 build.rs | 9 ++++++
57 src/backend/libc/c.rs | 56 ++++++++++++++++-----------------
58 src/backend/libc/fs/mod.rs | 7 +++--
59 src/backend/libc/fs/syscalls.rs | 6 ++--
60 src/backend/libc/io/syscalls.rs | 6 ++--
61 src/backend/libc/io/types.rs | 12 +++----
62 src/backend/libc/mm/types.rs | 12 +++----
63 src/backend/libc/net/sockopt.rs | 6 ++--
64 src/fs/constants.rs | 6 ++--
65 src/fs/ioctl.rs | 8 ++---
66 src/fs/mod.rs | 6 ++--
67 src/fs/raw_dir.rs | 4 +++
68 src/io/read_write.rs | 6 ++--
69 src/ioctl/linux.rs | 4 +--
70 src/ioctl/mod.rs | 2 +-
71 src/net/sockopt.rs | 4 +--
72 src/net/types.rs | 48 ++++++++++++++--------------
73 src/timespec.rs | 2 +-
74 18 files changed, 109 insertions(+), 95 deletions(-)
75
76 diff --git a/build.rs b/build.rs
77 index d2d6541f..738492aa 100644
78 --- a/build.rs
79 +++ b/build.rs
80 @@ -35,6 +35,10 @@ fn main() {
81 // enable the libc backend even if rustix is depended on transitively.
82 let cfg_use_libc = var("CARGO_CFG_RUSTIX_USE_LIBC").is_ok();
83
84 + // Check for `RUSTFLAGS=--cfg=rustix_no_linux_raw`. This allows Linux users to
85 + // enable the libc backend without the linux raw dependency.
86 + let cfg_no_linux_raw = var("CARGO_CFG_RUSTIX_NO_LINUX_RAW").is_ok();
87 +
88 // Check for `--features=rustc-dep-of-std`.
89 let rustc_dep_of_std = var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
90
91 @@ -103,10 +107,15 @@ fn main() {
92 || arch.starts_with("mips"))
93 && !rustix_use_experimental_asm);
94 if libc {
95 + if os != "android" && os == "linux" && !cfg_no_linux_raw {
96 + use_feature("linux_raw_dep");
97 + }
98 +
99 // Use the libc backend.
100 use_feature("libc");
101 } else {
102 // Use the linux_raw backend.
103 + use_feature("linux_raw_dep");
104 use_feature("linux_raw");
105 if rustix_use_experimental_asm {
106 use_feature("asm_experimental_arch");
107 diff --git a/src/backend/libc/c.rs b/src/backend/libc/c.rs
108 index 2f737c21..656c4388 100644
109 --- a/src/backend/libc/c.rs
110 +++ b/src/backend/libc/c.rs
111 @@ -19,49 +19,49 @@ pub(crate) const NFS_SUPER_MAGIC: u32 = 0x0000_6969;
112 pub(crate) const EXIT_SIGNALED_SIGABRT: c_int = 128 + SIGABRT as c_int;
113
114 // TODO: Upstream these.
115 -#[cfg(all(linux_kernel, feature = "net"))]
116 +#[cfg(all(linux_raw_dep, feature = "net"))]
117 pub(crate) const ETH_P_TSN: c_int = linux_raw_sys::if_ether::ETH_P_TSN as _;
118 -#[cfg(all(linux_kernel, feature = "net"))]
119 +#[cfg(all(linux_raw_dep, feature = "net"))]
120 pub(crate) const ETH_P_ERSPAN2: c_int = linux_raw_sys::if_ether::ETH_P_ERSPAN2 as _;
121 -#[cfg(all(linux_kernel, feature = "net"))]
122 +#[cfg(all(linux_raw_dep, feature = "net"))]
123 pub(crate) const ETH_P_ERSPAN: c_int = linux_raw_sys::if_ether::ETH_P_ERSPAN as _;
124 -#[cfg(all(linux_kernel, feature = "net"))]
125 +#[cfg(all(linux_raw_dep, feature = "net"))]
126 pub(crate) const ETH_P_PROFINET: c_int = linux_raw_sys::if_ether::ETH_P_PROFINET as _;
127 -#[cfg(all(linux_kernel, feature = "net"))]
128 +#[cfg(all(linux_raw_dep, feature = "net"))]
129 pub(crate) const ETH_P_REALTEK: c_int = linux_raw_sys::if_ether::ETH_P_REALTEK as _;
130 -#[cfg(all(linux_kernel, feature = "net"))]
131 +#[cfg(all(linux_raw_dep, feature = "net"))]
132 pub(crate) const ETH_P_ETHERCAT: c_int = linux_raw_sys::if_ether::ETH_P_ETHERCAT as _;
133 -#[cfg(all(linux_kernel, feature = "net"))]
134 +#[cfg(all(linux_raw_dep, feature = "net"))]
135 pub(crate) const ETH_P_PREAUTH: c_int = linux_raw_sys::if_ether::ETH_P_PREAUTH as _;
136 -#[cfg(all(linux_kernel, feature = "net"))]
137 +#[cfg(all(linux_raw_dep, feature = "net"))]
138 pub(crate) const ETH_P_LLDP: c_int = linux_raw_sys::if_ether::ETH_P_LLDP as _;
139 -#[cfg(all(linux_kernel, feature = "net"))]
140 +#[cfg(all(linux_raw_dep, feature = "net"))]
141 pub(crate) const ETH_P_MRP: c_int = linux_raw_sys::if_ether::ETH_P_MRP as _;
142 -#[cfg(all(linux_kernel, feature = "net"))]
143 +#[cfg(all(linux_raw_dep, feature = "net"))]
144 pub(crate) const ETH_P_NCSI: c_int = linux_raw_sys::if_ether::ETH_P_NCSI as _;
145 -#[cfg(all(linux_kernel, feature = "net"))]
146 +#[cfg(all(linux_raw_dep, feature = "net"))]
147 pub(crate) const ETH_P_CFM: c_int = linux_raw_sys::if_ether::ETH_P_CFM as _;
148 -#[cfg(all(linux_kernel, feature = "net"))]
149 +#[cfg(all(linux_raw_dep, feature = "net"))]
150 pub(crate) const ETH_P_IBOE: c_int = linux_raw_sys::if_ether::ETH_P_IBOE as _;
151 -#[cfg(all(linux_kernel, feature = "net"))]
152 +#[cfg(all(linux_raw_dep, feature = "net"))]
153 pub(crate) const ETH_P_HSR: c_int = linux_raw_sys::if_ether::ETH_P_HSR as _;
154 -#[cfg(all(linux_kernel, feature = "net"))]
155 +#[cfg(all(linux_raw_dep, feature = "net"))]
156 pub(crate) const ETH_P_NSH: c_int = linux_raw_sys::if_ether::ETH_P_NSH as _;
157 -#[cfg(all(linux_kernel, feature = "net"))]
158 +#[cfg(all(linux_raw_dep, feature = "net"))]
159 pub(crate) const ETH_P_DSA_8021Q: c_int = linux_raw_sys::if_ether::ETH_P_DSA_8021Q as _;
160 -#[cfg(all(linux_kernel, feature = "net"))]
161 +#[cfg(all(linux_raw_dep, feature = "net"))]
162 pub(crate) const ETH_P_DSA_A5PSW: c_int = linux_raw_sys::if_ether::ETH_P_DSA_A5PSW as _;
163 -#[cfg(all(linux_kernel, feature = "net"))]
164 +#[cfg(all(linux_raw_dep, feature = "net"))]
165 pub(crate) const ETH_P_IFE: c_int = linux_raw_sys::if_ether::ETH_P_IFE as _;
166 -#[cfg(all(linux_kernel, feature = "net"))]
167 +#[cfg(all(linux_raw_dep, feature = "net"))]
168 pub(crate) const ETH_P_CAN: c_int = linux_raw_sys::if_ether::ETH_P_CAN as _;
169 -#[cfg(all(linux_kernel, feature = "net"))]
170 +#[cfg(all(linux_raw_dep, feature = "net"))]
171 pub(crate) const ETH_P_CANXL: c_int = linux_raw_sys::if_ether::ETH_P_CANXL as _;
172 -#[cfg(all(linux_kernel, feature = "net"))]
173 +#[cfg(all(linux_raw_dep, feature = "net"))]
174 pub(crate) const ETH_P_XDSA: c_int = linux_raw_sys::if_ether::ETH_P_XDSA as _;
175 -#[cfg(all(linux_kernel, feature = "net"))]
176 +#[cfg(all(linux_raw_dep, feature = "net"))]
177 pub(crate) const ETH_P_MAP: c_int = linux_raw_sys::if_ether::ETH_P_MAP as _;
178 -#[cfg(all(linux_kernel, feature = "net"))]
179 +#[cfg(all(linux_raw_dep, feature = "net"))]
180 pub(crate) const ETH_P_MCTP: c_int = linux_raw_sys::if_ether::ETH_P_MCTP as _;
181
182 #[cfg(all(
183 @@ -89,7 +89,7 @@ pub(crate) const MSG_DONTWAIT: c_int = MSG_NONBLOCK;
184 // `O_LARGEFILE` can be automatically set by the kernel on Linux:
185 // <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/open.c?h=v6.13#n1423>
186 // so libc implementations may leave it undefined or defined to zero.
187 -#[cfg(linux_kernel)]
188 +#[cfg(linux_raw_dep)]
189 pub(crate) const O_LARGEFILE: c_int = linux_raw_sys::general::O_LARGEFILE as _;
190
191 // Gated under `_LARGEFILE_SOURCE` but automatically set by the kernel.
192 @@ -489,7 +489,8 @@ pub(super) use readwrite_pv64v2::{preadv64v2 as preadv2, pwritev64v2 as pwritev2
193 #[cfg(feature = "fs")]
194 #[cfg(all(
195 linux_like,
196 - not(any(target_os = "android", target_os = "emscripten", target_env = "gnu"))
197 + linux_raw_dep,
198 + not(any(target_os = "emscripten", target_env = "gnu"))
199 ))]
200 mod statx_flags {
201 pub(crate) use linux_raw_sys::general::{
202 @@ -507,7 +508,8 @@ mod statx_flags {
203 #[cfg(feature = "fs")]
204 #[cfg(all(
205 linux_like,
206 - not(any(target_os = "android", target_os = "emscripten", target_env = "gnu"))
207 + linux_raw_dep,
208 + not(any(target_os = "emscripten", target_env = "gnu"))
209 ))]
210 pub(crate) use statx_flags::*;
211
212 @@ -515,10 +517,6 @@ pub(crate) use statx_flags::*;
213 #[cfg(target_os = "android")]
214 pub(crate) use __fsid_t as fsid_t;
215
216 -#[cfg(feature = "mm")]
217 -#[cfg(target_os = "android")]
218 -pub(crate) const MAP_DROPPABLE: c_int = bitcast!(linux_raw_sys::general::MAP_DROPPABLE);
219 -
220 #[cfg(test)]
221 mod tests {
222 use super::*;
223 diff --git a/src/backend/libc/fs/mod.rs b/src/backend/libc/fs/mod.rs
224 index 264b955c..f75c6fb7 100644
225 --- a/src/backend/libc/fs/mod.rs
226 +++ b/src/backend/libc/fs/mod.rs
227 @@ -16,9 +16,12 @@ pub(crate) mod syscalls;
228 pub(crate) mod types;
229
230 // TODO: Fix linux-raw-sys to define ioctl codes for sparc.
231 -#[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))]
232 +#[cfg(all(linux_raw_dep, any(target_arch = "sparc", target_arch = "sparc64")))]
233 pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::Opcode = 0x8008_6610;
234
235 -#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))]
236 +#[cfg(all(
237 + linux_raw_dep,
238 + not(any(target_arch = "sparc", target_arch = "sparc64"))
239 +))]
240 pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::Opcode =
241 linux_raw_sys::ioctl::EXT4_IOC_RESIZE_FS as crate::ioctl::Opcode;
242 diff --git a/src/backend/libc/fs/syscalls.rs b/src/backend/libc/fs/syscalls.rs
243 index f2ac4f73..ef1033cc 100644
244 --- a/src/backend/libc/fs/syscalls.rs
245 +++ b/src/backend/libc/fs/syscalls.rs
246 @@ -1840,7 +1840,7 @@ pub(crate) fn memfd_create(name: &CStr, flags: MemfdFlags) -> io::Result<OwnedFd
247 unsafe { ret_owned_fd(memfd_create(c_str(name), bitflags_bits!(flags))) }
248 }
249
250 -#[cfg(linux_kernel)]
251 +#[cfg(linux_raw_dep)]
252 pub(crate) fn openat2(
253 dirfd: BorrowedFd<'_>,
254 path: &CStr,
255 @@ -2053,9 +2053,9 @@ pub(crate) fn statx(
256 // doesn't represent all the known flags.
257 //
258 // [it's deprecated]: https://patchwork.kernel.org/project/linux-fsdevel/patch/[email protected]/
259 - #[cfg(not(any(target_os = "android", target_env = "musl")))]
260 + #[cfg(any(not(linux_raw_dep), not(target_env = "musl")))]
261 const STATX__RESERVED: u32 = c::STATX__RESERVED as u32;
262 - #[cfg(any(target_os = "android", target_env = "musl"))]
263 + #[cfg(target_env = "musl")]
264 const STATX__RESERVED: u32 = linux_raw_sys::general::STATX__RESERVED;
265 if (mask.bits() & STATX__RESERVED) == STATX__RESERVED {
266 return Err(io::Errno::INVAL);
267 diff --git a/src/backend/libc/io/syscalls.rs b/src/backend/libc/io/syscalls.rs
268 index f1231aaf..d91e983c 100644
269 --- a/src/backend/libc/io/syscalls.rs
270 +++ b/src/backend/libc/io/syscalls.rs
271 @@ -13,7 +13,7 @@ use crate::fd::{AsFd as _, BorrowedFd, OwnedFd, RawFd};
272 target_os = "wasi"
273 )))]
274 use crate::io::DupFlags;
275 -#[cfg(linux_kernel)]
276 +#[cfg(all(linux_kernel, not(target_os = "android")))]
277 use crate::io::ReadWriteFlags;
278 use crate::io::{self, FdFlags};
279 use crate::ioctl::{IoctlOutput, Opcode};
280 @@ -150,7 +150,7 @@ pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>], offset: u64) ->
281 }
282 }
283
284 -#[cfg(linux_kernel)]
285 +#[cfg(all(linux_kernel, not(target_os = "android")))]
286 pub(crate) fn preadv2(
287 fd: BorrowedFd<'_>,
288 bufs: &mut [IoSliceMut<'_>],
289 @@ -170,7 +170,7 @@ pub(crate) fn preadv2(
290 }
291 }
292
293 -#[cfg(linux_kernel)]
294 +#[cfg(all(linux_kernel, not(target_os = "android")))]
295 pub(crate) fn pwritev2(
296 fd: BorrowedFd<'_>,
297 bufs: &[IoSlice<'_>],
298 diff --git a/src/backend/libc/io/types.rs b/src/backend/libc/io/types.rs
299 index 510206f9..b434b68a 100644
300 --- a/src/backend/libc/io/types.rs
301 +++ b/src/backend/libc/io/types.rs
302 @@ -17,7 +17,7 @@ bitflags! {
303 }
304 }
305
306 -#[cfg(linux_kernel)]
307 +#[cfg(all(linux_kernel, not(target_os = "android")))]
308 bitflags! {
309 /// `RWF_*` constants for use with [`preadv2`] and [`pwritev2`].
310 ///
311 @@ -27,15 +27,15 @@ bitflags! {
312 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
313 pub struct ReadWriteFlags: u32 {
314 /// `RWF_DSYNC` (since Linux 4.7)
315 - const DSYNC = linux_raw_sys::general::RWF_DSYNC;
316 + const DSYNC = libc::RWF_DSYNC as u32;
317 /// `RWF_HIPRI` (since Linux 4.6)
318 - const HIPRI = linux_raw_sys::general::RWF_HIPRI;
319 + const HIPRI = libc::RWF_HIPRI as u32;
320 /// `RWF_SYNC` (since Linux 4.7)
321 - const SYNC = linux_raw_sys::general::RWF_SYNC;
322 + const SYNC = libc::RWF_SYNC as u32;
323 /// `RWF_NOWAIT` (since Linux 4.14)
324 - const NOWAIT = linux_raw_sys::general::RWF_NOWAIT;
325 + const NOWAIT = libc::RWF_NOWAIT as u32;
326 /// `RWF_APPEND` (since Linux 4.16)
327 - const APPEND = linux_raw_sys::general::RWF_APPEND;
328 + const APPEND = libc::RWF_APPEND as u32;
329
330 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
331 const _ = !0;
332 diff --git a/src/backend/libc/mm/types.rs b/src/backend/libc/mm/types.rs
333 index 0b99e3c4..6f7d24f5 100644
334 --- a/src/backend/libc/mm/types.rs
335 +++ b/src/backend/libc/mm/types.rs
336 @@ -44,19 +44,19 @@ bitflags! {
337 #[cfg(linux_kernel)]
338 const GROWSDOWN = bitcast!(c::PROT_GROWSDOWN);
339 /// `PROT_SEM`
340 - #[cfg(linux_kernel)]
341 + #[cfg(linux_raw_dep)]
342 const SEM = linux_raw_sys::general::PROT_SEM;
343 /// `PROT_BTI`
344 - #[cfg(all(linux_kernel, target_arch = "aarch64"))]
345 + #[cfg(all(linux_raw_dep, target_arch = "aarch64"))]
346 const BTI = linux_raw_sys::general::PROT_BTI;
347 /// `PROT_MTE`
348 - #[cfg(all(linux_kernel, target_arch = "aarch64"))]
349 + #[cfg(all(linux_raw_dep, target_arch = "aarch64"))]
350 const MTE = linux_raw_sys::general::PROT_MTE;
351 /// `PROT_SAO`
352 - #[cfg(all(linux_kernel, any(target_arch = "powerpc", target_arch = "powerpc64")))]
353 + #[cfg(all(linux_raw_dep, any(target_arch = "powerpc", target_arch = "powerpc64")))]
354 const SAO = linux_raw_sys::general::PROT_SAO;
355 /// `PROT_ADI`
356 - #[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))]
357 + #[cfg(all(linux_raw_dep, any(target_arch = "sparc", target_arch = "sparc64")))]
358 const ADI = linux_raw_sys::general::PROT_ADI;
359
360 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
361 @@ -252,7 +252,7 @@ bitflags! {
362 #[cfg(any())]
363 const UNINITIALIZED = bitcast!(c::MAP_UNINITIALIZED);
364 /// `MAP_DROPPABLE`
365 - #[cfg(linux_kernel)]
366 + #[cfg(all(linux_kernel, not(target_os = "android")))]
367 const DROPPABLE = bitcast!(c::MAP_DROPPABLE);
368
369 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
370 diff --git a/src/backend/libc/net/sockopt.rs b/src/backend/libc/net/sockopt.rs
371 index 132ebe75..a9e32d37 100644
372 --- a/src/backend/libc/net/sockopt.rs
373 +++ b/src/backend/libc/net/sockopt.rs
374 @@ -76,7 +76,7 @@ use c::TCP_KEEPALIVE as TCP_KEEPIDLE;
375 use c::TCP_KEEPIDLE;
376 use core::mem::{size_of, MaybeUninit};
377 use core::time::Duration;
378 -#[cfg(target_os = "linux")]
379 +#[cfg(linux_raw_dep)]
380 use linux_raw_sys::xdp::{xdp_mmap_offsets, xdp_statistics, xdp_statistics_v1};
381 #[cfg(windows)]
382 use windows_sys::Win32::Foundation::BOOL;
383 @@ -1090,7 +1090,7 @@ pub(crate) fn set_xdp_rx_ring_size(fd: BorrowedFd<'_>, value: u32) -> io::Result
384 setsockopt(fd, c::SOL_XDP, c::XDP_RX_RING, value)
385 }
386
387 -#[cfg(target_os = "linux")]
388 +#[cfg(linux_raw_dep)]
389 #[inline]
390 pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets> {
391 // The kernel will write `xdp_mmap_offsets` or `xdp_mmap_offsets_v1` to the
392 @@ -1177,7 +1177,7 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
393 }
394 }
395
396 -#[cfg(target_os = "linux")]
397 +#[cfg(linux_raw_dep)]
398 #[inline]
399 pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
400 let mut optlen = size_of::<xdp_statistics>().try_into().unwrap();
401 diff --git a/src/fs/constants.rs b/src/fs/constants.rs
402 index 5f106342..337b67e6 100644
403 --- a/src/fs/constants.rs
404 +++ b/src/fs/constants.rs
405 @@ -56,12 +56,12 @@ mod tests {
406
407 #[test]
408 fn test_layouts() {
409 - #[cfg(linux_kernel)]
410 + #[cfg(linux_raw_dep)]
411 assert_eq_size!(FsWord, linux_raw_sys::general::__fsword_t);
412
413 // Don't test against `__kernel_mode_t` on platforms where it's a
414 // `u16`.
415 - #[cfg(linux_kernel)]
416 + #[cfg(linux_raw_dep)]
417 #[cfg(not(any(
418 target_arch = "x86",
419 target_arch = "sparc",
420 @@ -70,7 +70,7 @@ mod tests {
421 )))]
422 assert_eq_size!(RawMode, linux_raw_sys::general::__kernel_mode_t);
423
424 - #[cfg(linux_kernel)]
425 + #[cfg(linux_raw_dep)]
426 #[cfg(any(
427 target_arch = "x86",
428 target_arch = "sparc",
429 diff --git a/src/fs/ioctl.rs b/src/fs/ioctl.rs
430 index c126fdd1..16e0dda1 100644
431 --- a/src/fs/ioctl.rs
432 +++ b/src/fs/ioctl.rs
433 @@ -58,7 +58,7 @@ pub fn ioctl_ficlone<Fd: AsFd, SrcFd: AsFd>(fd: Fd, src_fd: SrcFd) -> io::Result
434 }
435
436 /// `ioctl(fd, EXT4_IOC_RESIZE_FS, blocks)`—Resize ext4 filesystem on fd.
437 -#[cfg(linux_kernel)]
438 +#[cfg(linux_raw_dep)]
439 #[inline]
440 #[doc(alias = "EXT4_IOC_RESIZE_FS")]
441 pub fn ext4_ioc_resize_fs<Fd: AsFd>(fd: Fd, blocks: u64) -> io::Result<()> {
442 @@ -94,7 +94,7 @@ unsafe impl ioctl::Ioctl for Ficlone<'_> {
443 }
444 }
445
446 -#[cfg(linux_kernel)]
447 +#[cfg(linux_raw_dep)]
448 bitflags! {
449 /// `FS_*` constants for use with [`ioctl_getflags`].
450 ///
451 @@ -136,7 +136,7 @@ bitflags! {
452 /// `ioctl(fd, FS_IOC_GETFLAGS)`—Returns the [inode flags] attributes
453 ///
454 /// [inode flags]: https://man7.org/linux/man-pages/man2/ioctl_iflags.2.html
455 -#[cfg(linux_kernel)]
456 +#[cfg(linux_raw_dep)]
457 #[inline]
458 #[doc(alias = "FS_IOC_GETFLAGS")]
459 pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> {
460 @@ -153,7 +153,7 @@ pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> {
461 /// `ioctl(fd, FS_IOC_SETFLAGS)`—Modify the [inode flags] attributes
462 ///
463 /// [inode flags]: https://man7.org/linux/man-pages/man2/ioctl_iflags.2.html
464 -#[cfg(linux_kernel)]
465 +#[cfg(linux_raw_dep)]
466 #[inline]
467 #[doc(alias = "FS_IOC_SETFLAGS")]
468 pub fn ioctl_setflags<Fd: AsFd>(fd: Fd, flags: IFlags) -> io::Result<()> {
469 diff --git a/src/fs/mod.rs b/src/fs/mod.rs
470 index 505925f7..1807ada6 100644
471 --- a/src/fs/mod.rs
472 +++ b/src/fs/mod.rs
473 @@ -30,7 +30,7 @@ pub(crate) mod fd;
474 mod getpath;
475 #[cfg(not(target_os = "wasi"))] // WASI doesn't have get[gpu]id.
476 mod id;
477 -#[cfg(linux_kernel)]
478 +#[cfg(linux_raw_dep)]
479 pub mod inotify;
480 #[cfg(linux_kernel)]
481 mod ioctl;
482 @@ -45,7 +45,7 @@ mod ioctl;
483 mod makedev;
484 #[cfg(any(linux_kernel, target_os = "freebsd"))]
485 mod memfd_create;
486 -#[cfg(linux_kernel)]
487 +#[cfg(linux_raw_dep)]
488 mod openat2;
489 #[cfg(linux_kernel)]
490 mod raw_dir;
491 @@ -110,7 +110,7 @@ pub use ioctl::*;
492 pub use makedev::*;
493 #[cfg(any(linux_kernel, target_os = "freebsd"))]
494 pub use memfd_create::memfd_create;
495 -#[cfg(linux_kernel)]
496 +#[cfg(linux_raw_dep)]
497 pub use openat2::openat2;
498 #[cfg(linux_kernel)]
499 pub use raw_dir::{RawDir, RawDirEntry};
500 diff --git a/src/fs/raw_dir.rs b/src/fs/raw_dir.rs
501 index 7fec6fd7..9691ca71 100644
502 --- a/src/fs/raw_dir.rs
503 +++ b/src/fs/raw_dir.rs
504 @@ -7,6 +7,10 @@ use crate::fs::FileType;
505 use crate::io;
506 use core::fmt;
507 use core::mem::{align_of, MaybeUninit};
508 +
509 +#[cfg(not(linux_raw_dep))]
510 +use libc::dirent64 as linux_dirent64;
511 +#[cfg(linux_raw_dep)]
512 use linux_raw_sys::general::linux_dirent64;
513
514 /// A directory iterator implemented with getdents.
515 diff --git a/src/io/read_write.rs b/src/io/read_write.rs
516 index 572c7b65..0e096910 100644
517 --- a/src/io/read_write.rs
518 +++ b/src/io/read_write.rs
519 @@ -10,7 +10,7 @@ use backend::fd::AsFd;
520 #[cfg(not(windows))]
521 pub use crate::maybe_polyfill::io::{IoSlice, IoSliceMut};
522
523 -#[cfg(linux_kernel)]
524 +#[cfg(all(linux_kernel, not(target_os = "android")))]
525 pub use backend::io::types::ReadWriteFlags;
526
527 /// `read(fd, buf)`—Reads from a stream.
528 @@ -277,7 +277,7 @@ pub fn pwritev<Fd: AsFd>(fd: Fd, bufs: &[IoSlice<'_>], offset: u64) -> io::Resul
529 ///
530 /// [Linux]: https://man7.org/linux/man-pages/man2/preadv2.2.html
531 /// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Scatter_002dGather.html#index-preadv64v2
532 -#[cfg(linux_kernel)]
533 +#[cfg(all(linux_kernel, not(target_os = "android")))]
534 #[inline]
535 pub fn preadv2<Fd: AsFd>(
536 fd: Fd,
537 @@ -298,7 +298,7 @@ pub fn preadv2<Fd: AsFd>(
538 ///
539 /// [Linux]: https://man7.org/linux/man-pages/man2/pwritev2.2.html
540 /// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Scatter_002dGather.html#index-pwritev64v2
541 -#[cfg(linux_kernel)]
542 +#[cfg(all(linux_kernel, not(target_os = "android")))]
543 #[inline]
544 pub fn pwritev2<Fd: AsFd>(
545 fd: Fd,
546 diff --git a/src/ioctl/linux.rs b/src/ioctl/linux.rs
547 index 7215228a..8d96a1b2 100644
548 --- a/src/ioctl/linux.rs
549 +++ b/src/ioctl/linux.rs
550 @@ -88,12 +88,12 @@ mod tests {
551 #[allow(unused_imports)]
552 use super::*;
553
554 - #[cfg(not(any(
555 + #[cfg(all(linux_raw_dep, not(any(
556 // These have no ioctl opcodes defined in linux_raw_sys so we can't use
557 // that as a known-good value for this test.
558 target_arch = "sparc",
559 target_arch = "sparc64"
560 -)))]
561 +))))]
562 #[test]
563 fn check_known_opcodes() {
564 use crate::backend::c::{c_long, c_uint};
565 diff --git a/src/ioctl/mod.rs b/src/ioctl/mod.rs
566 index e3e8f8e1..4beed113 100644
567 --- a/src/ioctl/mod.rs
568 +++ b/src/ioctl/mod.rs
569 @@ -344,7 +344,7 @@ type _Opcode = c::c_uint;
570 #[cfg(windows)]
571 type _Opcode = i32;
572
573 -#[cfg(linux_kernel)]
574 +#[cfg(linux_raw_dep)]
575 #[cfg(not(any(target_arch = "sparc", target_arch = "sparc64")))]
576 #[cfg(test)]
577 mod tests {
578 diff --git a/src/net/sockopt.rs b/src/net/sockopt.rs
579 index ef8176ae..145f32be 100644
580 --- a/src/net/sockopt.rs
581 +++ b/src/net/sockopt.rs
582 @@ -1604,7 +1604,7 @@ pub fn set_xdp_rx_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
583 /// - [Linux]
584 ///
585 /// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html
586 -#[cfg(target_os = "linux")]
587 +#[cfg(linux_raw_dep)]
588 #[doc(alias = "XDP_MMAP_OFFSETS")]
589 pub fn xdp_mmap_offsets<Fd: AsFd>(fd: Fd) -> io::Result<XdpMmapOffsets> {
590 backend::net::sockopt::xdp_mmap_offsets(fd.as_fd())
591 @@ -1616,7 +1616,7 @@ pub fn xdp_mmap_offsets<Fd: AsFd>(fd: Fd) -> io::Result<XdpMmapOffsets> {
592 /// - [Linux]
593 ///
594 /// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-statistics-getsockopt
595 -#[cfg(target_os = "linux")]
596 +#[cfg(linux_raw_dep)]
597 #[doc(alias = "XDP_STATISTICS")]
598 pub fn xdp_statistics<Fd: AsFd>(fd: Fd) -> io::Result<XdpStatistics> {
599 backend::net::sockopt::xdp_statistics(fd.as_fd())
600 diff --git a/src/net/types.rs b/src/net/types.rs
601 index 057f944d..43dfa610 100644
602 --- a/src/net/types.rs
603 +++ b/src/net/types.rs
604 @@ -1321,10 +1321,10 @@ pub mod eth {
605 #[cfg(linux_kernel)]
606 pub const PUPAT: Protocol = Protocol(new_raw_protocol((c::ETH_P_PUPAT as u16).to_be() as u32));
607 /// `ETH_P_TSN`
608 - #[cfg(linux_kernel)]
609 + #[cfg(linux_raw_dep)]
610 pub const TSN: Protocol = Protocol(new_raw_protocol((c::ETH_P_TSN as u16).to_be() as u32));
611 /// `ETH_P_ERSPAN2`
612 - #[cfg(linux_kernel)]
613 + #[cfg(linux_raw_dep)]
614 pub const ERSPAN2: Protocol =
615 Protocol(new_raw_protocol((c::ETH_P_ERSPAN2 as u16).to_be() as u32));
616 /// `ETH_P_IP`
617 @@ -1395,7 +1395,7 @@ pub mod eth {
618 pub const P_8021Q: Protocol =
619 Protocol(new_raw_protocol((c::ETH_P_8021Q as u16).to_be() as u32));
620 /// `ETH_P_ERSPAN`
621 - #[cfg(linux_kernel)]
622 + #[cfg(linux_raw_dep)]
623 pub const ERSPAN: Protocol =
624 Protocol(new_raw_protocol((c::ETH_P_ERSPAN as u16).to_be() as u32));
625 /// `ETH_P_IPX`
626 @@ -1445,18 +1445,18 @@ pub mod eth {
627 #[cfg(linux_kernel)]
628 pub const PAE: Protocol = Protocol(new_raw_protocol((c::ETH_P_PAE as u16).to_be() as u32));
629 /// `ETH_P_PROFINET`
630 - #[cfg(linux_kernel)]
631 + #[cfg(linux_raw_dep)]
632 pub const PROFINET: Protocol =
633 Protocol(new_raw_protocol((c::ETH_P_PROFINET as u16).to_be() as u32));
634 /// `ETH_P_REALTEK`
635 - #[cfg(linux_kernel)]
636 + #[cfg(linux_raw_dep)]
637 pub const REALTEK: Protocol =
638 Protocol(new_raw_protocol((c::ETH_P_REALTEK as u16).to_be() as u32));
639 /// `ETH_P_AOE`
640 #[cfg(linux_kernel)]
641 pub const AOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_AOE as u16).to_be() as u32));
642 /// `ETH_P_ETHERCAT`
643 - #[cfg(linux_kernel)]
644 + #[cfg(linux_raw_dep)]
645 pub const ETHERCAT: Protocol =
646 Protocol(new_raw_protocol((c::ETH_P_ETHERCAT as u16).to_be() as u32));
647 /// `ETH_P_8021AD`
648 @@ -1468,17 +1468,17 @@ pub mod eth {
649 pub const P_802_EX1: Protocol =
650 Protocol(new_raw_protocol((c::ETH_P_802_EX1 as u16).to_be() as u32));
651 /// `ETH_P_PREAUTH`
652 - #[cfg(linux_kernel)]
653 + #[cfg(linux_raw_dep)]
654 pub const PREAUTH: Protocol =
655 Protocol(new_raw_protocol((c::ETH_P_PREAUTH as u16).to_be() as u32));
656 /// `ETH_P_TIPC`
657 #[cfg(linux_kernel)]
658 pub const TIPC: Protocol = Protocol(new_raw_protocol((c::ETH_P_TIPC as u16).to_be() as u32));
659 /// `ETH_P_LLDP`
660 - #[cfg(linux_kernel)]
661 + #[cfg(linux_raw_dep)]
662 pub const LLDP: Protocol = Protocol(new_raw_protocol((c::ETH_P_LLDP as u16).to_be() as u32));
663 /// `ETH_P_MRP`
664 - #[cfg(linux_kernel)]
665 + #[cfg(linux_raw_dep)]
666 pub const MRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MRP as u16).to_be() as u32));
667 /// `ETH_P_MACSEC`
668 #[cfg(linux_kernel)]
669 @@ -1495,19 +1495,19 @@ pub mod eth {
670 #[cfg(linux_kernel)]
671 pub const P_1588: Protocol = Protocol(new_raw_protocol((c::ETH_P_1588 as u16).to_be() as u32));
672 /// `ETH_P_NCSI`
673 - #[cfg(linux_kernel)]
674 + #[cfg(linux_raw_dep)]
675 pub const NCSI: Protocol = Protocol(new_raw_protocol((c::ETH_P_NCSI as u16).to_be() as u32));
676 /// `ETH_P_PRP`
677 #[cfg(linux_kernel)]
678 pub const PRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_PRP as u16).to_be() as u32));
679 /// `ETH_P_CFM`
680 - #[cfg(linux_kernel)]
681 + #[cfg(linux_raw_dep)]
682 pub const CFM: Protocol = Protocol(new_raw_protocol((c::ETH_P_CFM as u16).to_be() as u32));
683 /// `ETH_P_FCOE`
684 #[cfg(linux_kernel)]
685 pub const FCOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_FCOE as u16).to_be() as u32));
686 /// `ETH_P_IBOE`
687 - #[cfg(linux_kernel)]
688 + #[cfg(linux_raw_dep)]
689 pub const IBOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_IBOE as u16).to_be() as u32));
690 /// `ETH_P_TDLS`
691 #[cfg(linux_kernel)]
692 @@ -1520,10 +1520,10 @@ pub mod eth {
693 pub const P_80221: Protocol =
694 Protocol(new_raw_protocol((c::ETH_P_80221 as u16).to_be() as u32));
695 /// `ETH_P_HSR`
696 - #[cfg(linux_kernel)]
697 + #[cfg(linux_raw_dep)]
698 pub const HSR: Protocol = Protocol(new_raw_protocol((c::ETH_P_HSR as u16).to_be() as u32));
699 /// `ETH_P_NSH`
700 - #[cfg(linux_kernel)]
701 + #[cfg(linux_raw_dep)]
702 pub const NSH: Protocol = Protocol(new_raw_protocol((c::ETH_P_NSH as u16).to_be() as u32));
703 /// `ETH_P_LOOPBACK`
704 #[cfg(linux_kernel)]
705 @@ -1542,15 +1542,15 @@ pub mod eth {
706 #[cfg(linux_kernel)]
707 pub const EDSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_EDSA as u16).to_be() as u32));
708 /// `ETH_P_DSA_8021Q`
709 - #[cfg(linux_kernel)]
710 + #[cfg(linux_raw_dep)]
711 pub const DSA_8021Q: Protocol =
712 Protocol(new_raw_protocol((c::ETH_P_DSA_8021Q as u16).to_be() as u32));
713 /// `ETH_P_DSA_A5PSW`
714 - #[cfg(linux_kernel)]
715 + #[cfg(linux_raw_dep)]
716 pub const DSA_A5PSW: Protocol =
717 Protocol(new_raw_protocol((c::ETH_P_DSA_A5PSW as u16).to_be() as u32));
718 /// `ETH_P_IFE`
719 - #[cfg(linux_kernel)]
720 + #[cfg(linux_raw_dep)]
721 pub const IFE: Protocol = Protocol(new_raw_protocol((c::ETH_P_IFE as u16).to_be() as u32));
722 /// `ETH_P_AF_IUCV`
723 #[cfg(linux_kernel)]
724 @@ -1568,7 +1568,7 @@ pub mod eth {
725 #[cfg(linux_kernel)]
726 pub const AX25: Protocol = Protocol(new_raw_protocol((c::ETH_P_AX25 as u16).to_be() as u32));
727 /// `ETH_P_ALL`
728 - #[cfg(linux_kernel)]
729 + #[cfg(linux_raw_dep)]
730 pub const ALL: Protocol = Protocol(new_raw_protocol((c::ETH_P_ALL as u16).to_be() as u32));
731 /// `ETH_P_802_2`
732 #[cfg(linux_kernel)]
733 @@ -1593,13 +1593,13 @@ pub mod eth {
734 pub const LOCALTALK: Protocol =
735 Protocol(new_raw_protocol((c::ETH_P_LOCALTALK as u16).to_be() as u32));
736 /// `ETH_P_CAN`
737 - #[cfg(linux_kernel)]
738 + #[cfg(linux_raw_dep)]
739 pub const CAN: Protocol = Protocol(new_raw_protocol((c::ETH_P_CAN as u16).to_be() as u32));
740 /// `ETH_P_CANFD`
741 #[cfg(linux_kernel)]
742 pub const CANFD: Protocol = Protocol(new_raw_protocol((c::ETH_P_CANFD as u16).to_be() as u32));
743 /// `ETH_P_CANXL`
744 - #[cfg(linux_kernel)]
745 + #[cfg(linux_raw_dep)]
746 pub const CANXL: Protocol = Protocol(new_raw_protocol((c::ETH_P_CANXL as u16).to_be() as u32));
747 /// `ETH_P_PPPTALK`
748 #[cfg(linux_kernel)]
749 @@ -1632,7 +1632,7 @@ pub mod eth {
750 pub const ARCNET: Protocol =
751 Protocol(new_raw_protocol((c::ETH_P_ARCNET as u16).to_be() as u32));
752 /// `ETH_P_DSA`
753 - #[cfg(linux_kernel)]
754 + #[cfg(linux_raw_dep)]
755 pub const DSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_DSA as u16).to_be() as u32));
756 /// `ETH_P_TRAILER`
757 #[cfg(linux_kernel)]
758 @@ -1650,13 +1650,13 @@ pub mod eth {
759 #[cfg(linux_kernel)]
760 pub const CAIF: Protocol = Protocol(new_raw_protocol((c::ETH_P_CAIF as u16).to_be() as u32));
761 /// `ETH_P_XDSA`
762 - #[cfg(linux_kernel)]
763 + #[cfg(linux_raw_dep)]
764 pub const XDSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_XDSA as u16).to_be() as u32));
765 /// `ETH_P_MAP`
766 - #[cfg(linux_kernel)]
767 + #[cfg(linux_raw_dep)]
768 pub const MAP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MAP as u16).to_be() as u32));
769 /// `ETH_P_MCTP`
770 - #[cfg(linux_kernel)]
771 + #[cfg(linux_raw_dep)]
772 pub const MCTP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MCTP as u16).to_be() as u32));
773 }
774
775 diff --git a/src/timespec.rs b/src/timespec.rs
776 index f5404ba4..a6458bbc 100644
777 --- a/src/timespec.rs
778 +++ b/src/timespec.rs
779 @@ -411,7 +411,7 @@ mod tests {
780 }
781
782 // Test that `Timespec` matches Linux's `__kernel_timespec`.
783 - #[cfg(linux_kernel)]
784 + #[cfg(linux_raw_dep)]
785 #[test]
786 fn test_against_kernel_timespec() {
787 assert_eq_size!(Timespec, linux_raw_sys::general::__kernel_timespec);
788 --
789 2.50.0.727.gbf7dc18ff4-goog
790