Include android cfg preprocessor to all linux available paths - #1
Open
chris2402 wants to merge 1 commit into
Open
Include android cfg preprocessor to all linux available paths#1chris2402 wants to merge 1 commit into
chris2402 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR broadens Linux usbfs-related code paths so Android can use the same enumeration, hotplug, bus/device metadata, and kernel-driver APIs where applicable.
Changes:
- Enables linux_usbfs enumeration and hotplug modules on Android.
- Widens Linux-specific
cfggates in device and enumeration APIs to include Android. - Updates the control-transfer example cfg to include Android.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
src/platform/linux_usbfs/mod.rs |
Enables enumeration and hotplug modules for Android. |
src/platform/linux_usbfs/device.rs |
Uses sysfs-aware device creation and kernel-driver attach/detach paths on Android. |
src/lib.rs |
Exposes bus listing, device listing, hotplug, and BusInfo without the previous platform gate. |
src/enumeration.rs |
Extends Linux-style device/bus metadata APIs to Android. |
src/device.rs |
Enables kernel-driver attach/detach wrappers on Android. |
examples/control.rs |
Includes Android in the platform cfg for control transfers without claiming an interface. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
102
to
+105
| /// This function can only detach kernel drivers on Linux. Calling on other platforms has | ||
| /// no effect. | ||
| pub fn detach_kernel_driver(&self, interface: u8) -> Result<(), Error> { | ||
| #[cfg(target_os = "linux")] | ||
| #[cfg(any(target_os = "linux", target_os = "android"))] |
Comment on lines
115
to
+118
| /// This function can only attach kernel drivers on Linux. Calling on other platforms has | ||
| /// no effect. | ||
| pub fn attach_kernel_driver(&self, interface: u8) -> Result<(), Error> { | ||
| #[cfg(target_os = "linux")] | ||
| #[cfg(any(target_os = "linux", target_os = "android"))] |
| #[derive(Clone)] | ||
| pub struct DeviceInfo { | ||
| #[cfg(target_os = "linux")] | ||
| #[cfg(any(target_os = "linux", target_os = "android"))] |
Comment on lines
463
to
+467
| /// * Linux: `path`, `busnum`, `root_hub` | ||
| /// * Windows: `instance_id`, `parent_instance_id`, `location_paths`, `devinst`, `root_hub_description` | ||
| /// * macOS: `registry_id`, `location_id`, `name`, `provider_class_name`, `class_name` | ||
| #[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))] | ||
| pub struct BusInfo { | ||
| #[cfg(any(target_os = "linux"))] | ||
| #[cfg(any(target_os = "linux", target_os = "android"))] |
Comment on lines
517
to
+518
| /// *(Linux-only)* Sysfs path for the bus. | ||
| #[cfg(any(target_os = "linux"))] | ||
| #[cfg(any(target_os = "linux", target_os = "android"))] |
Comment on lines
523
to
525
| /// *(Linux-only)* Bus number. | ||
| /// | ||
| /// On Linux, the `bus_id` is an integer and this provides the value as `u8`. |
Comment on lines
531
to
+532
| /// *(Linux-only)* The root hub [`DeviceInfo`] representing the bus. | ||
| #[cfg(any(target_os = "linux"))] | ||
| #[cfg(any(target_os = "linux", target_os = "android"))] |
| @@ -18,7 +18,7 @@ fn main() { | |||
| let device = di.open().wait().unwrap(); | |||
|
|
|||
| // Linux can make control transfers without claiming an interface | |||
Comment on lines
13
to
15
| mod hotplug; | ||
|
|
||
| #[cfg(not(target_os = "android"))] | ||
| pub(crate) use hotplug::LinuxHotplugWatch as HotplugWatch; |
chris2402
marked this pull request as ready for review
May 26, 2026 14:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
nusb project considers only Android sandboxed (user-space) application API's and gates required endpoints behind compiler flags.
What
Changed all compiler flag preprocessors where Linux is allowed to also allow Android.
Warning
This is for testing a prototype of rust-sdk with nusb