Skip to content

Commit 4a67af2

Browse files
Merge pull request #58 from andrewdavidmackenzie/rusage_under_feature_flag
Put module `pid_rusage` under a feature flag. Add flags to Cargo and describe in README.md
2 parents 3437b90 + 38919f3 commit 4a67af2

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ edition = "2018"
1313
errno = "0.2.5"
1414
libc = "^0.2.62"
1515

16+
[features]
17+
default = ["macosx_10_9"]
18+
macosx_10_7 = []
19+
macosx_10_9 = ["macosx_10_7"]
20+
1621
[lib]
1722
name = "libproc"
1823
path = "src/lib.rs"

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub fn pidfdinfo<T: PIDFDInfo>(pid : i32, fd: i32) -> Result<T, String> (macos)
6363
```
6464

6565
## PID Resource Usage related
66+
(Added in Mac OS X 10.9 - under "macosx_10_9" feature)
6667
```
6768
pub fn pidrusage<T: PIDRUsage>(pid : i32) -> Result<T, String> (macos)
6869
```
@@ -80,6 +81,25 @@ pub fn kmsgbuf() -> Result<String, String>
8081
# Platforms
8182
Mac OS X (10.5 and above) and Linux.
8283

84+
## Mac OS X Versions
85+
Calls were aded to libproc in Mac OS X 10.7 and again in 10.9.
86+
This library can be compiled to not include those calls by using rust `features`
87+
to enable/disable support for those versions.
88+
89+
The default build is for Mac OS 10.9 or later. See:
90+
```toml
91+
[features]
92+
default = ["macosx_10_9"]
93+
macosx_10_7 = []
94+
macosx_10_9 = ["macosx_10_7"]
95+
```
96+
in Cargo.toml
97+
98+
To build for versions prior to Mac OS 10.7 disable the default features by passing --no-default-features to cargo.
99+
100+
To build for Mac OS X 10.7 (or 10.8) you can enable that feature alone using
101+
--no-default-features --features "macosx_10_7"
102+
83103
# Build and Test
84104
`cargo test` should build and test as usual for rust projects.
85105

src/libproc/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ pub mod task_info;
1919
/// BSD specific information - very MacOS specific
2020
pub mod bsd_info;
2121
#[cfg(target_os = "macos")]
22-
/// Information about Process Resource Usage
22+
#[cfg(feature = "macosx_10_9")]
23+
/// Information about Process Resource Usage - added in Mac OS X 10.9
2324
pub mod pid_rusage;
2425
/// Information about Files and File Descriptors used by processes
2526
#[cfg(target_os = "macos")]

src/libproc/pid_rusage.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern {
4646
/// }
4747
/// ```
4848
#[cfg(target_os = "macos")]
49+
#[cfg(feature = "macosx_10_9")]
4950
pub fn pidrusage<T: PIDRUsage>(pid : i32) -> Result<T, String> {
5051
let flavor = T::flavor() as i32;
5152
let mut pidrusage = T::default();

0 commit comments

Comments
 (0)