Skip to content

Commit fda7cbe

Browse files
rustix: on Linux, support a build without linux-raw-sys (#1478)
* 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. * rustix: fixes for Android musl build Android doesn't only have a bionic toolchain, but musl toolchain for components built on the build workstation. --------- Co-authored-by: Gurchetan Singh <[email protected]>
1 parent 94a0c51 commit fda7cbe

File tree

25 files changed

+134
-110
lines changed

25 files changed

+134
-110
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ jobs:
104104
- run: cargo check --workspace --release -vv --target=x86_64-unknown-linux-musl --features=all-apis --all-targets
105105
- run: cargo check --workspace --release -vv --target=x86_64-unknown-linux-musl --features=use-libc,all-apis --all-targets
106106
- run: cargo check --workspace --release -vv --target=x86_64-unknown-linux-gnux32 --features=all-apis --all-targets
107-
- run: cargo check --workspace --release -vv --target=x86_64-linux-android --features=all-apis --all-targets
108-
- run: cargo check --workspace --release -vv --target=i686-linux-android --features=all-apis --all-targets
107+
- run: cargo check --workspace --release -vv --target=x86_64-linux-android --features=use-libc,net,std,alloc,event,fs,mm,param,pipe,use-libc-auxv,libc_errno --all-targets
108+
- run: cargo check --workspace --release -vv --target=i686-linux-android --features=use-libc,net,std,alloc,event,fs,mm,param,pipe,use-libc-auxv,libc_errno --all-targets
109109
- run: cargo check --workspace --release -vv --target=x86_64-apple-darwin --features=all-apis --all-targets
110110
- run: cargo check --workspace --release -vv --target=x86_64-unknown-freebsd --features=all-apis --all-targets
111111
- run: cargo check --workspace --release -vv --target=x86_64-unknown-netbsd --features=all-apis --all-targets
@@ -132,11 +132,11 @@ jobs:
132132
- run: cargo check --workspace --release -vv --target=powerpc64le-unknown-linux-gnu --features=all-apis --all-targets
133133
- run: cargo check --workspace --release -vv --target=armv5te-unknown-linux-gnueabi --features=all-apis --all-targets
134134
- run: cargo check --workspace --release -vv --target=s390x-unknown-linux-gnu --features=all-apis --all-targets
135-
- run: cargo check --workspace --release -vv --target=arm-linux-androideabi --features=all-apis --all-targets
135+
- run: cargo check --workspace --release -vv --target=arm-linux-androideabi --features=use-libc,net,std,alloc,event,fs,mm,param,pipe,use-libc-auxv,libc_errno --all-targets
136136
- run: cargo check --workspace --release -vv --target=sparc64-unknown-linux-gnu --features=all-apis --all-targets
137137
- run: cargo check --workspace --release -vv --target=sparcv9-sun-solaris --features=all-apis --all-targets
138138
- run: cargo check --workspace --release -vv --target=aarch64-apple-ios --features=all-apis --all-targets
139-
- run: cargo check --workspace --release -vv --target=aarch64-linux-android --features=all-apis --all-targets
139+
- run: cargo check --workspace --release -vv --target=aarch64-linux-android --features=use-libc,net,std,alloc,event,fs,mm,param,pipe,use-libc-auxv,libc_errno --all-targets
140140
- run: cargo check --workspace --release -vv --target=i686-pc-windows-msvc --features=all-apis --all-targets
141141

142142
check_no_default_features:

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ libc = { version = "0.2.171", default-features = false }
4545
#
4646
# Some syscalls do not have libc wrappers, such as in `io_uring`. For these,
4747
# the libc backend uses the linux-raw-sys ABI and `libc::syscall`.
48-
[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]
48+
[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]
4949
linux-raw-sys = { version = "0.9.2", default-features = false, features = ["general", "ioctl", "no_std"] }
5050

5151
# For the libc backend on Windows, use the Winsock API in windows-sys.
@@ -256,6 +256,7 @@ check-cfg = [
256256
'cfg(linux_kernel)',
257257
'cfg(linux_like)',
258258
'cfg(linux_raw)',
259+
'cfg(linux_raw_dep)',
259260
'cfg(lower_upper_exp_for_non_zero)',
260261
'cfg(netbsdlike)',
261262
'cfg(rustc_attrs)',

build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ fn main() {
3535
// enable the libc backend even if rustix is depended on transitively.
3636
let cfg_use_libc = var("CARGO_CFG_RUSTIX_USE_LIBC").is_ok();
3737

38+
// Check for `RUSTFLAGS=--cfg=rustix_no_linux_raw`. This allows Linux users to
39+
// enable the libc backend without the linux raw dependency.
40+
let cfg_no_linux_raw = var("CARGO_CFG_RUSTIX_NO_LINUX_RAW").is_ok();
41+
3842
// Check for `--features=rustc-dep-of-std`.
3943
let rustc_dep_of_std = var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
4044

@@ -108,10 +112,15 @@ fn main() {
108112
|| arch.starts_with("mips"))
109113
&& !rustix_use_experimental_asm);
110114
if libc {
115+
if os != "android" && os == "linux" && !cfg_no_linux_raw {
116+
use_feature("linux_raw_dep");
117+
}
118+
111119
// Use the libc backend.
112120
use_feature("libc");
113121
} else {
114122
// Use the linux_raw backend.
123+
use_feature("linux_raw_dep");
115124
use_feature("linux_raw");
116125
if rustix_use_experimental_asm {
117126
use_feature("asm_experimental_arch");

src/backend/libc/c.rs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,49 @@ pub(crate) const NFS_SUPER_MAGIC: u32 = 0x0000_6969;
1919
pub(crate) const EXIT_SIGNALED_SIGABRT: c_int = 128 + SIGABRT as c_int;
2020

2121
// TODO: Upstream these.
22-
#[cfg(all(linux_kernel, feature = "net"))]
22+
#[cfg(all(linux_raw_dep, feature = "net"))]
2323
pub(crate) const ETH_P_TSN: c_int = linux_raw_sys::if_ether::ETH_P_TSN as _;
24-
#[cfg(all(linux_kernel, feature = "net"))]
24+
#[cfg(all(linux_raw_dep, feature = "net"))]
2525
pub(crate) const ETH_P_ERSPAN2: c_int = linux_raw_sys::if_ether::ETH_P_ERSPAN2 as _;
26-
#[cfg(all(linux_kernel, feature = "net"))]
26+
#[cfg(all(linux_raw_dep, feature = "net"))]
2727
pub(crate) const ETH_P_ERSPAN: c_int = linux_raw_sys::if_ether::ETH_P_ERSPAN as _;
28-
#[cfg(all(linux_kernel, feature = "net"))]
28+
#[cfg(all(linux_raw_dep, feature = "net"))]
2929
pub(crate) const ETH_P_PROFINET: c_int = linux_raw_sys::if_ether::ETH_P_PROFINET as _;
30-
#[cfg(all(linux_kernel, feature = "net"))]
30+
#[cfg(all(linux_raw_dep, feature = "net"))]
3131
pub(crate) const ETH_P_REALTEK: c_int = linux_raw_sys::if_ether::ETH_P_REALTEK as _;
32-
#[cfg(all(linux_kernel, feature = "net"))]
32+
#[cfg(all(linux_raw_dep, feature = "net"))]
3333
pub(crate) const ETH_P_ETHERCAT: c_int = linux_raw_sys::if_ether::ETH_P_ETHERCAT as _;
34-
#[cfg(all(linux_kernel, feature = "net"))]
34+
#[cfg(all(linux_raw_dep, feature = "net"))]
3535
pub(crate) const ETH_P_PREAUTH: c_int = linux_raw_sys::if_ether::ETH_P_PREAUTH as _;
36-
#[cfg(all(linux_kernel, feature = "net"))]
36+
#[cfg(all(linux_raw_dep, feature = "net"))]
3737
pub(crate) const ETH_P_LLDP: c_int = linux_raw_sys::if_ether::ETH_P_LLDP as _;
38-
#[cfg(all(linux_kernel, feature = "net"))]
38+
#[cfg(all(linux_raw_dep, feature = "net"))]
3939
pub(crate) const ETH_P_MRP: c_int = linux_raw_sys::if_ether::ETH_P_MRP as _;
40-
#[cfg(all(linux_kernel, feature = "net"))]
40+
#[cfg(all(linux_raw_dep, feature = "net"))]
4141
pub(crate) const ETH_P_NCSI: c_int = linux_raw_sys::if_ether::ETH_P_NCSI as _;
42-
#[cfg(all(linux_kernel, feature = "net"))]
42+
#[cfg(all(linux_raw_dep, feature = "net"))]
4343
pub(crate) const ETH_P_CFM: c_int = linux_raw_sys::if_ether::ETH_P_CFM as _;
44-
#[cfg(all(linux_kernel, feature = "net"))]
44+
#[cfg(all(linux_raw_dep, feature = "net"))]
4545
pub(crate) const ETH_P_IBOE: c_int = linux_raw_sys::if_ether::ETH_P_IBOE as _;
46-
#[cfg(all(linux_kernel, feature = "net"))]
46+
#[cfg(all(linux_raw_dep, feature = "net"))]
4747
pub(crate) const ETH_P_HSR: c_int = linux_raw_sys::if_ether::ETH_P_HSR as _;
48-
#[cfg(all(linux_kernel, feature = "net"))]
48+
#[cfg(all(linux_raw_dep, feature = "net"))]
4949
pub(crate) const ETH_P_NSH: c_int = linux_raw_sys::if_ether::ETH_P_NSH as _;
50-
#[cfg(all(linux_kernel, feature = "net"))]
50+
#[cfg(all(linux_raw_dep, feature = "net"))]
5151
pub(crate) const ETH_P_DSA_8021Q: c_int = linux_raw_sys::if_ether::ETH_P_DSA_8021Q as _;
52-
#[cfg(all(linux_kernel, feature = "net"))]
52+
#[cfg(all(linux_raw_dep, feature = "net"))]
5353
pub(crate) const ETH_P_DSA_A5PSW: c_int = linux_raw_sys::if_ether::ETH_P_DSA_A5PSW as _;
54-
#[cfg(all(linux_kernel, feature = "net"))]
54+
#[cfg(all(linux_raw_dep, feature = "net"))]
5555
pub(crate) const ETH_P_IFE: c_int = linux_raw_sys::if_ether::ETH_P_IFE as _;
56-
#[cfg(all(linux_kernel, feature = "net"))]
56+
#[cfg(all(linux_raw_dep, feature = "net"))]
5757
pub(crate) const ETH_P_CAN: c_int = linux_raw_sys::if_ether::ETH_P_CAN as _;
58-
#[cfg(all(linux_kernel, feature = "net"))]
58+
#[cfg(all(linux_raw_dep, feature = "net"))]
5959
pub(crate) const ETH_P_CANXL: c_int = linux_raw_sys::if_ether::ETH_P_CANXL as _;
60-
#[cfg(all(linux_kernel, feature = "net"))]
60+
#[cfg(all(linux_raw_dep, feature = "net"))]
6161
pub(crate) const ETH_P_XDSA: c_int = linux_raw_sys::if_ether::ETH_P_XDSA as _;
62-
#[cfg(all(linux_kernel, feature = "net"))]
62+
#[cfg(all(linux_raw_dep, feature = "net"))]
6363
pub(crate) const ETH_P_MAP: c_int = linux_raw_sys::if_ether::ETH_P_MAP as _;
64-
#[cfg(all(linux_kernel, feature = "net"))]
64+
#[cfg(all(linux_raw_dep, feature = "net"))]
6565
pub(crate) const ETH_P_MCTP: c_int = linux_raw_sys::if_ether::ETH_P_MCTP as _;
6666

6767
#[cfg(all(
@@ -89,7 +89,7 @@ pub(crate) const MSG_DONTWAIT: c_int = MSG_NONBLOCK;
8989
// `O_LARGEFILE` can be automatically set by the kernel on Linux:
9090
// <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/open.c?h=v6.13#n1423>
9191
// so libc implementations may leave it undefined or defined to zero.
92-
#[cfg(linux_kernel)]
92+
#[cfg(linux_raw_dep)]
9393
pub(crate) const O_LARGEFILE: c_int = linux_raw_sys::general::O_LARGEFILE as _;
9494

9595
// Gated under `_LARGEFILE_SOURCE` but automatically set by the kernel.
@@ -489,7 +489,8 @@ pub(super) use readwrite_pv64v2::{preadv64v2 as preadv2, pwritev64v2 as pwritev2
489489
#[cfg(feature = "fs")]
490490
#[cfg(all(
491491
linux_like,
492-
not(any(target_os = "android", target_os = "emscripten", target_env = "gnu"))
492+
linux_raw_dep,
493+
not(any(target_os = "emscripten", target_env = "gnu"))
493494
))]
494495
mod statx_flags {
495496
pub(crate) use linux_raw_sys::general::{
@@ -507,18 +508,15 @@ mod statx_flags {
507508
#[cfg(feature = "fs")]
508509
#[cfg(all(
509510
linux_like,
510-
not(any(target_os = "android", target_os = "emscripten", target_env = "gnu"))
511+
linux_raw_dep,
512+
not(any(target_os = "emscripten", target_env = "gnu"))
511513
))]
512514
pub(crate) use statx_flags::*;
513515

514516
#[cfg(feature = "fs")]
515517
#[cfg(target_os = "android")]
516518
pub(crate) use __fsid_t as fsid_t;
517519

518-
#[cfg(feature = "mm")]
519-
#[cfg(target_os = "android")]
520-
pub(crate) const MAP_DROPPABLE: c_int = bitcast!(linux_raw_sys::general::MAP_DROPPABLE);
521-
522520
// FreeBSD added `timerfd_*` in FreeBSD 14. NetBSD added then in NetBSD 10.
523521
#[cfg(all(feature = "time", any(target_os = "freebsd", target_os = "netbsd")))]
524522
syscall!(pub(crate) fn timerfd_create(

src/backend/libc/fs/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ pub(crate) mod syscalls;
1616
pub(crate) mod types;
1717

1818
// TODO: Fix linux-raw-sys to define ioctl codes for sparc.
19-
#[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))]
19+
#[cfg(all(linux_raw_dep, any(target_arch = "sparc", target_arch = "sparc64")))]
2020
pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::Opcode = 0x8008_6610;
2121

22-
#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))]
22+
#[cfg(all(
23+
linux_raw_dep,
24+
not(any(target_arch = "sparc", target_arch = "sparc64"))
25+
))]
2326
pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::Opcode =
2427
linux_raw_sys::ioctl::EXT4_IOC_RESIZE_FS as crate::ioctl::Opcode;

src/backend/libc/fs/syscalls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,7 @@ pub(crate) fn memfd_create(name: &CStr, flags: MemfdFlags) -> io::Result<OwnedFd
18401840
unsafe { ret_owned_fd(memfd_create(c_str(name), bitflags_bits!(flags))) }
18411841
}
18421842

