Skip to content

Commit 1dcc582

Browse files
bors[bot]vdagonneauasomers
authored
Merge #1611
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 <[email protected]> Co-authored-by: Alan Somers <[email protected]>
2 parents d1c6fed + 771c710 commit 1dcc582

37 files changed

+1399
-180
lines changed

.cirrus.yml

+15-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ build: &BUILD
1919
- $TOOL +$TOOLCHAIN $BUILD $ZFLAGS --target $TARGET --all-targets
2020
- $TOOL +$TOOLCHAIN doc $ZFLAGS --no-deps --target $TARGET
2121
- $TOOL +$TOOLCHAIN clippy $ZFLAGS --target $TARGET -- -D warnings
22+
- if [ -z "$NOHACK" ]; then $TOOL +$TOOLCHAIN install cargo-hack; fi
23+
- if [ -z "$NOHACK" ]; then $TOOL +$TOOLCHAIN hack $ZFLAGS check --target $TARGET --each-feature; fi
2224

2325
# Tests that do require executing the binaries
2426
test: &TEST
@@ -50,6 +52,9 @@ task:
5052
- cargo build --target i686-unknown-freebsd
5153
- cargo doc --no-deps --target i686-unknown-freebsd
5254
- cargo test --target i686-unknown-freebsd
55+
i386_feature_script:
56+
- . $HOME/.cargo/env
57+
- cargo hack check --each-feature --target i686-unknown-freebsd
5358
before_cache_script: rm -rf $CARGO_HOME/registry/index
5459

5560
# Test OSX in a full VM
@@ -201,13 +206,17 @@ task:
201206
# https://github.com/rust-embedded/cross/issues/535
202207
- name: iOS aarch64
203208
env:
209+
# cargo hack tries to invoke the iphonesimulator SDK for iOS
210+
NOHACK: 1
204211
TARGET: aarch64-apple-ios
205212
# Rustup only supports cross-building from arbitrary hosts for iOS at
206213
# 1.49.0 and above. Below that it's possible to cross-build from an OSX
207214
# host, but OSX VMs are more expensive than Linux VMs.
208215
TOOLCHAIN: 1.49.0
209216
- name: iOS x86_64
210217
env:
218+
# cargo hack tries to invoke the iphonesimulator SDK for iOS
219+
NOHACK: 1
211220
TARGET: x86_64-apple-ios
212221
TOOLCHAIN: 1.49.0
213222
# Cross testing on powerpc fails with "undefined reference to renameat2".
@@ -244,11 +253,11 @@ task:
244253
BUILD: check
245254
name: Redox x86_64
246255
env:
247-
TARGET: x86_64-unknown-redox
248-
# Redox requires a nightly compiler.
249-
# If stuff breaks, change nightly to the date at
250-
# https://gitlab.redox-os.org/redox-os/redox/-/blob/master/rust-toolchain
251-
TOOLCHAIN: nightly-2021-06-15
256+
TARGET: x86_64-unknown-redox
257+
# Redox requires a nightly compiler.
258+
# If stuff breaks, change nightly to the date at
259+
# https://gitlab.redox-os.org/redox-os/redox/-/blob/master/rust-toolchain
260+
TOOLCHAIN: nightly-2021-06-15
252261
setup_script:
253262
- rustup target add $TARGET
254263
- rustup toolchain install $TOOLCHAIN --profile minimal --target $TARGET
@@ -310,6 +319,6 @@ task:
310319
image: rustlang/rust:nightly
311320
setup_script:
312321
- cargo update -Zminimal-versions
313-
script:
322+
check_script:
314323
- cargo check
315324
before_cache_script: rm -rf $CARGO_HOME/registry/index

CHANGELOG.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](https://semver.org/).
55

6+
## [Unreleased] - ReleaseDate
7+
### Added
8+
9+
- Added fine-grained features flags. Most Nix functionality can now be
10+
conditionally enabled. By default, all features are enabled.
11+
(#[1611](https://github.com/nix-rust/nix/pull/1611))
12+
13+
### Changed
14+
### Fixed
15+
### Removed
16+
617
## [0.23.1] - 2021-12-16
718

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

23-
### Removed
24-
2534
## [0.23.0] - 2021-09-28
2635
### Added
2736

Cargo.toml

+43
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ categories = ["os::unix-apis"]
1111
include = ["src/**/*", "test/**/*", "LICENSE", "README.md", "CHANGELOG.md"]
1212

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

37+
[features]
38+
default = [
39+
"acct", "aio", "dir", "env", "event", "features", "fs",
40+
"hostname", "inotify", "ioctl", "kmod", "mman", "mount", "mqueue",
41+
"net", "personality", "poll", "process", "pthread", "ptrace", "quota",
42+
"reboot", "resource", "sched", "signal", "socket", "term", "time",
43+
"ucontext", "uio", "users", "zerocopy",
44+
]
45+
46+
acct = []
47+
aio = []
48+
dir = ["fs"]
49+
env = []
50+
event = []
51+
features = []
52+
fs = []
53+
hostname = []
54+
inotify = []
55+
ioctl = []
56+
kmod = []
57+
mman = []
58+
mount = ["uio"]
59+
mqueue = ["fs"]
60+
net = ["socket"]
61+
personality = []
62+
poll = []
63+
pthread = []
64+
ptrace = ["process"]
65+
quota = []
66+
process = []
67+
reboot = []
68+
resource = []
69+
sched = ["process"]
70+
signal = ["process"]
71+
socket = []
72+
term = []
73+
time = []
74+
ucontext = ["signal"]
75+
uio = []
76+
users = ["features"]
77+
zerocopy = ["fs", "uio"]
78+
3679
[target.'cfg(target_os = "dragonfly")'.build-dependencies]
3780
cc = "1"
3881

src/dir.rs

+17-26
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
55
use std::ptr;
66
use std::ffi;
77
use crate::sys;
8+
use cfg_if::cfg_if;
89

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

187188
impl Entry {
188189
/// Returns the inode number (`d_ino`) of the underlying `dirent`.
189-
#[cfg(any(target_os = "android",
190-
target_os = "emscripten",
191-
target_os = "fuchsia",
192-
target_os = "haiku",
193-
target_os = "illumos",
194-
target_os = "ios",
195-
target_os = "l4re",
196-
target_os = "linux",
197-
target_os = "macos",
198-
target_os = "solaris"))]
199-
pub fn ino(&self) -> u64 {
200-
self.0.d_ino as u64
201-
}
202-
203-
/// Returns the inode number (`d_fileno`) of the underlying `dirent`.
204-
#[cfg(not(any(target_os = "android",
205-
target_os = "emscripten",
206-
target_os = "fuchsia",
207-
target_os = "haiku",
208-
target_os = "illumos",
209-
target_os = "ios",
210-
target_os = "l4re",
211-
target_os = "linux",
212-
target_os = "macos",
213-
target_os = "solaris")))]
214190
#[allow(clippy::useless_conversion)] // Not useless on all OSes
215191
pub fn ino(&self) -> u64 {
216-
u64::from(self.0.d_fileno)
192+
cfg_if! {
193+
if #[cfg(any(target_os = "android",
194+
target_os = "emscripten",
195+
target_os = "fuchsia",
196+
target_os = "haiku",
197+
target_os = "illumos",
198+
target_os = "ios",
199+
target_os = "l4re",
200+
target_os = "linux",
201+
target_os = "macos",
202+
target_os = "solaris"))] {
203+
self.0.d_ino as u64
204+
} else {
205+
u64::from(self.0.d_fileno)
206+
}
207+
}
217208
}
218209

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

0 commit comments

Comments
 (0)