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

Replace libusb with pure Rust nusb #26

Merged
merged 53 commits into from
Oct 16, 2024
Merged

Replace libusb with pure Rust nusb #26

merged 53 commits into from
Oct 16, 2024

Conversation

tuna-f1sh
Copy link
Owner

@tuna-f1sh tuna-f1sh commented Aug 7, 2024

Creates a Profiler trait that provides both libusb and nusb system USB profilers. I've kept 'libusb' as an optional feature for those wishing to keep using that and for exact parity with lsusb; they should both output the same but lsusb uses libusb of course.

  • Since nusb uses IOkit (same as system_profiler command), use this for all macOS profiling by default instead of parsing system_profiler or at least default merge if different - bus names seem to be missing. left this as a TODO one day.
  • Refactor repeat code in the profilers so that the different args (device, handle etc) are contained within the profiler struct and they can be universal.
  • Wait for release with Add DeviceInfo::port_chain kevinmehall/nusb#71 to not have [patch.io] in Crate.toml. Need my fork at the moment anyway for listing hubs in devices on Windows.
  • Update/add missing documentation.
  • Move profilers into separate backend files.

Closes #17.

@tuna-f1sh tuna-f1sh marked this pull request as draft August 7, 2024 14:25
@tuna-f1sh tuna-f1sh force-pushed the nusb branch 7 times, most recently from 696fa98 to eb73ab9 Compare August 9, 2024 13:38
@tuna-f1sh
Copy link
Owner Author

tuna-f1sh commented Aug 12, 2024

Some notes:

  • nusb - does not profile root_hubs - design choice - unlike libusb. Not massive issue since they are not very useful but it does make a difference to --lsusb and --tree outputs, where these are displayed.
  • Created some features to control libc and pure Rust: 'native' uses nusb and udevrs; 'libc' uses rusb (libusb) and udev (libudev).

Due to output changes for --lsusb --verbose and --tree on Linux, I'll keep 'libusb' as the default but now but users can optionally build with out this dependency (pure Rust) using --no-default-features -F=native.

@tuna-f1sh
Copy link
Owner Author

tuna-f1sh commented Aug 23, 2024

nusb is actually more feature rich than libusb with my added list_root_hubs fork. I can build the 'root hub' Bus abstraction over the HCI on all platforms. With the pci.ids crate, vendor and device information is gathered too.

  • Windows: bus numbers are not a thing so the profiler has a cache of each root hub instance discovered, incrementing a bus number on each new one and assigning devices that have this as their 'bus_id' to it.
  • macOS: uses IOKit to read HCI (xHCI, EHCI, OCHI and VHCI) host controllers. The inclusion of VHCI means that even the devices on T2 Intel Macbooks (Facetime camera etc.) have a bus without using system_profiler.
  • Linux: same as libusb; is kernel generated root hub 'device'.

Considering this, I'll make 'native' the default and probably change behaviour on macOS so that is uses this rather than system_profiler since the data should be the same (via IOKit) and is actually more verbose.

@tuna-f1sh
Copy link
Owner Author

Windows example:

Screenshot 2024-08-23 at 11 37 26

@tuna-f1sh
Copy link
Owner Author

Example of macOS full bus information from nusb fork:

Screenshot 2024-08-23 at 15 03 43

@tuna-f1sh tuna-f1sh merged commit 9b60ec4 into main Oct 16, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace rusb (libusb bindings) with native Rust
1 participant