1843-
#[cfg(linux_kernel)]
1843+
#[cfg(linux_raw_dep)]
18441844
pub(crate) fn openat2(
18451845
dirfd: BorrowedFd<'_>,
18461846
path: &CStr,
@@ -2053,9 +2053,9 @@ pub(crate) fn statx(
20532053
// doesn't represent all the known flags.
20542054
//
20552055
// [it's deprecated]: https://patchwork.kernel.org/project/linux-fsdevel/patch/[email protected]/
2056-
#[cfg(not(any(target_os = "android", target_env = "musl")))]
2056+
#[cfg(any(not(linux_raw_dep), not(target_env = "musl")))]
20572057
const STATX__RESERVED: u32 = c::STATX__RESERVED as u32;
2058-
#[cfg(any(target_os = "android", target_env = "musl"))]
2058+
#[cfg(target_env = "musl")]
20592059
const STATX__RESERVED: u32 = linux_raw_sys::general::STATX__RESERVED;
20602060
if (mask.bits() & STATX__RESERVED) == STATX__RESERVED {
20612061
return Err(io::Errno::INVAL);

src/backend/libc/io/syscalls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::fd::{AsFd as _, BorrowedFd, OwnedFd, RawFd};
1313
target_os = "wasi"
1414
)))]
1515
use crate::io::DupFlags;
16-
#[cfg(linux_kernel)]
16+
#[cfg(all(linux_kernel, not(target_os = "android")))]
1717
use crate::io::ReadWriteFlags;
1818
use crate::io::{self, FdFlags};
1919
use crate::ioctl::{IoctlOutput, Opcode};
@@ -150,7 +150,7 @@ pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>], offset: u64) ->
150150
}
151151
}
152152

