Skip to content

Commit 76aff5e

Browse files
authored
Fix Android build: enable linux-raw-sys and exclude Android-unsupported Linux userspace features (#1528)
* Fix tests: exclude Android from preadv2/pwritev2 tests that require RWF_* constants * Fix Android build by enabling linux_raw_dep and excluding unsupported features * Enabled target_os=android for libc backend
1 parent bb00248 commit 76aff5e

File tree

8 files changed

+16
-15
lines changed

8 files changed

+16
-15
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ libc = { version = "0.2.177", default-features = false, optional = true }
4545
libc_errno = { package = "errno", version = "0.3.10", default-features = false }
4646
libc = { version = "0.2.177", default-features = false }
4747

48-
# Additional dependencies for Linux with the libc backend:
48+
# Additional dependencies for Linux and Android with the libc backend:
4949
#
5050
# Some syscalls do not have libc wrappers, such as in `io_uring`. For these,
5151
# the libc backend uses the linux-raw-sys ABI and `libc::syscall`.
52-
[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]
52+
[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]
5353
linux-raw-sys = { version = "0.11.0", default-features = false, features = ["general", "ioctl", "no_std"] }
5454

5555
# For the libc backend on Windows, use the Winsock API in windows-sys.

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn main() {
117117
|| arch.starts_with("mips"))
118118
&& !rustix_use_experimental_asm);
119119
if libc {
120-
if os != "android" && os == "linux" && !cfg_no_linux_raw {
120+
if (os == "linux" || os == "android") && !cfg_no_linux_raw {
121121
use_feature("linux_raw_dep");
122122
}
123123

src/backend/libc/c.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ mod statx_flags {
503503
linux_like,
504504
linux_raw_dep,
505505
not(any(
506+
target_os = "android",
506507
target_os = "emscripten",
507508
target_env = "gnu",
508509
all(target_arch = "loongarch64", target_env = "musl")

src/backend/libc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub(crate) mod event;
109109
#[cfg(feature = "fs")]
110110
pub(crate) mod fs;
111111
pub(crate) mod io;
112-
#[cfg(linux_kernel)]
112+
#[cfg(all(linux_kernel, not(target_os = "android")))]
113113
#[cfg(feature = "io_uring")]
114114
pub(crate) mod io_uring;
115115
#[cfg(not(any(

src/backend/libc/net/sockopt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ use c::TCP_KEEPALIVE as TCP_KEEPIDLE;
8282
use c::TCP_KEEPIDLE;
8383
use core::mem::{size_of, MaybeUninit};
8484
use core::time::Duration;
85-
#[cfg(linux_raw_dep)]
85+
#[cfg(all(linux_raw_dep, target_os = "linux"))]
8686
use linux_raw_sys::xdp::{xdp_mmap_offsets, xdp_statistics, xdp_statistics_v1};
8787

8888
#[inline]
@@ -1153,7 +1153,7 @@ pub(crate) fn set_xdp_rx_ring_size(fd: BorrowedFd<'_>, value: u32) -> io::Result
11531153
setsockopt(fd, c::SOL_XDP, c::XDP_RX_RING, value)
11541154
}
11551155

1156-
#[cfg(linux_raw_dep)]
1156+
#[cfg(all(linux_raw_dep, target_os = "linux"))]
11571157
#[inline]
11581158
pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets> {
11591159
// 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<XdpMmapOffsets>
12401240
}
12411241
}
12421242

1243-
#[cfg(linux_raw_dep)]
1243+
#[cfg(all(linux_raw_dep, target_os = "linux"))]
12441244
#[inline]
12451245
pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
12461246
let mut optlen = size_of::<xdp_statistics>().try_into().unwrap();

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub mod ffi;
225225
#[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
226226
pub mod fs;
227227
pub mod io;
228-
#[cfg(linux_kernel)]
228+
#[cfg(all(linux_kernel, not(target_os = "android")))]
229229
#[cfg(feature = "io_uring")]
230230
#[cfg_attr(docsrs, doc(cfg(feature = "io_uring")))]
231231
pub mod io_uring;

src/net/sockopt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,7 @@ pub fn set_xdp_rx_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
17741774
/// - [Linux]
17751775
///
17761776
/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html
1777-
#[cfg(linux_raw_dep)]
1777+
#[cfg(all(linux_raw_dep, target_os = "linux"))]
17781778
#[doc(alias = "XDP_MMAP_OFFSETS")]
17791779
pub fn xdp_mmap_offsets<Fd: AsFd>(fd: Fd) -> io::Result<XdpMmapOffsets> {
17801780
backend::net::sockopt::xdp_mmap_offsets(fd.as_fd())
@@ -1786,7 +1786,7 @@ pub fn xdp_mmap_offsets<Fd: AsFd>(fd: Fd) -> io::Result<XdpMmapOffsets> {
17861786
/// - [Linux]
17871787
///
17881788
/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-statistics-getsockopt
1789-
#[cfg(linux_raw_dep)]
1789+
#[cfg(all(linux_raw_dep, target_os = "linux"))]
17901790
#[doc(alias = "XDP_STATISTICS")]
17911791
pub fn xdp_statistics<Fd: AsFd>(fd: Fd) -> io::Result<XdpStatistics> {
17921792
backend::net::sockopt::xdp_statistics(fd.as_fd())

tests/io/read_write.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn test_rwf_values() {
202202
);
203203
}
204204

205-
#[cfg(linux_raw_dep)]
205+
#[cfg(all(linux_raw_dep, not(target_os = "android")))]
206206
#[cfg(feature = "fs")]
207207
#[test]
208208
fn test_pwritev2() {
@@ -256,7 +256,7 @@ fn test_pwritev2() {
256256
assert_eq!(&buf, b"world");
257257
}
258258

259-
#[cfg(linux_raw_dep)]
259+
#[cfg(all(linux_raw_dep, not(target_os = "android")))]
260260
#[cfg(all(feature = "net", feature = "pipe"))]
261261
#[test]
262262
fn test_preadv2_nowait() {
@@ -308,7 +308,7 @@ fn test_preadv2_nowait() {
308308
fn test_p_offsets() {
309309
use rustix::fs::{openat, Mode, OFlags, CWD};
310310
use rustix::io::{pread, preadv, pwrite, pwritev};
311-
#[cfg(linux_raw_dep)]
311+
#[cfg(all(linux_raw_dep, not(target_os = "android")))]
312312
use rustix::io::{preadv2, pwritev2, ReadWriteFlags};
313313

314314
let mut buf = [0_u8; 5];
@@ -343,7 +343,7 @@ fn test_p_offsets() {
343343
Ok(_) => {}
344344
Err(e) => panic!("pwritev failed with an unexpected error: {:?}", e),
345345
}
346-
#[cfg(linux_raw_dep)]
346+
#[cfg(all(linux_raw_dep, not(target_os = "android")))]
347347
{
348348
match preadv2(
349349
&f,
@@ -393,7 +393,7 @@ fn test_p_offsets() {
393393
Err(e) => panic!("pwritev failed with an unexpected error: {:?}", e),
394394
}
395395
}
396-
#[cfg(linux_raw_dep)]
396+
#[cfg(all(linux_raw_dep, not(target_os = "android")))]
397397
{
398398
match preadv2(
399399
&f,

0 commit comments

Comments
 (0)