From 25e3f9331140e05c3cec23fa460c8aef19a97dc7 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 29 Sep 2024 15:31:17 -0600 Subject: [PATCH 1/8] Declare an MSRV It isn't yet tested in CI though. --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index ee2e0b1..d49bd96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ keywords = ["freebsd"] categories = ["os:unix-apis", "api-bindings"] readme = "README.md" repository = "https://github.com/fubarnetes/rctl" +rust-version = "1.70.0" documentation = "https://fubarnetes.github.io/rctl/rctl/" edition = "2021" From fa9abb41f3a65419fe9d391280b26e0ebabeebf5 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 29 Sep 2024 15:32:18 -0600 Subject: [PATCH 2/8] Fix the build with -Zdirect-minimal-versions. But it isn't yet tested in CI. --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d49bd96..152f7f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,10 +21,10 @@ is-it-maintained-open-issues = { repository = "fubarnetes/rctl" } serialize = ["serde", "serde_json"] [dependencies] -libc = "0.2" +libc = "0.2.153" nix = { version = "0.28", default-features = false, features = [ "signal", "user" ] } number_prefix = "0.4" sysctl = "0.5" -serde = { version="1.0", features = ["derive"], optional=true } +serde = { version="1.0.113", features = ["derive"], optional=true } serde_json = { version="1.0", optional=true } -thiserror = "1.0" +thiserror = "1.0.32" From ee1822d2807590b9186998f1d97859705eaeb508 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 29 Sep 2024 14:25:30 -0600 Subject: [PATCH 3/8] Fix the serde feature after #51 We should really add a CI configuration that includes that feature. --- src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8c69eab..3783805 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,12 +107,11 @@ pub enum Error { /// Helper module containing enums representing [Subjects](Subject) mod subject { use super::ParseError; - use std::fmt; use nix::unistd::{self, Uid}; + use std::fmt; /// Represents a user subject #[derive(Clone, Debug, PartialEq, Eq, Hash)] - #[cfg_attr(feature = "serialize", derive(serde::Serialize))] pub struct User(pub Uid); impl User { @@ -143,6 +142,16 @@ mod subject { } } + #[cfg(feature = "serialize")] + impl serde::Serialize for User { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + self.0.as_raw().serialize(serializer) + } + } + impl<'a> From<&'a User> for String { fn from(user: &'a User) -> String { format!("user:{}", user.0) From b3a525481878836ba36a1b2722539c3e61d554af Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 29 Sep 2024 15:43:45 -0600 Subject: [PATCH 4/8] On docs.rs, only build docs for FreeBSD amd64 --- Cargo.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 152f7f5..bce4303 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,13 @@ maintenance = { status = "experimental" } is-it-maintained-issue-resolution = { repository = "fubarnetes/rctl" } is-it-maintained-open-issues = { repository = "fubarnetes/rctl" } +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] +targets = [ + "x86_64-unknown-freebsd", +] + [features] serialize = ["serde", "serde_json"] From e18156ac272663192e206435733f59ed51cdf2e2 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 29 Sep 2024 15:44:46 -0600 Subject: [PATCH 5/8] Repoint crates.io link to docs.rs --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index bce4303..01c6c57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ categories = ["os:unix-apis", "api-bindings"] readme = "README.md" repository = "https://github.com/fubarnetes/rctl" rust-version = "1.70.0" -documentation = "https://fubarnetes.github.io/rctl/rctl/" +documentation = "https://docs.rs/rctl" edition = "2021" [badges] From c39e2c93b6b5702fba1e8f03d2022cfec1d2f654 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 29 Sep 2024 14:34:33 -0600 Subject: [PATCH 6/8] Delete dead code --- src/lib.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3783805..095adc9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1201,16 +1201,6 @@ impl<'a> IntoIterator for &'a RuleParsingIntoIter { } } -trait RuleParsingExt<'a>: Sized { - fn parse_rules(self) -> RuleParserAdapter; -} - -impl<'a> RuleParsingExt<'a> for str::Split<'a, &'a str> { - fn parse_rules(self) -> RuleParserAdapter { - RuleParserAdapter { inner: self } - } -} - /// A filter can match a set of [Rules](Rule). #[derive(Debug, Default, Clone, PartialEq)] pub struct Filter { From f22cb01e5d1e9d41001128f10826860f84edd87c Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 29 Sep 2024 14:35:26 -0600 Subject: [PATCH 7/8] Clippy cleanup --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 095adc9..adb887b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -702,7 +702,6 @@ pub enum Action { /// [`ReadBps`], [`WriteBps`], [`ReadIops`], [`WriteIops`] /// /// [`CpuTime`]: Resource::CpuTime - /// [`WallClock`]: Resource::Wallclock /// [`ReadBps`]: Resource::ReadBps /// [`WriteBps`]: Resource::WriteBps @@ -2023,7 +2022,7 @@ pub mod tests { subject: Subject::user_name("nobody").expect("no user 'nobody'"), resource: Resource::VMemoryUse, action: Action::Deny, - limit: Limit::amount(1 * 1024 * 1024 * 1024), + limit: Limit::amount(1 << 30), } ); From c18cd882f192f3d3bd7c84e428254a7ae1496436 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 29 Sep 2024 15:58:26 -0600 Subject: [PATCH 8/8] Switch CI from github workflows to Cirrus Github workflows is currently broken, and I lack the knowledge to fix it. Also, Cirrus has one major advantage over GWF: native support for FreeBSD. --- .cirrus.yml | 91 ++++++++++++++++++++++++++++++++++ .github/workflows/audit.yml | 20 -------- .github/workflows/coverage.yml | 40 --------------- .github/workflows/docs.yml | 29 ----------- .github/workflows/release.yml | 29 ----------- .github/workflows/style.yml | 28 ----------- .github/workflows/test.yml | 34 ------------- 7 files changed, 91 insertions(+), 180 deletions(-) create mode 100644 .cirrus.yml delete mode 100644 .github/workflows/audit.yml delete mode 100644 .github/workflows/coverage.yml delete mode 100644 .github/workflows/docs.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/style.yml delete mode 100644 .github/workflows/test.yml diff --git a/.cirrus.yml b/.cirrus.yml new file mode 100644 index 0000000..0fc1a79 --- /dev/null +++ b/.cirrus.yml @@ -0,0 +1,91 @@ +setup: &SETUP + env: + HOME: /tmp # cargo needs it + RUSTFLAGS: -D warnings + setup_script: + - pkg install -y llvm + - fetch https://sh.rustup.rs -o rustup.sh + - sh rustup.sh -y --profile=minimal --default-toolchain $VERSION + +task: + env: + HOME: /tmp # cargo cache needs it + TARGET: x86_64-unknown-freebsd + VERSION: nightly + matrix: + - name: FreeBSD 13 amd64 nightly + freebsd_instance: + image: freebsd-13-4-release-amd64 + - name: FreeBSD 14 amd64 nightly + freebsd_instance: + image: freebsd-14-1-release-amd64-ufs + - name: FreeBSD 14 amd64 stable + env: + VERSION: 1.70.0 + freebsd_instance: + image: freebsd-14-1-release-amd64-ufs + - name: FreeBSD 14 i686 nightly + # Test i686 FreeBSD in 32-bit emulation on a 64-bit host. + env: + TARGET: i686-unknown-freebsd + # Can't use nightly on i686 due to + # https://github.com/rust-lang/rust/issues/130677 + VERSION: 1.70.0 + freebsd_instance: + image: freebsd-14-1-release-amd64-ufs + << : *SETUP + extra_setup_script: + - . $HOME/.cargo/env + - if [ "$TARGET" = "i686-unknown-freebsd" ]; then rustup target add --toolchain $VERSION i686-unknown-freebsd; fi + cargo_cache: + folder: $HOME/.cargo/registry + fingerprint_script: cat Cargo.lock || echo "" + test_script: + - . $HOME/.cargo/env + - cargo test --all-features --target $TARGET + doc_script: + - . $HOME/.cargo/env + - cargo doc --target $TARGET --no-deps --all-features + before_cache_script: rm -rf $HOME/.cargo/registry/index + +# Stuff that doesn't need to be repeated for each target, env, and toolchain +lint_task: + name: Lint + env: + HOME: /tmp # cargo cache needs it + VERSION: nightly + freebsd_instance: + image: freebsd-14-1-release-amd64-ufs + << : *SETUP + extra_setup_script: + - . $HOME/.cargo/env + - rustup component add --toolchain $VERSION clippy + - rustup component add --toolchain $VERSION rustfmt + cargo_cache: + folder: $HOME/.cargo/registry + clippy_script: + - . $HOME/.cargo/env + - cargo clippy --all-targets -- -D warnings + - cargo clippy --all-targets --all-features -- -D warnings + audit_script: + - . $HOME/.cargo/env + # install ca_root_nss due to https://github.com/rustsec/rustsec/issues/1137 + - pkg install -y ca_root_nss cargo-audit + - cargo audit + minver_script: + - . $HOME/.cargo/env + - cargo update -Zdirect-minimal-versions + - cargo check --all-features --all-targets --all + before_cache_script: rm -rf $CARGO_HOME/registry/index + +task: + name: Style + container: + image: rustlang/rust:nightly + cargo_cache: + folder: $HOME/.cargo/registry + fingerprint_script: cat Cargo.lock || echo "" + fmt_script: + - rustup component add rustfmt + - cargo fmt --all -- --check --color=never + before_cache_script: rm -rf $HOME/.cargo/registry/index diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml deleted file mode 100644 index 2f7c08e..0000000 --- a/.github/workflows/audit.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Security audit - -on: - schedule: - - cron: "0 0 * * *" - push: - paths: - - '**/Cargo.toml' - - '**/Cargo.lock' - pull_request: - -jobs: - audit: - name: Audit - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/audit-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index df13ead..0000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Coverage - -on: - push: - pull_request: - -jobs: - coverage: - runs-on: macos-latest - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository - - strategy: - matrix: - box: - - fbsd_13_1 - - fbsd_12_4 - - steps: - - uses: actions/checkout@v2 - - - name: Set up vagrant - run: vagrant up ${{ matrix.box }} - - - name: Install coverage prerequisites - run: | - vagrant ssh ${{ matrix.box }} -- sudo pkg install -y kcov - vagrant ssh ${{ matrix.box }} -- cargo install cargo-kcov - - - name: Build - run: vagrant ssh ${{ matrix.box }} -- "cd /vagrant; cargo build" - - - name: Collect coverage - run: | - vagrant ssh ${{ matrix.box }} -- "cd /vagrant; cargo kcov -- --verify --exclude-pattern=/home/vagrant/.cargo,/usr/lib,/usr/local/lib,/usr/src/lib/" - vagrant ssh ${{ matrix.box }} -- "cd /vagrant/target; tar cf - cov/" | tar xv - - - uses: codecov/codecov-action@v1 - with: - fail_ci_if_error: true - verbose: true diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index 738522d..0000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Build docs - -on: - release: - types: published - -jobs: - docs: - runs-on: macos-latest - - strategy: - matrix: - box: - - fbsd_13_1 - - steps: - - uses: actions/checkout@v2 - - - name: Set up vagrant - run: vagrant up ${{ matrix.box }} - - - name: Build documentation - run: vagrant ssh ${{ matrix.box }} -- "cd /vagrant; cargo doc; tar cf - target/doc/" | tar xv - - - name: Deploy documentation to GitHub Pages - uses: JamesIves/github-pages-deploy-action@4.1.1 - with: - branch: gh-pages - folder: target/doc/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index c8c8ad9..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Release - -on: - release: - types: published - -jobs: - docs: - runs-on: macos-latest - - strategy: - matrix: - box: - - fbsd_13_1 - - steps: - - uses: actions/checkout@v2 - - - name: Set up vagrant - run: vagrant up ${{ matrix.box }} - - - name: Build documentation - run: vagrant ssh ${{ matrix.box }} -- "cd /vagrant; cargo doc; tar cf - target/doc/" | tar xv - - - name: Deploy documentation to GitHub Pages - uses: JamesIves/github-pages-deploy-action@4.1.1 - with: - branch: gh-pages - folder: target/doc/ diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml deleted file mode 100644 index 9c19b9a..0000000 --- a/.github/workflows/style.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Lints - -on: - push: - pull_request: - -jobs: - stylecheck: - name: Style Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Run cargo fmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - clippy: - name: Clippy - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/clippy-check@v1 - with: - use-cross: true - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-features --target x86_64-unknown-freebsd \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 51061b2..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Build and Test - -on: - push: - pull_request: - -jobs: - build_and_test: - runs-on: macos-latest - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository - - strategy: - matrix: - box: - - fbsd_13_1 - - fbsd_12_4 - - steps: - - uses: actions/checkout@v2 - - - name: Set up vagrant - run: vagrant up ${{ matrix.box }} - - - name: Build - run: vagrant ssh ${{ matrix.box }} -- "cd /vagrant; cargo build" - - - name: Test - run: vagrant ssh ${{ matrix.box }} -- "cd /vagrant; cargo test --lib" - - - name: Docstests - run: vagrant ssh ${{ matrix.box }} -- "cd /vagrant; cargo test --doc" - - - name: Build Docs - run: vagrant ssh ${{ matrix.box }} -- "cd /vagrant; cargo doc"