Skip to content

Commit

Permalink
Merge pull request #19 from tuna-f1sh/udevrs
Browse files Browse the repository at this point in the history
Replace udev-rs libudev bindings with native Rust udev
  • Loading branch information
tuna-f1sh committed Jun 25, 2024
2 parents 3459b3d + 7e99555 commit acd9ffa
Show file tree
Hide file tree
Showing 8 changed files with 362 additions and 48 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ jobs:
fail-fast: false
matrix:
job:
- { os: ubuntu-latest, target: aarch64-unknown-linux-gnu, use-cross: true, feature-flags: "--all-features" }
# only default as don't generate docs or hwdb
- { os: ubuntu-latest, target: aarch64-unknown-linux-gnu, use-cross: true, feature-flags: "" }
# all ok as udev ignored on non-linux
- { os: ubuntu-latest, target: x86_64-pc-windows-gnu, use-cross: true, feature-flags: "--all-features" }
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu, use-cross: false, feature-flags: "--all-features" }
# specificy to avoid udevlib
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu, use-cross: false, feature-flags: "-F=cli_generate" }
# all ok as udev ignored on non-linux
- { os: macos-latest, target: universal-apple-darwin, use-cross: false, feature-flags: "--all-features" }
steps:
- uses: actions/checkout@v4
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

## [Unreleased]

- Working on full dumps of device descriptors ([#15](https://github.com/tuna-f1sh/cyme/issues/15))
### Addded

- Full dumps of device descriptors for matching `--lsusb --verbose` ([#15](https://github.com/tuna-f1sh/cyme/issues/15))

### Changed

- Replace [udev-rs](https://github.com/Smithay/udev-rs) and indirectly libudev-sys with Rust native [udev](https://github.com/cr8t/udev); libudev dependency (and system requirement) is now optional but can be used with `--no-default-features -F=udevlib`. ([#19](https://github.com/tuna-f1sh/cyme/pull/19))

## [1.6.1] - 2024-13-06

Expand Down
126 changes: 124 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "List system USB buses and devices; a modern cross-platform `lsusb
repository = "https://github.com/tuna-f1sh/cyme"
readme = "README.md"
license = "GPL-3.0-or-later"
version = "1.6.1"
version = "1.7.0"
edition = "2021"
keywords = ["usb", "lsusb", "system_profiler", "macos", "libusb"]
categories = ["command-line-utilities"]
Expand All @@ -32,32 +32,34 @@ terminal_size = "0.2.5"
strum = "0.24.1"
strum_macros = "0.24.3"

[patch.crates-io]
libudev-sys = { git = "https://github.com/Emilgardis/libudev-sys/", branch = "fix-cross-compilation" }

[dev-dependencies]
diff = "0.1"
assert-json-diff = "2.0.2"

[target.x86_64-unknown-linux-gnu.dependencies]
udev = { version = "^0.8.0", optional = true }
udevrs = { version = "^0.3.0", optional = true }
udevlib = { package = "udev", version = "^0.8.0", optional = true }
rusb = "0.9.4"

[target.arm-unknown-linux-gnueabihf.dependencies]
udev = { version = "^0.8.0", optional = true }
udevrs = { version = "^0.3.0", optional = true }
udevlib = { package = "udev", version = "^0.8.0", optional = true }
rusb = "0.9.4"

[target.aarch64-unknown-linux-gnu.dependencies]
udev = { version = "^0.8.0", optional = true }
udevrs = { version = "^0.3.0", optional = true }
udevlib = { package = "udev", version = "^0.8.0", optional = true }
rusb = "0.9.4"

[features]
libusb = ["dep:rusb"]
udev = ["dep:udev"]
udev_hwdb = ["udev/hwdb"]
udev = ["libusb", "dep:udevrs"]
udev_hwdb = ["libusb", "udevlib?/hwdb"]
# libudev C binding
udevlib = ["libusb", "dep:udevlib"]
usb_test = []
cli_generate = ["dep:clap_complete", "dep:clap_mangen"] # for generating man and completions
default = ["libusb"]
default = ["libusb", "udev"]

[[bin]]
name = "cyme"
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ The name comes from the technical term for the type of blossom on a Apple tree:
## Requirements

* Linux/Windows and pre-compiled targets require [libusb 1.0.0](https://libusb.info): `brew install libusb`, `sudo apt install libusb-1.0-0-dev` or one's package manager of choice.
* Linux pre-compiled and `--features udev`/`--features udev_hwdb` requires 'libudev-dev': `sudo apt install libudev-dev` or one's package manager of choice.

For pre-compiled binaries, see the [releases](https://github.com/tuna-f1sh/cyme/releases).

Expand All @@ -70,9 +69,12 @@ More package managers to come/package distribution, please feel free to create a

## Linux udev

To obtain device and interface drivers being used on Linux like `lsusb`, one must install 'libudev-dev' via a package manager and the `--features udev` feature when building. To lookup USB IDs from the udev hwdb as well (like `lsusb`) use `--features udev_hwdb`. Without hwdb, `cyme` will use the 'usb-ids' crate, which is the same source as the hwdb binary data but the bundled hwdb may differ due to customisations or last update ('usb-ids' will be most up to date).
> [!NOTE]
> Only supported on Linux targets.
Only supported on Linux targets.
To obtain device and interface drivers being used on Linux like `lsusb`, one can use the `--features udev` feature when building - it's a default feature. The feature uses the Rust crate [udevrs](https://crates.io/crates/udevrs) to obtain the information. To use the C FFI libudev library, use `--no-default-features --features udevlib` which will use the 'libudev' crate. Note that this will require 'libudev-dev' to be installed on the host machine.

To lookup USB IDs from the udev hwdb as well (like `lsusb`) use `--features udev_hwdb`. Without hwdb, `cyme` will use the 'usb-ids' crate, which is the same source as the hwdb binary data but the bundled hwdb may differ due to customisations or last update ('usb-ids' will be most up to date).

## Alias `lsusb`

Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pub mod system_profiler;
pub mod types;
#[cfg(all(target_os = "linux", feature = "udev"))]
pub mod udev;
#[cfg(all(all(target_os = "linux", feature = "udevlib"), not(feature = "udev")))]
#[path = "udev_ffi.rs"]
pub mod udev;
pub mod usb;

/// Set cyme module and binary log level
Expand Down
Loading

0 comments on commit acd9ffa

Please sign in to comment.