• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 91eed6a7cfe8fa56777cccda65527d4a9ea25801 Mon Sep 17 00:00:00 2001
2From: Marcin Radomski <marcin@mradomski.pl>
3Date: Fri, 15 Mar 2024 23:08:44 +0100
4Subject: [PATCH 1/3] Make linux-raw-sys dependency optional
5
6See b/331344966 for status of the efforts to upstream this.
7
8Replace minimal set of cfg(linux_kernel) with
9cfg(feature = "linux-raw-sys") to keep the build working.
10
11With this, quite a few features just work:
12
13  cargo build --no-default-features --features \
14      use-libc,use-libc-auxv,std,event,mount,time,pipe,rand,stdio
15---
16 Cargo.toml                      | 4 ++--
17 Cargo.toml.orig                 | 5 +++--
18 src/backend/libc/io/syscalls.rs | 6 +++---
19 src/backend/libc/io/types.rs    | 2 +-
20 src/io/read_write.rs            | 6 +++---
21 4 files changed, 10 insertions(+), 9 deletions(-)
22
23diff --git a/Cargo.toml b/Cargo.toml
24index 8184720b..8f091a9a 100644
25--- a/Cargo.toml
26+++ b/Cargo.toml
27@@ -213,6 +213,7 @@ features = [
28     "no_std",
29 ]
30 default-features = false
31+optional = true
32
33 [target."cfg(all(criterion, not(any(target_os = \"emscripten\", target_os = \"wasi\"))))".dev-dependencies.criterion]
34 version = "0.4"
35@@ -239,6 +240,7 @@ features = [
36     "elf",
37 ]
38 default-features = false
39+optional = true
40
41 [target."cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = \"linux\", target_endian = \"little\", any(target_arch = \"arm\", all(target_arch = \"aarch64\", target_pointer_width = \"64\"), target_arch = \"riscv64\", all(rustix_use_experimental_asm, target_arch = \"powerpc64\"), 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.libc]
42 version = "0.2.152"
43diff --git a/Cargo.toml.orig b/Cargo.toml.orig
44index 59d4673f..715f7e8f 100644
45--- a/Cargo.toml.orig
46+++ b/Cargo.toml.orig
47@@ -35,8 +35,9 @@ once_cell = { version = "1.5.2", optional = true }
48 # addition to the libc backend. The linux_raw backend is used by default. The
49 # libc backend can be selected via adding `--cfg=rustix_use_libc` to
50 # `RUSTFLAGS` or enabling the `use-libc` cargo feature.
51+# Enabling only the libc backend will limit available functionality.
52 [target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), 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]
53-linux-raw-sys = { version = "0.4.12", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] }
54+linux-raw-sys = { version = "0.4.12", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"], optional = true }
55 libc_errno = { package = "errno", version = "0.3.8", default-features = false, optional = true }
56 libc = { version = "0.2.152", default-features = false, features = ["extra_traits"], optional = true }
57
58@@ -53,7 +54,7 @@ libc = { version = "0.2.153", default-features = false, features = ["extra_trait
59 # Some syscalls do not have libc wrappers, such as in `io_uring`. For these,
60 # the libc backend uses the linux-raw-sys ABI and `libc::syscall`.
61 [target.'cfg(all(any(target_os = "android", target_os = "linux"), any(rustix_use_libc, miri, not(all(target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), 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]
62-linux-raw-sys = { version = "0.4.12", default-features = false, features = ["general", "ioctl", "no_std"] }
63+linux-raw-sys = { version = "0.4.12", default-features = false, features = ["general", "ioctl", "no_std"], optional = true }
64
65 # For the libc backend on Windows, use the Winsock API in windows-sys.
66 [target.'cfg(windows)'.dependencies.windows-sys]
67diff --git a/src/backend/libc/io/syscalls.rs b/src/backend/libc/io/syscalls.rs
68index e28e6bef..da88f54b 100644
69--- a/src/backend/libc/io/syscalls.rs
70+++ b/src/backend/libc/io/syscalls.rs
71@@ -13,7 +13,7 @@ use crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd};
72     target_os = "wasi"
73 )))]
74 use crate::io::DupFlags;
75-#[cfg(linux_kernel)]
76+#[cfg(feature = "linux-raw-sys")]
77 use crate::io::ReadWriteFlags;
78 use crate::io::{self, FdFlags};
79 use crate::ioctl::{IoctlOutput, RawOpcode};
80@@ -139,7 +139,7 @@ pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>], offset: u64) ->
81     }
82 }
83
84-#[cfg(linux_kernel)]
85+#[cfg(feature = "linux-raw-sys")]
86 pub(crate) fn preadv2(
87     fd: BorrowedFd<'_>,
88     bufs: &mut [IoSliceMut<'_>],
89@@ -159,7 +159,7 @@ pub(crate) fn preadv2(
90     }
91 }
92
93-#[cfg(linux_kernel)]
94+#[cfg(feature = "linux-raw-sys")]
95 pub(crate) fn pwritev2(
96     fd: BorrowedFd<'_>,
97     bufs: &[IoSlice<'_>],
98diff --git a/src/backend/libc/io/types.rs b/src/backend/libc/io/types.rs
99index 510206f9..a86dc261 100644
100--- a/src/backend/libc/io/types.rs
101+++ b/src/backend/libc/io/types.rs
102@@ -17,7 +17,7 @@ bitflags! {
103     }
104 }
105
106-#[cfg(linux_kernel)]
107+#[cfg(feature = "linux-raw-sys")]
108 bitflags! {
109     /// `RWF_*` constants for use with [`preadv2`] and [`pwritev2`].
110     ///
111diff --git a/src/io/read_write.rs b/src/io/read_write.rs
112index 2ed9dd71..d5296fa4 100644
113--- a/src/io/read_write.rs
114+++ b/src/io/read_write.rs
115@@ -11,7 +11,7 @@ use core::mem::MaybeUninit;
116 #[cfg(not(windows))]
117 pub use crate::maybe_polyfill::io::{IoSlice, IoSliceMut};
118
119-#[cfg(linux_kernel)]
120+#[cfg(feature = "linux-raw-sys")]
121 pub use backend::io::types::ReadWriteFlags;
122
123 /// `read(fd, buf)`—Reads from a stream.
124@@ -281,7 +281,7 @@ pub fn pwritev<Fd: AsFd>(fd: Fd, bufs: &[IoSlice<'_>], offset: u64) -> io::Resul
125 ///  - [Linux]
126 ///
127 /// [Linux]: https://man7.org/linux/man-pages/man2/preadv2.2.html
128-#[cfg(linux_kernel)]
129+#[cfg(feature = "linux-raw-sys")]
130 #[inline]
131 pub fn preadv2<Fd: AsFd>(
132     fd: Fd,
133@@ -300,7 +300,7 @@ pub fn preadv2<Fd: AsFd>(
134 ///  - [Linux]
135 ///
136 /// [Linux]: https://man7.org/linux/man-pages/man2/pwritev2.2.html
137-#[cfg(linux_kernel)]
138+#[cfg(feature = "linux-raw-sys")]
139 #[inline]
140 pub fn pwritev2<Fd: AsFd>(
141     fd: Fd,
142--
1432.44.0.291.gc1ea87d7ee-goog
144
145