Skip to content

refactor: cfg for aio/epoll/event/mman/mod/resource/sendfile/signal #2218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 12 additions & 45 deletions src/sys/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ impl Kqueue {
}
}

#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
apple_targets,
target_os = "openbsd"
))]
#[cfg(any(freebsdlike, apple_targets, target_os = "openbsd"))]
type type_of_udata = *mut libc::c_void;
#[cfg(target_os = "netbsd")]
type type_of_udata = intptr_t;
Expand All @@ -108,9 +103,7 @@ libc_enum! {
/// Takes a descriptor as the identifier, and returns whenever one of
/// the specified exceptional conditions has occurred on the descriptor.
EVFILT_EXCEPT,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
apple_targets))]
#[cfg(any(freebsdlike, apple_targets))]
/// Establishes a file system monitor.
EVFILT_FS,
#[cfg(target_os = "freebsd")]
Expand Down Expand Up @@ -142,9 +135,7 @@ libc_enum! {
EVFILT_SIGNAL,
/// Establishes a timer and notifies when the timer expires.
EVFILT_TIMER,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
apple_targets))]
#[cfg(any(freebsdlike, apple_targets))]
/// Notifies only when explicitly requested by the user.
EVFILT_USER,
#[cfg(apple_targets)]
Expand All @@ -159,12 +150,7 @@ libc_enum! {
impl TryFrom<type_of_event_filter>
}

#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
apple_targets,
target_os = "openbsd"
))]
#[cfg(any(freebsdlike, apple_targets, target_os = "openbsd"))]
#[doc(hidden)]
pub type type_of_event_flag = u16;
#[cfg(target_os = "netbsd")]
Expand Down Expand Up @@ -244,34 +230,22 @@ libc_bitflags!(
NOTE_EXITSTATUS;
#[allow(missing_docs)]
NOTE_EXTEND;
#[cfg(any(apple_targets,
target_os = "freebsd",
target_os = "dragonfly"))]
#[cfg(any(apple_targets, freebsdlike))]
#[allow(missing_docs)]
NOTE_FFAND;
#[cfg(any(apple_targets,
target_os = "freebsd",
target_os = "dragonfly"))]
#[cfg(any(apple_targets, freebsdlike))]
#[allow(missing_docs)]
NOTE_FFCOPY;
#[cfg(any(apple_targets,
target_os = "freebsd",
target_os = "dragonfly"))]
#[cfg(any(apple_targets, freebsdlike))]
#[allow(missing_docs)]
NOTE_FFCTRLMASK;
#[cfg(any(apple_targets,
target_os = "freebsd",
target_os = "dragonfly"))]
#[cfg(any(apple_targets, freebsdlike))]
#[allow(missing_docs)]
NOTE_FFLAGSMASK;
#[cfg(any(apple_targets,
target_os = "freebsd",
target_os = "dragonfly"))]
#[cfg(any(apple_targets, freebsdlike))]
#[allow(missing_docs)]
NOTE_FFNOP;
#[cfg(any(apple_targets,
target_os = "freebsd",
target_os = "dragonfly"))]
#[cfg(any(apple_targets, freebsdlike))]
#[allow(missing_docs)]
NOTE_FFOR;
#[allow(missing_docs)]
Expand Down Expand Up @@ -314,9 +288,7 @@ libc_bitflags!(
NOTE_TRACK;
#[allow(missing_docs)]
NOTE_TRACKERR;
#[cfg(any(apple_targets,
target_os = "freebsd",
target_os = "dragonfly"))]
#[cfg(any(apple_targets, freebsdlike))]
#[allow(missing_docs)]
NOTE_TRIGGER;
#[cfg(target_os = "openbsd")]
Expand Down Expand Up @@ -434,12 +406,7 @@ pub fn kevent(
kq.kevent(changelist, eventlist, Some(timeout))
}

