Skip to content

Include android cfg preprocessor to all linux available paths - #1

Open
chris2402 wants to merge 1 commit into
mainfrom
chris/android-as-linux
Open

Include android cfg preprocessor to all linux available paths#1
chris2402 wants to merge 1 commit into
mainfrom
chris/android-as-linux

Conversation

@chris2402

@chris2402 chris2402 commented May 26, 2026

Copy link
Copy Markdown
Collaborator

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 cfg gates 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 thread src/device.rs
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 thread src/device.rs
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"))]
Comment thread src/enumeration.rs
#[derive(Clone)]
pub struct DeviceInfo {
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "android"))]
Comment thread src/enumeration.rs
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 thread src/enumeration.rs
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 thread src/enumeration.rs
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 thread src/enumeration.rs
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"))]
Comment thread examples/control.rs
@@ -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
chris2402 marked this pull request as ready for review May 26, 2026 14:27
@chris2402
chris2402 requested a review from smy-huddly May 26, 2026 14:27
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.

2 participants