Skip to content

Commit

Permalink
fix: rebase 8.0.0 branch with the latest changes from main (#179)
Browse files Browse the repository at this point in the history
* Fix Armv7 build (#158)

* Add armv7 build target

* Fix mismatched types for pointer width 32

* Use `sh` instead of `python` for `which` assertion

* Replace mach with mach2 (#157)

* feat: add support for RPM `ndb` databases (#159)

* feat: add support for RPM `ndb` databases

* chore: always try sqlite before librpm

* chore: remove `rpm` feature

* fix: librpm call not lazily evaluated

* Add `librpm` dependency note to README (#160)

* Update the changelog

* Bump version to 7.1.0

* Fix i686 build (#162)

closes #161

* Add Sonoma to macos_version_to_name (#163)

* BREAKING CHANGE: Change BatteryReadout::health return value to u8

There's no particular reason why one should allocate 64 bits for a
value that can only be <= 100.

As a bonus, ceil() the return value before finally casting to u8.

* Update BatteryReadout::health function signature

for other operating systems besides Linux.

* Added general detection for wayland compositors (#164)

* Upgrade dependencies to their latest versions

* Update changelog

Make some formatting changes as well.

* Add missing generic argument

sqlite's changed a bit between releases.

* Bump version to 7.2.0

* Add missing second generic argument to sqlite read() call

* Remove unneeded argument to unistd::gethostname function call

* Remove unused variable

* Refactor obsolete find_ifa function

* Bump version to 7.2.1

* Bump vergen version

* Use gitcl feature of vergen

This depends on the git binary, more ubiquituous than the libgit2 bindings, so
it should technically work on every platform we support.

* Refactor the old vergen interface

* Add new entry to the changelog

* Update version to 7.2.2

* Replace flatten() calls with map_while(Result::ok)

* Fix Readouts struct's network field type

Closes: #168

* Improve CI workflow (#169)

* Replace discontinued actions-rs

* Split cargo fmt and clippy into their own CI job

* Faster package count on Alpine Linux (#170)

* Bump version to 7.2.3

* added macos 15 version name (#171)

https://www.apple.com/newsroom/2024/06/macos-sequoia-takes-productivity-and-intelligence-on-mac-to-new-heights/

* Removed panic if local gpu db is not able to be read (#173)

* Add support for the Nix package manager (#172)

Added support for the Nix package manager using Nix' SQLite database.

* Bump version and update changelog

* linux: Safely exit when homebrew is not installed

* Improve linuxbrew keepme safeguard

* Remove unused import

* Bump version to 7.3.1

* Allow disk_space function to accept a path argument (#156)

BREAKING CHANGE: allow disk_space function to accept a path argument
- Bump version and update changelog
- Change disk_space path argument to be of type &Path and check path exists in shared::disk_space
- Add missing import for openwrt

---------

Co-authored-by: Adrian Groh <50576978+Gobidev@users.noreply.github.com>
Co-authored-by: Silas Groh <silas.groh@t-online.de>
Co-authored-by: grtcdr <tahaaziz.benali@esprit.tn>
Co-authored-by: Rex Ng <rex.ky.ng@gmail.com>
Co-authored-by: Absolpega <106615943+Absolpega@users.noreply.github.com>
Co-authored-by: grtcdr <ba.tahaaziz@gmail.com>
Co-authored-by: Matthias Baer <matthiasbaer@bluewin.ch>
Co-authored-by: Rex Ng <timescam@duck.com>
Co-authored-by: coolGi <57488297+coolGi2007@users.noreply.github.com>
  • Loading branch information
10 people authored Sep 28, 2024
1 parent 13a4812 commit 4c7ffe1
Show file tree
Hide file tree
Showing 20 changed files with 347 additions and 220 deletions.
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

0 comments on commit 4c7ffe1

Please sign in to comment.