blob: 0b40834726dfa6b04bb7d4955c518884a8e1406c [file] [log] [blame]
From 91eed6a7cfe8fa56777cccda65527d4a9ea25801 Mon Sep 17 00:00:00 2001
From: Marcin Radomski <marcin@mradomski.pl>
Date: Fri, 15 Mar 2024 23:08:44 +0100
Subject: [PATCH 1/3] Make linux-raw-sys dependency optional
See b/331344966 for status of the efforts to upstream this.
Replace minimal set of cfg(linux_kernel) with
cfg(feature = "linux-raw-sys") to keep the build working.
With this, quite a few features just work:
cargo build --no-default-features --features \
use-libc,use-libc-auxv,std,event,mount,time,pipe,rand,stdio
---
Cargo.toml | 4 ++--
Cargo.toml.orig | 5 +++--
src/backend/libc/io/syscalls.rs | 6 +++---
src/backend/libc/io/types.rs | 2 +-
src/io/read_write.rs | 6 +++---
4 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 8184720b..8f091a9a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -213,6 +213,7 @@ features = [
"no_std",
]
default-features = false
+optional = true
[target."cfg(all(criterion, not(any(target_os = \"emscripten\", target_os = \"wasi\"))))".dev-dependencies.criterion]
version = "0.4"
@@ -239,6 +240,7 @@ features = [
"elf",
]
default-features = false
+optional = true
[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]
version = "0.2.152"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 59d4673f..715f7e8f 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -35,8 +35,9 @@ once_cell = { version = "1.5.2", optional = true }
# addition to the libc backend. The linux_raw backend is used by default. The
# libc backend can be selected via adding `--cfg=rustix_use_libc` to
# `RUSTFLAGS` or enabling the `use-libc` cargo feature.
+# Enabling only the libc backend will limit available functionality.
[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]
-linux-raw-sys = { version = "0.4.12", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] }
+linux-raw-sys = { version = "0.4.12", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"], optional = true }
libc_errno = { package = "errno", version = "0.3.8", default-features = false, optional = true }
libc = { version = "0.2.152", default-features = false, features = ["extra_traits"], optional = true }
@@ -53,7 +54,7 @@ libc = { version = "0.2.153", default-features = false, features = ["extra_trait
# Some syscalls do not have libc wrappers, such as in `io_uring`. For these,
# the libc backend uses the linux-raw-sys ABI and `libc::syscall`.
[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]
-linux-raw-sys = { version = "0.4.12", default-features = false, features = ["general", "ioctl", "no_std"] }
+linux-raw-sys = { version = "0.4.12", default-features = false, features = ["general", "ioctl", "no_std"], optional = true }
# For the libc backend on Windows, use the Winsock API in windows-sys.
[target.'cfg(windows)'.dependencies.windows-sys]
diff --git a/src/backend/libc/io/syscalls.rs b/src/backend/libc/io/syscalls.rs
index e28e6bef..da88f54b 100644
--- a/src/backend/libc/io/syscalls.rs
+++ b/src/backend/libc/io/syscalls.rs
@@ -13,7 +13,7 @@ use crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd};
target_os = "wasi"
)))]
use crate::io::DupFlags;
-#[cfg(linux_kernel)]
+#[cfg(feature = "linux-raw-sys")]
use crate::io::ReadWriteFlags;
use crate::io::{self, FdFlags};
use crate::ioctl::{IoctlOutput, RawOpcode};
@@ -139,7 +139,7 @@ pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>], offset: u64) ->
}
}
-#[cfg(linux_kernel)]
+#[cfg(feature = "linux-raw-sys")]
pub(crate) fn preadv2(
fd: BorrowedFd<'_>,
bufs: &mut [IoSliceMut<'_>],
@@ -159,7 +159,7 @@ pub(crate) fn preadv2(
}
}
-#[cfg(linux_kernel)]
+#[cfg(feature = "linux-raw-sys")]
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..a86dc261 100644
--- a/src/backend/libc/io/types.rs
+++ b/src/backend/libc/io/types.rs
@@ -17,7 +17,7 @@ bitflags! {
}
}
-#[cfg(linux_kernel)]
+#[cfg(feature = "linux-raw-sys")]
bitflags! {
/// `RWF_*` constants for use with [`preadv2`] and [`pwritev2`].
///
diff --git a/src/io/read_write.rs b/src/io/read_write.rs
index 2ed9dd71..d5296fa4 100644
--- a/src/io/read_write.rs
+++ b/src/io/read_write.rs
@@ -11,7 +11,7 @@ use core::mem::MaybeUninit;
#[cfg(not(windows))]
pub use crate::maybe_polyfill::io::{IoSlice, IoSliceMut};
-#[cfg(linux_kernel)]
+#[cfg(feature = "linux-raw-sys")]
pub use backend::io::types::ReadWriteFlags;
/// `read(fd, buf)`—Reads from a stream.
@@ -281,7 +281,7 @@ pub fn pwritev<Fd: AsFd>(fd: Fd, bufs: &[IoSlice<'_>], offset: u64) -> io::Resul
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/preadv2.2.html
-#[cfg(linux_kernel)]
+#[cfg(feature = "linux-raw-sys")]
#[inline]
pub fn preadv2<Fd: AsFd>(
fd: Fd,
@@ -300,7 +300,7 @@ pub fn preadv2<Fd: AsFd>(
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/pwritev2.2.html
-#[cfg(linux_kernel)]
+#[cfg(feature = "linux-raw-sys")]
#[inline]
pub fn pwritev2<Fd: AsFd>(
fd: Fd,
--
2.44.0.291.gc1ea87d7ee-goog