Skip to content

Commit

Permalink
Have USB compilation be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
jkcoxson committed Sep 13, 2022
1 parent a3dbd87 commit 4417009
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ log = { version = "*" }
env_logger = { version = "*" }
colored = { version = "*" }

rusb = { version = "*" }
libusb1-sys = { version = "*" }
rusb = { version = "*", optional = true }
libusb1-sys = { version = "*", optional = true }

[features]
usb = [ "libusb1-sys", "rusb" ]
2 changes: 2 additions & 0 deletions src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl SharedDevices {
self.devices.insert(udid, dev);
}

#[cfg(feature = "usb")]
pub fn add_usb_device(&mut self, udid: String, _data: Arc<Mutex<Self>>) {
self.last_index += 1;
self.last_interface_index += 1;
Expand Down Expand Up @@ -226,6 +227,7 @@ impl SharedDevices {
Err(())
}

#[cfg(feature = "usb")]
pub fn check_udid(&mut self, udid: String) -> bool {
if self.paired_udids.contains(&udid) {
return true;
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod devices;
mod heartbeat;
mod mdns;
mod raw_packet;
#[cfg(feature = "usb")]
mod usb;

#[tokio::main]
Expand All @@ -37,6 +38,7 @@ async fn main() {
let mut use_unix = true;

let mut use_mdns = true;
#[cfg(feature = "usb")]
let mut use_usb = false;

// Loop through args
Expand Down Expand Up @@ -64,6 +66,7 @@ async fn main() {
use_mdns = false;
i += 1;
}
#[cfg(feature = "usb")]
"--enable-usb" => {
use_usb = true;
i += 1;
Expand All @@ -79,6 +82,7 @@ async fn main() {
#[cfg(unix)]
println!(" --disable-unix");
println!(" --enable-mdns");
#[cfg(feature = "usb")]
println!(" --enable-usb (unusable for now)");
println!(" -h, --help");
println!(" --about");
Expand All @@ -100,6 +104,7 @@ async fn main() {
let data = Arc::new(Mutex::new(devices::SharedDevices::new(plist_storage)));
info!("Created new central data");
let data_clone = data.clone();
#[cfg(feature = "usb")]
let usb_data = data.clone();

if let Some(host) = host.clone() {
Expand Down Expand Up @@ -157,6 +162,7 @@ async fn main() {
});
}

#[cfg(feature = "usb")]
if use_usb {
usb::start_listener(usb_data);
}
Expand Down

0 comments on commit 4417009

Please sign in to comment.