From 3351c5cf7de42556c87ee949531865919527652d Mon Sep 17 00:00:00 2001 From: Andrew Mackenzie Date: Thu, 12 Dec 2024 22:59:43 +0100 Subject: [PATCH 1/4] Revert "Update minimum rust version to 1.82.0" This reverts commit 373a0e5fa04d35f50dccd7b8c8b75fb67ab9f44a. --- .github/workflows/clippy_build_test.yml | 4 +-- Cargo.toml | 2 +- Makefile | 2 +- README.md | 41 ++++++------------------- 4 files changed, 14 insertions(+), 35 deletions(-) diff --git a/.github/workflows/clippy_build_test.yml b/.github/workflows/clippy_build_test.yml index e94a3d33..ae3e8d7e 100644 --- a/.github/workflows/clippy_build_test.yml +++ b/.github/workflows/clippy_build_test.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest, macos-13, macos-14, macos-15 ] - rust: [ stable, beta, 1.82.0 ] # Minimum Rust Version Supported = 1.82.0 + rust: [ stable, beta, 1.72.0 ] # Minimum Rust Version Supported = 1.72.0 experimental: [ false ] include: - os: ubuntu-latest @@ -35,7 +35,7 @@ jobs: rust: nightly experimental: true - os: macos-13 - rust: 1.82.0 + rust: 1.72.0 experimental: true - os: macos-14 rust: nightly diff --git a/Cargo.toml b/Cargo.toml index bb375045..4b84243e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ documentation = "https://docs.rs/libproc/latest/libproc" readme = "README.md" license = "MIT" edition = "2018" -rust-version = "1.82" +rust-version = "1.72" [dependencies] errno = "0.3.0" diff --git a/Makefile b/Makefile index a48a7011..6051c4da 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -RUST_MIN_VERSION := 1.82.0 +RUST_MIN_VERSION := 1.72.0 ACT := $(shell command -v act 2> /dev/null) UNAME := $(shell uname -s) diff --git a/README.md b/README.md index 72940b56..ac0770c0 100644 --- a/README.md +++ b/README.md @@ -2,23 +2,20 @@ [![codecov](https://codecov.io/gh/andrewdavidmackenzie/libproc-rs/branch/master/graph/badge.svg)](https://codecov.io/gh/andrewdavidmackenzie/libproc-rs) # libproc-rs - This is a library for getting information about running processes for Mac OS X and Linux. Add it to your project's `Cargo.toml`: - ```toml libproc = "0.14.4" ``` And then use it in your code: - ```rust use libproc::libproc::proc_pid; match proc_pid::pidpath(pid) { -Ok(path) => println ! ("PID {}: has path {}", pid, path), -Err(err) => writeln ! ( & mut std::io::stderr(), "Error: {}", err).unwrap() + Ok(path) => println!("PID {}: has path {}", pid, path), + Err(err) => writeln!(&mut std::io::stderr(), "Error: {}", err).unwrap() } ``` @@ -29,35 +26,28 @@ You can find the browseable docs for the latest release on [docs.rs](https://doc NOTE: `master` branch (code and docs) can differ from those docs prior to a new release. # Minimum rust version - The minimum rust version required, by version: - -* libproc-rs: 0.14.6 --> 1.74.1 +* libproc-rs: 0.14.6 --> 1.74.1 * libproc-rs: 0.14.7 --> 1.72.0 -* libproc-rs: 0.14.10 --> 1.82.0 This is tested in CI and must pass. # Test Matrix - The Github Actions CI test `libproc-rs` on : rust versions: - * `stable` (must pass) * `beta` (must pass) -* `1.82.0` (currently the minimum rust version supported) (must pass) -* `nightly` (allowed to fail) +* `1.72.0` (currently the minimum rust version supported) (must pass) +* `nightly` (allowed to fail) on the following platforms: - * `ubuntu-latest` * `macos-12` (Monterey) (Intel) * `macos-13` (Ventura) (Intel) * `macos-14` (Sonoma) (Arm64) # Examples - Two simple examples are included to show libproc-rs working. - `procinfo` that takes a PID as an optional argument (uses it's own pid if none supplied) and returns @@ -65,38 +55,32 @@ Two simple examples are included to show libproc-rs working. - `dmesg` is a version of dmesg implemented in rust that uses libproc-rs. These can be ran thus: -`sudo cargo run --example procinfo` or +`sudo cargo run --example procinfo` or `sudo cargo run --example dmesg` # Contributing - You are welcome to fork this repo and make a pull request, or write an issue. ## Experiment in OSS funding - -I am exploring the ideas around Open Source Software funding from [RadWorks Foundation]([https://radworks.org/) via -the [Drips Project](https://www.drips.network/) +I am exploring the ideas around Open Source Software funding from [RadWorks Foundation]([https://radworks.org/) via the [Drips Project](https://www.drips.network/) This project is in Drips [here](https://www.drips.network/app/projects/github/andrewdavidmackenzie/libproc-rs) ## Input Requested - * Suggestions for API, module re-org and cross-platform abstractions are welcome. * How to do error reporting? Define own new Errors, or keep simple with Strings? * Would like Path/PathBuf returned when it makes sense instead of String? ## TODO - -See the [list of issues](https://github.com/andrewdavidmackenzie/libproc-rs/issues). +See the [list of issues](https://github.com/andrewdavidmackenzie/libproc-rs/issues). I put the "help wanted" label where I need help from others. - + - Look at what similar methods could be implemented as a starting poon Linux - Complete the API on Mac OS X - figuring out all the Mac OS X / Darwin version mess.... - Add more documentation (including samples with documentation test) - Add own custom error type and implement From::from to ease reporting of multiple error types in clients ## Build and Test Locally - If you're feeling lucky today, start with `make` that will run `clippy`, `test` and will build docs also. If you want to stay "pure rust" : `cargo test` will build and test as usual. @@ -112,34 +96,29 @@ In order to have tests pass when run as `root` or not, some tests need to check at run-time (using our own `am_root()` function is handy) and avoid failing if *not* run as `root`. ### Using `act` to run GH Actions locally - If you develop on macos but want to ensure code builds and tests pass on linux while making changes, you can use the [act](https://github.com/nektos/act) tool to run the Github Actions Workflows on the test matrix. Just install `act` (`brew install act` on macOS) (previously install docker if you don't have it already, -and make sure the daemon is running) then run `act push`. You can test a subset of the rust +and make sure the daemon is running) then run `act push`. You can test a subset of the rust and os versions of the matrix with something like `act push --matrix os:ubuntu-latest` ## Enter the matrix - If you want to test locally as much of the test matrix as possible (different OS and versions of rust), that you can use `make matrix`. On macos, if you have `act` installed, it will use it to run the linux part of the matrix. ### Macos: clang detection and header file finding - Newer versions of `bindgen` have improved the detection of `clang` and hence macos header files. If you also have llvm/clang installed directly or via `brew` this may cause the build to fail saying it cannot find `libproc.h`. This can be fixed by setting `CLANG_PATH="/usr/bin/clang"` so that `bindgen` detects the Xcode version and hence can fidn the correct header files. # Other docs - * [Reference docs](doc/References.md) used to build and document libproc-rs * Details on methods available in different [macOS versions](doc/MacosVersions.md) # LICENSE - This code is licensed under MIT license (see LICENCE). From 407847154608519cc456747c6ba4e6ee6a45487b Mon Sep 17 00:00:00 2001 From: Andrew Mackenzie Date: Thu, 12 Dec 2024 23:02:47 +0100 Subject: [PATCH 2/4] Have bindgen generate code suitable for compiling with rustc 1.72.0 --- build.rs | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/build.rs b/build.rs index a81ca3a3..c757c344 100644 --- a/build.rs +++ b/build.rs @@ -1,22 +1,30 @@ +use bindgen::{RustEdition, RustTarget}; +use std::env; +use std::path::Path; + #[cfg(target_os = "macos")] fn main() { - use std::env; - use std::path::Path; - - let bindings = bindgen::builder() - .header_contents("libproc_rs.h", "#include ") - .layout_tests(false) - .clang_args(&["-x", "c++", "-I", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/"]) - .generate() - .expect("Failed to build libproc bindings"); + match RustTarget::stable(72, 0) { + Ok(rust_target) => { + let bindings = bindgen::builder() + .header_contents("libproc_rs.h", "#include ") + .rust_target(rust_target) + .rust_edition(RustEdition::Edition2018) + .layout_tests(false) + .clang_args(&["-x", "c++", "-I", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/"]) + .generate() + .expect("Failed to build libproc bindings"); - let output_path = Path::new(&env::var("OUT_DIR") - .expect("OUT_DIR env var was not defined")) - .join("osx_libproc_bindings.rs"); + let output_path = Path::new(&env::var("OUT_DIR") + .expect("OUT_DIR env var was not defined")) + .join("osx_libproc_bindings.rs"); - bindings - .write_to_file(output_path) - .expect("Failed to write libproc bindings"); + bindings + .write_to_file(output_path) + .expect("Failed to write libproc bindings"); + } + _ => eprintln!("Error executing bindgen") + } } #[cfg(any(target_os = "linux", target_os = "redox", target_os = "android"))] From 3a171c8101a2706fd3db8555f82ca0453bfb90c0 Mon Sep 17 00:00:00 2001 From: Andrew Mackenzie Date: Thu, 12 Dec 2024 23:05:56 +0100 Subject: [PATCH 3/4] Avoid linux warnings --- build.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/build.rs b/build.rs index c757c344..b38db33d 100644 --- a/build.rs +++ b/build.rs @@ -1,11 +1,12 @@ -use bindgen::{RustEdition, RustTarget}; -use std::env; -use std::path::Path; - #[cfg(target_os = "macos")] fn main() { + use bindgen::{RustEdition, RustTarget}; + use std::env; + use std::path::Path; + match RustTarget::stable(72, 0) { - Ok(rust_target) => { + Ok(rust + _target) => { let bindings = bindgen::builder() .header_contents("libproc_rs.h", "#include ") .rust_target(rust_target) From e063c4f23d4d24e1bc61d08a9936f7423cdddf7d Mon Sep 17 00:00:00 2001 From: Andrew Mackenzie Date: Thu, 12 Dec 2024 23:06:09 +0100 Subject: [PATCH 4/4] Avoid linux warnings --- build.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.rs b/build.rs index b38db33d..dc48f2c0 100644 --- a/build.rs +++ b/build.rs @@ -5,8 +5,7 @@ fn main() { use std::path::Path; match RustTarget::stable(72, 0) { - Ok(rust - _target) => { + Ok(rust_target) => { let bindings = bindgen::builder() .header_contents("libproc_rs.h", "#include ") .rust_target(rust_target)