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

Put use of Apple SDK behind feature #126

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ nix = { version = "0.26", default-features = false, features = ["fs", "ioctl", "
[target.'cfg(all(target_os = "linux", not(target_env = "musl")))'.dependencies]
libudev = { version = "0.3.0", optional = true }

[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
CoreFoundation-sys = "0.1.4"
IOKit-sys = "0.1.5"
mach2 = "0.4.1"
[target.'cfg(target_os = "macos")'.dependencies]
CoreFoundation-sys = { version = "0.1.4", optional = true }
IOKit-sys = { version = "0.1.5", optional = true }
mach2 = { version = "0.4.1", optional = true }

[target.'cfg(target_os = "ios")'.dependencies]
CoreFoundation-sys = { version = "0.1.4" }
IOKit-sys = { version = "0.1.5" }
mach2 = { version = "0.4.1" }

[target."cfg(windows)".dependencies]
regex = "1.5.5"
Expand All @@ -34,7 +39,7 @@ regex = "1.5.5"
version = "0.3.9"
features = [
"cguid", "commapi", "errhandlingapi", "fileapi", "guiddef", "handleapi", "minwinbase",
"minwindef", "ntdef", "setupapi", "winbase", "winerror", "winnt",
"minwindef", "ntdef", "setupapi", "winbase", "winerror", "winnt"
]

[dependencies]
Expand All @@ -50,3 +55,4 @@ default = ["libudev"]
# TODO: Make the feature unconditionally available with the next major release
# (5.0) and remove this feature gate.
usbportinfo-interface = []
applesdk = ["CoreFoundation-sys", "IOKit-sys", "mach2"]
32 changes: 16 additions & 16 deletions src/posix/enumerate.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#[cfg(any(target_os = "ios", target_os = "macos"))]
#[cfg(any(target_os = "ios", all(target_os = "macos", feature = "applesdk")))]
use nix::libc::{c_char, c_void};
#[cfg(all(target_os = "linux", not(target_env = "musl"), feature = "libudev"))]
#[cfg(any(target_os = "ios", all(target_os = "macos", feature = "applesdk")))]
use std::ffi::OsStr;
#[cfg(any(target_os = "ios", target_os = "macos"))]
#[cfg(any(target_os = "ios", all(target_os = "macos", feature = "applesdk")))]
use std::ffi::{CStr, CString};
#[cfg(any(target_os = "ios", target_os = "macos"))]
#[cfg(any(target_os = "ios", all(target_os = "macos", feature = "applesdk")))]
use std::mem::MaybeUninit;

use cfg_if::cfg_if;
#[cfg(any(target_os = "ios", target_os = "macos"))]
#[cfg(any(target_os = "ios", all(target_os = "macos", feature = "applesdk")))]
use CoreFoundation_sys::*;
#[cfg(any(target_os = "ios", target_os = "macos"))]
#[cfg(any(target_os = "ios", all(target_os = "macos", feature = "applesdk")))]
use IOKit_sys::*;

#[cfg(any(
Expand All @@ -21,16 +21,16 @@
))]
use crate::SerialPortType;
#[cfg(any(
target_os = "ios",
all(target_os = "ios", feature = "applesdk"),
all(target_os = "linux", not(target_env = "musl"), feature = "libudev"),
target_os = "macos"
all(target_os = "macos", feature = "applesdk"),
))]
use crate::UsbPortInfo;
#[cfg(any(
target_os = "android",
target_os = "ios",
all(target_os = "ios", feature = "applesdk"),
all(target_os = "linux", not(target_env = "musl"), feature = "libudev"),
target_os = "macos",
all(target_os = "macos", feature = "applesdk"),
target_os = "netbsd",
target_os = "openbsd",
))]
Expand All @@ -42,7 +42,7 @@
#[cfg(all(target_os = "linux", not(target_env = "musl"), feature = "libudev"))]
fn udev_property_as_string(d: &libudev::Device, key: &str) -> Option<String> {
d.property_value(key)
.and_then(OsStr::to_str)

Check failure on line 45 in src/posix/enumerate.rs

View workflow job for this annotation

GitHub Actions / lint

failed to resolve: use of undeclared type `OsStr`
.map(|s| s.to_string())
}

Expand All @@ -58,7 +58,7 @@
key: &str,
from_str_radix: &dyn Fn(&str, u32) -> std::result::Result<T, std::num::ParseIntError>,
) -> Result<T> {
if let Some(hex_str) = d.property_value(key).and_then(OsStr::to_str) {

Check failure on line 61 in src/posix/enumerate.rs

View workflow job for this annotation

GitHub Actions / lint

failed to resolve: use of undeclared type `OsStr`
if let Ok(num) = from_str_radix(hex_str, 16) {
Ok(num)
} else {
Expand All @@ -71,7 +71,7 @@

#[cfg(all(target_os = "linux", not(target_env = "musl"), feature = "libudev"))]
fn port_type(d: &libudev::Device) -> Result<SerialPortType> {
match d.property_value("ID_BUS").and_then(OsStr::to_str) {

Check failure on line 74 in src/posix/enumerate.rs

View workflow job for this annotation

GitHub Actions / lint

failed to resolve: use of undeclared type `OsStr`
Some("usb") => {
let serial_number = udev_property_as_string(d, "ID_SERIAL_SHORT");
Ok(SerialPortType::UsbPort(UsbPortInfo {
Expand Down Expand Up @@ -120,7 +120,7 @@
}
}

#[cfg(any(target_os = "ios", target_os = "macos"))]
#[cfg(any(target_os = "ios", all(target_os = "macos", feature = "applesdk")))]
fn get_parent_device_by_type(
device: io_object_t,
parent_type: *const c_char,
Expand All @@ -147,7 +147,7 @@
}
}

#[cfg(any(target_os = "ios", target_os = "macos"))]
#[cfg(any(target_os = "ios", all(target_os = "macos", feature = "applesdk")))]
#[allow(non_upper_case_globals)]
/// Returns a specific property of the given device as an integer.
fn get_int_property(
Expand Down Expand Up @@ -198,7 +198,7 @@
}
}

#[cfg(any(target_os = "ios", target_os = "macos"))]
#[cfg(any(target_os = "ios", all(target_os = "macos", feature = "applesdk")))]
/// Returns a specific property of the given device as a string.
fn get_string_property(device_type: io_registry_entry_t, property: &str) -> Option<String> {
unsafe {
Expand Down Expand Up @@ -237,7 +237,7 @@
}
}

#[cfg(any(target_os = "ios", target_os = "macos"))]
#[cfg(any(target_os = "ios", all(target_os = "macos", feature = "applesdk")))]
/// Determine the serial port type based on the service object (like that returned by
/// `IOIteratorNext`). Specific properties are extracted for USB devices.
fn port_type(service: io_object_t) -> SerialPortType {
Expand Down Expand Up @@ -274,7 +274,7 @@
}

cfg_if! {
if #[cfg(any(target_os = "ios", target_os = "macos"))] {
if #[cfg(any(target_os = "ios", all(target_os = "macos", feature = "applesdk")))] {
/// Scans the system for serial ports and returns a list of them.
/// The `SerialPortInfo` struct contains the name of the port which can be used for opening it.
pub fn available_ports() -> Result<Vec<SerialPortInfo>> {
Expand Down Expand Up @@ -505,7 +505,7 @@
}
Ok(vec)
}
} else if #[cfg(target_os = "freebsd")] {
} else if #[cfg(any(target_os = "freebsd", all(target_os = "macos", not(feature = "applesdk"))))] {
use std::path::Path;

/// Scans the system for serial ports and returns a list of them.
Expand Down
Loading