Skip to content

Commit

Permalink
Merge pull request #60 from asomers/rust-version
Browse files Browse the repository at this point in the history
Multiple improvements
  • Loading branch information
asomers authored Sep 29, 2024
2 parents b04c07d + c18cd88 commit 0da0090
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 198 deletions.
91 changes: 91 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 0 additions & 20 deletions .github/workflows/audit.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/coverage.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/docs.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/release.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/style.yml

This file was deleted.

34 changes: 0 additions & 34 deletions .github/workflows/test.yml

This file was deleted.

16 changes: 12 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,30 @@ keywords = ["freebsd"]
categories = ["os:unix-apis", "api-bindings"]
readme = "README.md"
repository = "https://github.com/fubarnetes/rctl"
documentation = "https://fubarnetes.github.io/rctl/rctl/"
rust-version = "1.70.0"
documentation = "https://docs.rs/rctl"
edition = "2021"

[badges]
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"]

[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"
26 changes: 12 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -143,6 +142,16 @@ mod subject {
}
}

#[cfg(feature = "serialize")]
impl serde::Serialize for User {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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)
Expand Down Expand Up @@ -693,7 +702,6 @@ pub enum Action {
/// [`ReadBps`], [`WriteBps`], [`ReadIops`], [`WriteIops`]
///
/// [`CpuTime`]: Resource::CpuTime
/// [`WallClock`]: Resource::Wallclock
/// [`ReadBps`]: Resource::ReadBps
/// [`WriteBps`]: Resource::WriteBps
Expand Down Expand Up @@ -1192,16 +1200,6 @@ impl<'a> IntoIterator for &'a RuleParsingIntoIter<String> {
}
}

trait RuleParsingExt<'a>: Sized {
fn parse_rules(self) -> RuleParserAdapter<Self>;
}

impl<'a> RuleParsingExt<'a> for str::Split<'a, &'a str> {
fn parse_rules(self) -> RuleParserAdapter<Self> {
RuleParserAdapter { inner: self }
}
}

/// A filter can match a set of [Rules](Rule).
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Filter {
Expand Down Expand Up @@ -2024,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),
}
);

Expand Down

0 comments on commit 0da0090

Please sign in to comment.