Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rebase 8.0.0 branch with the latest changes from main #179

Merged
merged 40 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
53bcd5b
Fix Armv7 build (#158)
Gobidev May 12, 2023
d67e48c
Replace mach with mach2 (#157)
Gobidev May 15, 2023
d190308
feat: add support for RPM `ndb` databases (#159)
RubixDev May 15, 2023
455eb1f
Add `librpm` dependency note to README (#160)
Gobidev May 15, 2023
d7745aa
Update the changelog
May 15, 2023
b8e8fe1
Bump version to 7.1.0
May 15, 2023
8b2b11c
Fix i686 build (#162)
Gobidev May 29, 2023
49d9500
Add Sonoma to macos_version_to_name (#163)
rexkyng Jul 9, 2023
0f15123
BREAKING CHANGE: Change BatteryReadout::health return value to u8
Mar 28, 2023
7e1cb1a
Update BatteryReadout::health function signature
Aug 3, 2023
f4ea9be
Added general detection for wayland compositors (#164)
Absolpega Aug 28, 2023
901c1a3
Upgrade dependencies to their latest versions
Oct 6, 2023
ae17865
Update changelog
Oct 6, 2023
17763bc
Add missing generic argument
Oct 6, 2023
c768977
Bump version to 7.2.0
Oct 6, 2023
ed89a8a
Add missing second generic argument to sqlite read() call
Oct 6, 2023
1a2364e
Remove unneeded argument to unistd::gethostname function call
Oct 6, 2023
29f9a0b
Remove unused variable
Oct 6, 2023
6853503
Refactor obsolete find_ifa function
Oct 6, 2023
6ae1304
Bump version to 7.2.1
Oct 6, 2023
81ede72
Bump vergen version
Dec 19, 2023
9cd0213
Use gitcl feature of vergen
Dec 19, 2023
000c5d2
Refactor the old vergen interface
Dec 19, 2023
10100c2
Add new entry to the changelog
grtcdr Feb 17, 2024
9fb1add
Update version to 7.2.2
grtcdr Feb 17, 2024
c357e97
Replace flatten() calls with map_while(Result::ok)
grtcdr Feb 17, 2024
2205490
Fix Readouts struct's network field type
grtcdr May 10, 2024
8f91548
Improve CI workflow (#169)
FantasyTeddy May 29, 2024
1dca3fb
Faster package count on Alpine Linux (#170)
Gobidev Jun 2, 2024
42d7cc3
Bump version to 7.2.3
grtcdr Jun 2, 2024
040e9d3
added macos 15 version name (#171)
rexkyng Jun 11, 2024
0be8883
Removed panic if local gpu db is not able to be read (#173)
coolGi69 Jun 18, 2024
3a5bec0
Add support for the Nix package manager (#172)
coolGi69 Jun 22, 2024
ef60632
Bump version and update changelog
grtcdr Jun 28, 2024
30abf25
linux: Safely exit when homebrew is not installed
grtcdr Jul 8, 2024
e8d8656
Improve linuxbrew keepme safeguard
grtcdr Sep 11, 2024
15ba3ca
Remove unused import
grtcdr Sep 11, 2024
6781ee9
Bump version to 7.3.1
grtcdr Sep 11, 2024
9434b59
Allow disk_space function to accept a path argument (#156)
Rolv-Apneseth Apr 21, 2023
1c18fbb
Merge branch '8.0.0' into 8.0.0
Rolv-Apneseth Sep 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 38 additions & 31 deletions .github/workflows/libmacchina.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,31 @@ on: [push, pull_request]
name: CI

jobs:
lint:
runs-on: ubuntu-latest
name: Lint
env:
RUSTFLAGS: "-Dwarnings"
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Bootstrap
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Formatting
run: cargo fmt --all -- --check

- name: Clippy
run: cargo clippy --all-targets --all-features

checks:
name: ${{ matrix.name }} (${{ matrix.target }})
runs-on: ${{ matrix.os }}
env:
PROGRAM: ${{ matrix.cross && 'cross' || 'cargo' }}
strategy:
fail-fast: false
matrix:
Expand All @@ -17,6 +39,7 @@ jobs:
- x86_64-unknown-freebsd
- aarch64-linux-android
- aarch64-unknown-linux-gnu
- armv7-unknown-linux-gnueabihf

include:
- os: ubuntu-latest
Expand Down Expand Up @@ -62,44 +85,28 @@ jobs:
test: true
cargo_args: --features "openwrt"

- os: ubuntu-latest
name: Linux ARMv7
target: armv7-unknown-linux-gnueabihf
cross: true
test: true

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Bootstrap
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
target: ${{ matrix.target }}

- name: Formatting
uses: actions-rs/cargo@v1
uses: dtolnay/rust-toolchain@stable
with:
command: fmt
args: -- --check
use-cross: ${{ matrix.cross }}
continue-on-error: false
targets: ${{ matrix.target }}

- name: Lints
uses: actions-rs/cargo@v1
with:
command: clippy
args: --target=${{ matrix.target }} -- --no-deps -D clippy::all
use-cross: ${{ matrix.cross }}
continue-on-error: false
- name: Install cross
run: cargo install cross
if: ${{ matrix.cross }}

- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --target=${{ matrix.target }} ${{ matrix.cargo_args }}
use-cross: ${{ matrix.cross }}
run: ${{ env.PROGRAM }} build --target=${{ matrix.target }} ${{ matrix.cargo_args }}

- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: --target=${{ matrix.target }} ${{ matrix.cargo_args }}
use-cross: ${{ matrix.cross }}
- name: Test
run: ${{ env.PROGRAM }} test --target=${{ matrix.target }} ${{ matrix.cargo_args }}
if: ${{ matrix.test }}
71 changes: 66 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,63 @@
- Rolv Apneseth:
- BREAKING CHANGE: Allow disk_space function to accept a path argument (#156)

## `7.3.1`

- Fix overflow affecting linux::count_homebrew() implementation

## `7.3.0`

coolGi2007:
- Add support for the Nix package manager
- Bump `sqlite` dependency to version `0.36.0`
- Don't panic if the `pci.ids` database could not be found

Rex Ng:
- Recognize latest version of macOS

## `7.2.3`

- Fix `Readouts` struct `network` field type

Matthias Baer:
- Improve CI workflow (#169)

Adrian Groh:
- Faster package count on Alpine Linux (#170)

## `7.2.2`

- Update `vergen` dependency and correct its invocation.

## `7.2.1`

- Fix some build errors

## `7.2.0`

Adrian Groh:
- Fix build errors affecting i686 (#162)

Rex Ng:
- Recognize macOS Sonoma (#163)

Absolpega:
- Add general detection for Wayland (#164)

- Change the return value of BatteryReadout::health from `u64` to `u8`
- Upgrade dependencies to their latest versions

## `7.1.0`

Silas Groh:
- Add support for `ndb` databases

Adrian Groh:
- Replace `mach` dependency with `mach2`
- Replace `python` command with `sh` in `extra::which` unit tests
- Add armv7 to the list of build targets in the CI pipeline
- Fix compilation issues for armv7 build target

## `7.0.0`

- Rolv Apneseth:
Expand All @@ -18,15 +75,19 @@

## `6.4.0`

- Adrian Groh:
Adrian Groh:
- Use the correct kernel parameters when initializing FreeBSD `KernelReadout` (#148)
- Implement uptime readout for FreeBSD systems (#138)
- Use `MemAvailable` to calculate used memory (#134)
- Prioritize detecting window managers with xprop (#133)
- Rolv Apneseth: Implement GPU readout for Linux systems (#140)
- Matthias Baer: Use a singleton for `COMLibrary` (#143)
- Xarblu: Change Flatpak package-counting method (#125)
- Kian-Meng Ang: Fix a typo in the documentation

Rolv Apneseth: Implement GPU readout for Linux systems (#140)

Matthias Baer: Use a singleton for `COMLibrary` (#143)

Xarblu: Change Flatpak package-counting method (#125)

Kian-Meng Ang: Fix a typo in the documentation

## `6.3.5`

Expand Down
43 changes: 23 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,40 @@ build = "build.rs"

[dependencies]
cfg-if = "1.0.0"
libc = "0.2.131"
home = "0.5.3"
pciid-parser = "0.6.2"
libc = "0.2.148"
home = "0.5.5"
pciid-parser = "0.6.3"

[build-dependencies.vergen]
version = "7.3.2"
version = "8.2.6"
optional = true
default-features = false
features = ["build","cargo","git","rustc"]
features = ["build","cargo","git","gitcl","rustc"]

[target.'cfg(target_os = "linux")'.dependencies]
dirs = "4.0"
walkdir = "2.3.2"
dirs = "5.0.1"
walkdir = "2.4.0"
os-release = "0.1"
regex = "1.6.0"
regex = "1.9.2"
rpm-pkg-count = { version = "0.2.1", features = ["runtime"] }
nix = { version = "0.26.2", features = ["socket"], default-features = false }
wayland-sys = { version = "0.31.1", features = ["dlopen", "client"] }

[target.'cfg(target_os = "netbsd")'.dependencies]
nix = { version = "0.24.1", default-features = false, features = ["hostname"] }
regex = "1.6.0"
nix = { version = "0.26.2", default-features = false, features = ["hostname"] }
regex = "1.9.2"

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = "0.9.3"
core-graphics = "0.22.3"
core-graphics = "0.23.1"
core-video-sys = "0.1.4"
mach = "0.3.2"
mach2 = "0.4.1"

[target.'cfg(target_family = "unix")'.dependencies]
num_cpus = "1.13.1"
num_cpus = "1.16.0"

[target.'cfg(target_os = "windows")'.dependencies]
local-ip-address = "0.4.4"
local-ip-address = "0.5.6"
wmi = "0.12.0"
winreg = "0.10.1"
windows = { version = "0.39.0", features = [
Expand All @@ -53,22 +56,22 @@ windows = { version = "0.39.0", features = [
]}

[target.'cfg(not(target_os = "windows"))'.dependencies]
if-addrs = "0.6.7"
if-addrs = "0.10.2"

[target.'cfg(any(target_os="freebsd", target_os = "linux"))'.dependencies]
sqlite = "0.27.0"
sqlite = "0.36.0"

[target.'cfg(any(target_os="freebsd", target_os = "netbsd"))'.dependencies]
x11rb = "0.10.1"
x11rb = "0.12.0"

[target.'cfg(any(target_os = "linux", target_os = "netbsd", target_os = "android"))'.dependencies]
itertools = "0.10.3"
itertools = "0.11.0"

[target.'cfg(not(any(target_os = "netbsd", target_os = "windows")))'.dependencies]
sysctl = "0.4.6"
sysctl = "0.5.4"

[target.'cfg(any(target_os = "linux", target_os = "netbsd"))'.build-dependencies]
pkg-config = { version = "0.3.25", optional = true}
pkg-config = { version = "0.3.27", optional = true}

[features]
openwrt = []
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Add the following to your project's _Cargo.toml_ file:
libmacchina = "7"
```

### Notes

On distributions like openSUSE that use the `ndb` RPM database format, `librpm`
(which is usually provided by the `rpm-devel` package) is required for the RPM
package count readout to work.

### Examples

```rust
Expand Down
20 changes: 5 additions & 15 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
use std::env;

#[cfg(feature = "version")]
fn commit_hash() {
use vergen::{Config, ShaKind};

let mut config = Config::default();
*config.git_mut().sha_kind_mut() = ShaKind::Short;

if let Err(e) = vergen::vergen(config) {
eprintln!("{}", e);
}
}
use std::{env, error::Error};

fn build_macos() {
println!("cargo:rustc-link-lib=framework=Foundation");
Expand All @@ -20,13 +8,15 @@ fn build_macos() {
println!("cargo:rustc-link-lib=framework=DisplayServices");
}

fn main() {
fn main() -> Result<(), Box<dyn Error>> {
match env::var("CARGO_CFG_TARGET_OS").as_ref().map(|x| &**x) {
Ok("macos") => build_macos(),
Ok("netbsd") => {}
_ => {}
}

#[cfg(feature = "version")]
commit_hash()
vergen::EmitBuilder::builder().emit()?;

Ok(())
}
4 changes: 2 additions & 2 deletions src/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl BatteryReadout for AndroidBatteryReadout {
}
}

fn health(&self) -> Result<u64, ReadoutError> {
fn health(&self) -> Result<u8, ReadoutError> {
Err(ReadoutError::NotImplemented)
}
}
Expand Down Expand Up @@ -216,7 +216,7 @@ impl GeneralReadout for AndroidGeneralReadout {

if let Ok(content) = file {
let reader = BufReader::new(content);
for line in reader.lines().flatten() {
for line in reader.lines().map_while(Result::ok) {
if line.starts_with("Hardware") {
hardware = Some(get_value_from_line(line, "Hardware"));
break; // If "Hardware" information is present, the rest is not needed.
Expand Down
8 changes: 6 additions & 2 deletions src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ where
/// Returns the value of PKG_DBDIR if exists or a default if not.
pub fn pkgdb_dir() -> Option<PathBuf> {
if let Ok(lines) = read_lines("/etc/mk.conf") {
let line = lines.flatten().find(|l| l.starts_with("PKG_DBDIR"));
let line = lines
.map_while(Result::ok)
.find(|l| l.starts_with("PKG_DBDIR"));

if let Some(pkg_dbdir) = line {
if let Some(value) = pkg_dbdir.split('=').nth(1) {
Expand All @@ -29,7 +31,9 @@ pub fn pkgdb_dir() -> Option<PathBuf> {
/// Returns the value of LOCALBASE if exists or a default if not.
pub fn localbase_dir() -> Option<PathBuf> {
if let Ok(lines) = read_lines("/etc/mk.conf") {
let line = lines.flatten().find(|l| l.starts_with("LOCALBASE"));
let line = lines
.map_while(Result::ok)
.find(|l| l.starts_with("LOCALBASE"));

if let Some(pkg_dbdir) = line {
if let Some(value) = pkg_dbdir.split('=').nth(1) {
Expand Down
5 changes: 3 additions & 2 deletions src/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ Returns the entries of a given `Path`.
pub fn get_entries(path: &Path) -> Option<Vec<PathBuf>> {
if let Ok(dir) = std::fs::read_dir(path) {
let mut entries: Vec<PathBuf> = Vec::new();
dir.flatten().for_each(|x| entries.push(x.path()));
dir.map_while(Result::ok)
.for_each(|x| entries.push(x.path()));
return Some(entries);
}

Expand Down Expand Up @@ -118,7 +119,7 @@ mod tests {
#[test]
#[cfg(not(feature = "openwrt"))]
fn test_which() {
assert!(which("python"));
assert!(which("sh"));
assert!(!which("not_a_real_command"));
}
}
4 changes: 2 additions & 2 deletions src/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl BatteryReadout for FreeBSDBatteryReadout {
Err(ReadoutError::MetricNotAvailable)
}

fn health(&self) -> Result<u64, ReadoutError> {
fn health(&self) -> Result<u8, ReadoutError> {
Err(ReadoutError::NotImplemented)
}
}
Expand Down Expand Up @@ -401,7 +401,7 @@ impl FreeBSDPackageReadout {
let statement = con.prepare("SELECT COUNT(*) FROM packages");
if let Ok(mut s) = statement {
if s.next().is_ok() {
return match s.read::<Option<i64>>(0) {
return match s.read::<Option<i64>, _>(0) {
Ok(Some(count)) => Some(count as usize),
_ => None,
};
Expand Down
Loading