diff --git a/adb_client/Cargo.toml b/adb_client/Cargo.toml index 590f75a..3faaa3e 100644 --- a/adb_client/Cargo.toml +++ b/adb_client/Cargo.toml @@ -10,6 +10,10 @@ repository.workspace = true rust-version.workspace = true version.workspace = true +[features] +default = ["mdns"] +mdns = ["dep:mdns-sd"] + [dependencies] base64 = { version = "0.22.1" } bincode = { version = "1.3.3" } @@ -18,9 +22,6 @@ chrono = { version = "0.4.40", default-features = false, features = ["std"] } homedir = { version = "= 0.3.4" } image = { version = "0.25.5", default-features = false } log = { version = "0.4.26" } -mdns-sd = { version = "0.13.9", default-features = false, features = [ - "logging", -] } num-bigint = { version = "0.8.4", package = "num-bigint-dig" } num-traits = { version = "0.2.19" } quick-protobuf = { version = "0.8.1" } @@ -39,6 +40,11 @@ serde_repr = { version = "0.1.19" } sha1 = { version = "0.10.6", features = ["oid"] } thiserror = { version = "2.0.7" } +# MDNS +mdns-sd = { version = "0.13.9", default-features = false, optional = true, features = [ + "logging", +] } + [dev-dependencies] anyhow = { version = "1.0.93" } criterion = { version = "0.6.0" } # Used for benchmarks diff --git a/adb_client/src/error.rs b/adb_client/src/error.rs index 0164211..ed18b1a 100644 --- a/adb_client/src/error.rs +++ b/adb_client/src/error.rs @@ -112,6 +112,7 @@ pub enum RustADBError { #[error("upgrade error: {0}")] UpgradeError(String), /// An error occurred while getting mdns devices + #[cfg(feature = "mdns")] #[error(transparent)] MDNSError(#[from] mdns_sd::Error), /// An error occurred while sending data to channel diff --git a/adb_client/src/lib.rs b/adb_client/src/lib.rs index 8c88387..093afa9 100644 --- a/adb_client/src/lib.rs +++ b/adb_client/src/lib.rs @@ -9,6 +9,7 @@ mod constants; mod device; mod emulator_device; mod error; +#[cfg(feature = "mdns")] mod mdns; mod models; mod server; @@ -20,6 +21,7 @@ pub use adb_device_ext::ADBDeviceExt; pub use device::{ADBTcpDevice, ADBUSBDevice, is_adb_device, search_adb_devices}; pub use emulator_device::ADBEmulatorDevice; pub use error::{Result, RustADBError}; +#[cfg(feature = "mdns")] pub use mdns::*; pub use models::{AdbStatResponse, RebootType}; pub use server::*; diff --git a/adb_client/src/models/adb_server_command.rs b/adb_client/src/models/adb_server_command.rs index 8790fbc..7bdac16 100644 --- a/adb_client/src/models/adb_server_command.rs +++ b/adb_client/src/models/adb_server_command.rs @@ -18,7 +18,9 @@ pub(crate) enum AdbServerCommand { Pair(SocketAddrV4, String), TransportAny, TransportSerial(String), + #[cfg(feature = "mdns")] MDNSCheck, + #[cfg(feature = "mdns")] MDNSServices, ServerStatus, ReconnectOffline, @@ -77,7 +79,9 @@ impl Display for AdbServerCommand { write!(f, "reverse:forward:{remote};{local}") } AdbServerCommand::ReverseRemoveAll => write!(f, "reverse:killforward-all"), + #[cfg(feature = "mdns")] AdbServerCommand::MDNSCheck => write!(f, "host:mdns:check"), + #[cfg(feature = "mdns")] AdbServerCommand::MDNSServices => write!(f, "host:mdns:services"), AdbServerCommand::ServerStatus => write!(f, "host:server-status"), AdbServerCommand::Reconnect => write!(f, "reconnect"), diff --git a/adb_client/src/server/commands/mdns.rs b/adb_client/src/server/commands/mdns.rs index 05a8f28..1c0e87b 100644 --- a/adb_client/src/server/commands/mdns.rs +++ b/adb_client/src/server/commands/mdns.rs @@ -6,6 +6,7 @@ use crate::{ const OPENSCREEN_MDNS_BACKEND: &str = "ADB_MDNS_OPENSCREEN"; +#[cfg(feature = "mdns")] impl ADBServer { /// Check if mdns discovery is available pub fn mdns_check(&mut self) -> Result { diff --git a/adb_client/src/server/commands/mod.rs b/adb_client/src/server/commands/mod.rs index 4a1b77f..a2d2085 100644 --- a/adb_client/src/server/commands/mod.rs +++ b/adb_client/src/server/commands/mod.rs @@ -2,6 +2,7 @@ mod connect; mod devices; mod disconnect; mod kill; +#[cfg(feature = "mdns")] mod mdns; mod pair; mod reconnect; diff --git a/adb_client/src/server/models/mod.rs b/adb_client/src/server/models/mod.rs index 0cbdb8e..a046a81 100644 --- a/adb_client/src/server/models/mod.rs +++ b/adb_client/src/server/models/mod.rs @@ -2,6 +2,7 @@ mod adb_version; mod device_long; mod device_short; mod device_state; +#[cfg(feature = "mdns")] mod mdns_services; mod server_status; mod wait_for_device; @@ -10,6 +11,7 @@ pub use adb_version::AdbVersion; pub use device_long::DeviceLong; pub use device_short::DeviceShort; pub use device_state::DeviceState; +#[cfg(feature = "mdns")] pub use mdns_services::MDNSServices; pub use server_status::{MDNSBackend, ServerStatus}; pub use wait_for_device::{WaitForDeviceState, WaitForDeviceTransport};