Skip to content

Add more cfg aliases #2205

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 9 commits into from
Nov 25, 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
6 changes: 6 additions & 0 deletions CONVENTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ impl SigSet {

When creating newtypes, we use Rust's `CamelCase` type naming convention.

## cfg gates

When creating operating-system-specific functionality, we gate it by
`#[cfg(target_os = ...)]`. If more than one operating system is affected, we
prefer to use the cfg aliases defined in build.rs, like `#[cfg(bsd)]`.

## Bitflags

Many C functions have flags parameters that are combined from constants using
Expand Down
12 changes: 12 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@ use cfg_aliases::cfg_aliases;

fn main() {
cfg_aliases! {
android: { target_os = "android" },
dragonfly: { target_os = "dragonfly" },
ios: { target_os = "ios" },
freebsd: { target_os = "freebsd" },
illumos: { target_os = "illumos" },
linux: { target_os = "linux" },
macos: { target_os = "macos" },
netbsd: { target_os = "netbsd" },
openbsd: { target_os = "openbsd" },
solarish: { target_os = "solaris" },
watchos: { target_os = "watchos" },
tvos: { target_os = "tvos" },
apple_targets: { any(ios, macos, watchos, tvos) },
bsd: { any(freebsd, dragonfly, netbsd, openbsd, apple_targets) },
linux_android: { any(android, linux) },
freebsdlike: { any(dragonfly, freebsd) },
solarish: { any(illumos, solaris) },
}
}
183 changes: 27 additions & 156 deletions src/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cfg_if! {
unsafe fn errno_location() -> *mut c_int {
unsafe { libc::__errno_location() }
}
} else if #[cfg(any(target_os = "illumos", target_os = "solaris"))] {
} else if #[cfg(solarish)] {
unsafe fn errno_location() -> *mut c_int {
unsafe { libc::___errno() }
}
Expand Down Expand Up @@ -501,7 +501,7 @@ fn desc(errno: Errno) -> &'static str {
))]
EBADMSG => "Not a data message",

#[cfg(any(target_os = "illumos", target_os = "solaris"))]
#[cfg(solarish)]
EBADMSG => "Trying to read unreadable message",

#[cfg(any(
Expand Down Expand Up @@ -745,7 +745,7 @@ fn desc(errno: Errno) -> &'static str {
))]
EOWNERDEAD => "Owner died",

#[cfg(any(target_os = "illumos", target_os = "solaris"))]
#[cfg(solarish)]
EOWNERDEAD => "Process died with lock",

#[cfg(any(
Expand All @@ -756,7 +756,7 @@ fn desc(errno: Errno) -> &'static str {
))]
ENOTRECOVERABLE => "State not recoverable",

#[cfg(any(target_os = "illumos", target_os = "solaris"))]
#[cfg(solarish)]
ENOTRECOVERABLE => "Lock is not recoverable",

#[cfg(any(
Expand Down Expand Up @@ -794,25 +794,10 @@ fn desc(errno: Errno) -> &'static str {
#[cfg(target_os = "freebsd")]
ECAPMODE => "Not permitted in capability mode",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd"
))]
#[cfg(bsd)]
ENEEDAUTH => "Need authenticator",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd",
target_os = "redox",
target_os = "illumos",
target_os = "solaris"
))]
#[cfg(any(bsd, target_os = "redox", solarish))]
EOVERFLOW => "Value too large to be stored in data type",

#[cfg(any(
Expand All @@ -825,36 +810,13 @@ fn desc(errno: Errno) -> &'static str {
))]
EILSEQ => "Illegal byte sequence",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd",
target_os = "haiku"
))]
#[cfg(any(bsd, target_os = "haiku"))]
ENOATTR => "Attribute not found",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd",
target_os = "redox",
target_os = "haiku"
))]
#[cfg(any(bsd, target_os = "redox", target_os = "haiku"))]
EBADMSG => "Bad message",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd",
target_os = "redox",
target_os = "haiku"
))]
#[cfg(any(bsd, target_os = "redox", target_os = "haiku"))]
EPROTO => "Protocol error",

#[cfg(any(
Expand All @@ -873,46 +835,17 @@ fn desc(errno: Errno) -> &'static str {
))]
EOWNERDEAD => "Previous owner died",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd",
target_os = "aix",
target_os = "illumos",
target_os = "solaris",
target_os = "haiku"
))]
#[cfg(any(bsd, target_os = "aix", solarish, target_os = "haiku"))]
ENOTSUP => "Operation not supported",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "aix",
target_os = "openbsd",
target_os = "netbsd"
))]
#[cfg(any(bsd, target_os = "aix"))]
EPROCLIM => "Too many processes",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "aix",
target_os = "openbsd",
target_os = "netbsd",
target_os = "redox"
))]
#[cfg(any(bsd, target_os = "aix", target_os = "redox"))]
EUSERS => "Too many users",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd",
bsd,
target_os = "redox",
target_os = "aix",
target_os = "illumos",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another place where we can use solarish

Expand All @@ -922,11 +855,7 @@ fn desc(errno: Errno) -> &'static str {
EDQUOT => "Disc quota exceeded",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd",
bsd,
target_os = "redox",
target_os = "aix",
target_os = "illumos",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be: solarish

Expand All @@ -935,89 +864,31 @@ fn desc(errno: Errno) -> &'static str {
))]
ESTALE => "Stale NFS file handle",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "aix",
target_os = "openbsd",
target_os = "netbsd",
target_os = "redox"
))]
#[cfg(any(bsd, target_os = "aix", target_os = "redox"))]
EREMOTE => "Too many levels of remote in path",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd"
))]
#[cfg(bsd)]
EBADRPC => "RPC struct is bad",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd"
))]
#[cfg(bsd)]
ERPCMISMATCH => "RPC version wrong",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd"
))]
#[cfg(bsd)]
EPROGUNAVAIL => "RPC prog. not avail",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd"
))]
#[cfg(bsd)]
EPROGMISMATCH => "Program version wrong",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd"
))]
#[cfg(bsd)]
EPROCUNAVAIL => "Bad procedure for program",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd"
))]
#[cfg(bsd)]
EFTYPE => "Inappropriate file type or format",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "openbsd",
target_os = "netbsd"
))]
#[cfg(bsd)]
EAUTH => "Authentication error",

#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
apple_targets,
target_os = "aix",
target_os = "openbsd",
target_os = "netbsd",
target_os = "redox"
))]
#[cfg(any(bsd, target_os = "aix", target_os = "redox"))]
ECANCELED => "Operation canceled",

#[cfg(apple_targets)]
Expand Down Expand Up @@ -1099,13 +970,13 @@ fn desc(errno: Errno) -> &'static str {
#[cfg(target_os = "dragonfly")]
EASYNC => "Async",

#[cfg(any(target_os = "illumos", target_os = "solaris"))]
#[cfg(solarish)]
EDEADLOCK => "Resource deadlock would occur",

#[cfg(any(target_os = "illumos", target_os = "solaris"))]
#[cfg(solarish)]
ELOCKUNMAPPED => "Locked lock was unmapped",

#[cfg(any(target_os = "illumos", target_os = "solaris"))]
#[cfg(solarish)]
ENOTACTIVE => "Facility is not active",
}
}
Expand Down Expand Up @@ -2688,7 +2559,7 @@ mod consts {
}
}

#[cfg(any(target_os = "illumos", target_os = "solaris"))]
#[cfg(solarish)]
mod consts {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(i32)]
Expand Down
Loading