153-
#[cfg(linux_kernel)]
153+
#[cfg(all(linux_kernel, not(target_os = "android")))]
154154
pub(crate) fn preadv2(
155155
fd: BorrowedFd<'_>,
156156
bufs: &mut [IoSliceMut<'_>],
@@ -170,7 +170,7 @@ pub(crate) fn preadv2(
170170
}
171171
}
172172

173-
#[cfg(linux_kernel)]
173+
#[cfg(all(linux_kernel, not(target_os = "android")))]
174174
pub(crate) fn pwritev2(
175175
fd: BorrowedFd<'_>,
176176
bufs: &[IoSlice<'_>],

src/backend/libc/io/types.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ bitflags! {
1717
}
1818
}
1919

20-
#[cfg(linux_kernel)]
20+
#[cfg(all(linux_kernel, not(target_os = "android")))]
2121
bitflags! {
2222
/// `RWF_*` constants for use with [`preadv2`] and [`pwritev2`].
2323
///
@@ -27,15 +27,15 @@ bitflags! {
2727
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
2828
pub struct ReadWriteFlags: u32 {
2929
/// `RWF_DSYNC` (since Linux 4.7)
30-
const DSYNC = linux_raw_sys::general::RWF_DSYNC;
30+
const DSYNC = libc::RWF_DSYNC as u32;
3131
/// `RWF_HIPRI` (since Linux 4.6)
32-
const HIPRI = linux_raw_sys::general::RWF_HIPRI;
32+
const HIPRI = libc::RWF_HIPRI as u32;
3333
/// `RWF_SYNC` (since Linux 4.7)
34-
const SYNC = linux_raw_sys::general::RWF_SYNC;
34+
const SYNC = libc::RWF_SYNC as u32;
3535
/// `RWF_NOWAIT` (since Linux 4.14)
36-
const NOWAIT = linux_raw_sys::general::RWF_NOWAIT;
36+
const NOWAIT = libc::RWF_NOWAIT as u32;
3737
/// `RWF_APPEND` (since Linux 4.16)
38-
const APPEND = linux_raw_sys::general::RWF_APPEND;
38+
const APPEND = libc::RWF_APPEND as u32;
3939

4040
/// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
4141
const _ = !0;

src/backend/libc/mm/types.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ bitflags! {
4444
#[cfg(linux_kernel)]
4545
const GROWSDOWN = bitcast!(c::PROT_GROWSDOWN);
4646
/// `PROT_SEM`
47-
#[cfg(linux_kernel)]
47+
#[cfg(linux_raw_dep)]
4848
const SEM = linux_raw_sys::general::PROT_SEM;
4949
/// `PROT_BTI`
50-
#[cfg(all(linux_kernel, target_arch = "aarch64"))]
50+
#[cfg(all(linux_raw_dep, target_arch = "aarch64"))]
5151
const BTI = linux_raw_sys::general::PROT_BTI;
5252
/// `PROT_MTE`
53-
#[cfg(all(linux_kernel, target_arch = "aarch64"))]
53+
#[cfg(all(linux_raw_dep, target_arch = "aarch64"))]
5454
const MTE = linux_raw_sys::general::PROT_MTE;
5555
/// `PROT_SAO`
56-
#[cfg(all(linux_kernel, any(target_arch = "powerpc", target_arch = "powerpc64")))]
56+
#[cfg(all(linux_raw_dep, any(target_arch = "powerpc", target_arch = "powerpc64")))]
5757
const SAO = linux_raw_sys::general::PROT_SAO;
5858
/// `PROT_ADI`
59-
#[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))]
59+
#[cfg(all(linux_raw_dep, any(target_arch = "sparc", target_arch = "sparc64")))]
6060
const ADI = linux_raw_sys::general::PROT_ADI;
6161

6262
/// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
@@ -252,7 +252,7 @@ bitflags! {
252252
#[cfg(any())]
253253
const UNINITIALIZED = bitcast!(c::MAP_UNINITIALIZED);
254254
/// `MAP_DROPPABLE`
255-
#[cfg(linux_kernel)]
255+
#[cfg(all(linux_kernel, not(target_os = "android")))]
256256
const DROPPABLE = bitcast!(c::MAP_DROPPABLE);
257257

258258
/// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>

src/backend/libc/net/sockopt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ use c::TCP_KEEPALIVE as TCP_KEEPIDLE;
7676
use c::TCP_KEEPIDLE;
7777
use core::mem::{size_of, MaybeUninit};
7878
use core::time::Duration;
79-
#[cfg(target_os = "linux")]
79+
#[cfg(linux_raw_dep)]
8080
use linux_raw_sys::xdp::{xdp_mmap_offsets, xdp_statistics, xdp_statistics_v1};
8181

8282
#[inline]
@@ -1088,7 +1088,7 @@ pub(crate) fn set_xdp_rx_ring_size(fd: BorrowedFd<'_>, value: u32) -> io::Result
10881088
setsockopt(fd, c::SOL_XDP, c::XDP_RX_RING, value)
10891089
}
10901090

1091-
#[cfg(target_os = "linux")]
1091+
#[cfg(linux_raw_dep)]
10921092
#[inline]
10931093
pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets> {
10941094
// The kernel will write `xdp_mmap_offsets` or `xdp_mmap_offsets_v1` to the
@@ -1175,7 +1175,7 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
11751175
}
11761176
}
11771177

1178-
#[cfg(target_os = "linux")]
1178+
#[cfg(linux_raw_dep)]
11791179
#[inline]
11801180
pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
11811181
let mut optlen = size_of::<xdp_statistics>().try_into().unwrap();

0 commit comments

Comments
 (0)