#[cfg(any(
apple_targets,
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd"
))]
#[cfg(any(apple_targets, freebsdlike, target_os = "openbsd"))]
type type_of_nchanges = c_int;
#[cfg(target_os = "netbsd")]
type type_of_nchanges = size_t;
Expand Down
4 changes: 2 additions & 2 deletions src/sys/mman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ libc_bitflags! {
/// The mapping is not backed by any file.
MAP_ANONYMOUS;
/// Put the mapping into the first 2GB of the process address space.
#[cfg(any(all(any(target_os = "android", target_os = "linux"),
#[cfg(any(all(linux_android,
any(target_arch = "x86", target_arch = "x86_64")),
all(target_os = "linux", target_env = "musl", any(target_arch = "x86", target_arch = "x86_64")),
all(target_os = "freebsd", target_pointer_width = "64")))]
Expand Down Expand Up @@ -140,7 +140,7 @@ libc_bitflags! {
#[cfg(any(freebsdlike, target_os = "netbsd", target_os = "openbsd"))]
MAP_HASSEMAPHORE;
/// Region grows down, like a stack.
#[cfg(any(target_os = "android", freebsdlike, target_os = "linux", target_os = "openbsd"))]
#[cfg(any(linux_android, freebsdlike, target_os = "openbsd"))]
MAP_STACK;
/// Pages in this mapping are not retained in the kernel's memory cache.
#[cfg(apple_targets)]
Expand Down
38 changes: 7 additions & 31 deletions src/sys/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Mostly platform-specific functionality
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
freebsdlike,
all(target_os = "linux", not(target_env = "uclibc")),
apple_targets,
target_os = "netbsd"
Expand Down Expand Up @@ -32,19 +31,13 @@ feature! {
pub mod fanotify;
}

#[cfg(any(
bsd,
target_os = "android",
target_os = "linux",
target_os = "redox",
target_os = "illumos",
))]
#[cfg(any(bsd, linux_android, target_os = "redox", target_os = "illumos"))]
#[cfg(feature = "ioctl")]
#[cfg_attr(docsrs, doc(cfg(feature = "ioctl")))]
#[macro_use]
pub mod ioctl;

#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
#[cfg(any(linux_android, target_os = "freebsd"))]
feature! {
#![feature = "fs"]
pub mod memfd;
Expand Down Expand Up @@ -74,10 +67,8 @@ feature! {
}

#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "linux",
linux_android,
freebsdlike,
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
Expand Down Expand Up @@ -116,15 +107,7 @@ feature! {
pub mod select;
}

#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
apple_targets,
target_os = "linux",
target_os = "solaris",
target_os = "illumos",
))]
#[cfg(any(linux_android, freebsdlike, apple_targets, solarish))]
feature! {
#![feature = "zerocopy"]
pub mod sendfile;
Expand All @@ -151,14 +134,7 @@ feature! {
pub mod stat;
}

#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
apple_targets,
target_os = "linux",
target_os = "openbsd"
))]
#[cfg(any(linux_android, freebsdlike, apple_targets, target_os = "openbsd"))]
feature! {
#![feature = "fs"]
pub mod statfs;
Expand Down
9 changes: 3 additions & 6 deletions src/sys/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ libc_enum! {
RLIMIT_LOCKS,

#[cfg(any(
target_os = "android",
linux_android,
target_os = "freebsd",
target_os = "openbsd",
target_os = "linux",
target_os = "netbsd"
))]
/// The maximum size (in bytes) which a process may lock into memory
Expand All @@ -96,11 +95,10 @@ libc_enum! {
RLIMIT_NICE,

#[cfg(any(
target_os = "android",
linux_android,
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "linux",
target_os = "aix",
))]
/// The maximum number of simultaneous processes for this user id.
Expand All @@ -111,11 +109,10 @@ libc_enum! {
/// create.
RLIMIT_NPTS,

#[cfg(any(target_os = "android",
#[cfg(any(linux_android,
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "linux",
target_os = "aix",
))]
/// When there is memory pressure and swap is available, prioritize
Expand Down
11 changes: 2 additions & 9 deletions src/sys/sendfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ use crate::Result;
///
/// For more information, see [the sendfile(2) man page.](https://man7.org/linux/man-pages/man2/sendfile.2.html) for Linux,
/// see [the sendfile(2) man page.](https://docs.oracle.com/cd/E88353_01/html/E37843/sendfile-3c.html) for Solaris.
#[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "solaris",
target_os = "illumos",
))]
#[cfg(any(linux_android, solarish))]
pub fn sendfile<F1: AsFd, F2: AsFd>(
out_fd: F1,
in_fd: F2,
Expand Down Expand Up @@ -82,9 +77,7 @@ pub fn sendfile64<F1: AsFd, F2: AsFd>(
}

cfg_if! {
if #[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
apple_targets,))] {
if #[cfg(any(freebsdlike, apple_targets))] {
use std::io::IoSlice;

#[derive(Clone, Debug)]
Expand Down
Loading