Skip to content

Commit

Permalink
Merge #1611
Browse files Browse the repository at this point in the history
1611: feature-gate most Nix functions r=rtzoeller a=asomers

Using features reduces build time and size for consumer crates.  By
default all features are enabled.

Co-authored-by: Vincent Dagonneau <vincentdagonneau@gmail.com>
Co-authored-by: Alan Somers <asomers@gmail.com>
  • Loading branch information
3 people committed Dec 21, 2021
2 parents d1c6fed + 771c710 commit 1dcc582
Show file tree
Hide file tree
Showing 37 changed files with 1,399 additions and 180 deletions.
21 changes: 15 additions & 6 deletions .cirrus.yml
Expand Up @@ -19,6 +19,8 @@ build: &BUILD
- $TOOL +$TOOLCHAIN $BUILD $ZFLAGS --target $TARGET --all-targets
- $TOOL +$TOOLCHAIN doc $ZFLAGS --no-deps --target $TARGET
- $TOOL +$TOOLCHAIN clippy $ZFLAGS --target $TARGET -- -D warnings
- if [ -z "$NOHACK" ]; then $TOOL +$TOOLCHAIN install cargo-hack; fi
- if [ -z "$NOHACK" ]; then $TOOL +$TOOLCHAIN hack $ZFLAGS check --target $TARGET --each-feature; fi

# Tests that do require executing the binaries
test: &TEST
Expand Down Expand Up @@ -50,6 +52,9 @@ task:
- cargo build --target i686-unknown-freebsd
- cargo doc --no-deps --target i686-unknown-freebsd
- cargo test --target i686-unknown-freebsd
i386_feature_script:
- . $HOME/.cargo/env
- cargo hack check --each-feature --target i686-unknown-freebsd
before_cache_script: rm -rf $CARGO_HOME/registry/index

# Test OSX in a full VM
Expand Down Expand Up @@ -201,13 +206,17 @@ task:
# https://github.com/rust-embedded/cross/issues/535
- name: iOS aarch64
env:
# cargo hack tries to invoke the iphonesimulator SDK for iOS
NOHACK: 1
TARGET: aarch64-apple-ios
# Rustup only supports cross-building from arbitrary hosts for iOS at
# 1.49.0 and above. Below that it's possible to cross-build from an OSX
# host, but OSX VMs are more expensive than Linux VMs.
TOOLCHAIN: 1.49.0
- name: iOS x86_64
env:
# cargo hack tries to invoke the iphonesimulator SDK for iOS
NOHACK: 1
TARGET: x86_64-apple-ios
TOOLCHAIN: 1.49.0
# Cross testing on powerpc fails with "undefined reference to renameat2".
Expand Down Expand Up @@ -244,11 +253,11 @@ task:
BUILD: check
name: Redox x86_64
env:
TARGET: x86_64-unknown-redox
# Redox requires a nightly compiler.
# If stuff breaks, change nightly to the date at
# https://gitlab.redox-os.org/redox-os/redox/-/blob/master/rust-toolchain
TOOLCHAIN: nightly-2021-06-15
TARGET: x86_64-unknown-redox
# Redox requires a nightly compiler.
# If stuff breaks, change nightly to the date at
# https://gitlab.redox-os.org/redox-os/redox/-/blob/master/rust-toolchain
TOOLCHAIN: nightly-2021-06-15
setup_script:
- rustup target add $TARGET
- rustup toolchain install $TOOLCHAIN --profile minimal --target $TARGET
Expand Down Expand Up @@ -310,6 +319,6 @@ task:
image: rustlang/rust:nightly
setup_script:
- cargo update -Zminimal-versions
script:
check_script:
- cargo check
before_cache_script: rm -rf $CARGO_HOME/registry/index
13 changes: 11 additions & 2 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased] - ReleaseDate
### Added

- Added fine-grained features flags. Most Nix functionality can now be
conditionally enabled. By default, all features are enabled.
(#[1611](https://github.com/nix-rust/nix/pull/1611))

### Changed
### Fixed
### Removed

## [0.23.1] - 2021-12-16

### Added
Expand All @@ -20,8 +31,6 @@ This project adheres to [Semantic Versioning](https://semver.org/).
`0..FD_SETSIZE`.
(#[1575](https://github.com/nix-rust/nix/pull/1575))

### Removed

## [0.23.0] - 2021-09-28
### Added

Expand Down
43 changes: 43 additions & 0 deletions Cargo.toml
Expand Up @@ -11,6 +11,7 @@ categories = ["os::unix-apis"]
include = ["src/**/*", "test/**/*", "LICENSE", "README.md", "CHANGELOG.md"]

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
targets = [
"x86_64-unknown-linux-gnu",
"aarch64-linux-android",
Expand All @@ -33,6 +34,48 @@ cfg-if = "1.0"
[target.'cfg(not(target_os = "redox"))'.dependencies]
memoffset = "0.6.3"

[features]
default = [
"acct", "aio", "dir", "env", "event", "features", "fs",
"hostname", "inotify", "ioctl", "kmod", "mman", "mount", "mqueue",
"net", "personality", "poll", "process", "pthread", "ptrace", "quota",
"reboot", "resource", "sched", "signal", "socket", "term", "time",
"ucontext", "uio", "users", "zerocopy",
]

acct = []
aio = []
dir = ["fs"]
env = []
event = []
features = []
fs = []
hostname = []
inotify = []
ioctl = []
kmod = []
mman = []
mount = ["uio"]
mqueue = ["fs"]
net = ["socket"]
personality = []
poll = []
pthread = []
ptrace = ["process"]
quota = []
process = []
reboot = []
resource = []
sched = ["process"]
signal = ["process"]
socket = []
term = []
time = []
ucontext = ["signal"]
uio = []
users = ["features"]
zerocopy = ["fs", "uio"]

[target.'cfg(target_os = "dragonfly")'.build-dependencies]
cc = "1"

Expand Down
43 changes: 17 additions & 26 deletions src/dir.rs
Expand Up @@ -5,6 +5,7 @@ use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
use std::ptr;
use std::ffi;
use crate::sys;
use cfg_if::cfg_if;

#[cfg(target_os = "linux")]
use libc::{dirent64 as dirent, readdir64_r as readdir_r};
Expand Down Expand Up @@ -186,34 +187,24 @@ pub enum Type {

impl Entry {
/// Returns the inode number (`d_ino`) of the underlying `dirent`.
#[cfg(any(target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "l4re",
target_os = "linux",
target_os = "macos",
target_os = "solaris"))]
pub fn ino(&self) -> u64 {
self.0.d_ino as u64
}

/// Returns the inode number (`d_fileno`) of the underlying `dirent`.
#[cfg(not(any(target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "l4re",
target_os = "linux",
target_os = "macos",
target_os = "solaris")))]
#[allow(clippy::useless_conversion)] // Not useless on all OSes
pub fn ino(&self) -> u64 {
u64::from(self.0.d_fileno)
cfg_if! {
if #[cfg(any(target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "l4re",
target_os = "linux",
target_os = "macos",
target_os = "solaris"))] {
self.0.d_ino as u64
} else {
u64::from(self.0.d_fileno)
}
}
}

/// Returns the bare file name of this directory entry without any other leading path component.
Expand Down

0 comments on commit 1dcc582

Please sign in to comment.