Skip to content

Commit 0d9bbcb

Browse files
committed
Avoid mach2 direct dependency
1 parent 83547a8 commit 0d9bbcb

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ project adheres to [Semantic Versioning](https://semver.org/).
2020
* Output USB VID and PID in hexadecimal digits in `UsbPortInfo`'s `Debug`
2121
representation.
2222
[#290](https://github.com/serialport/serialport-rs/pull/290)
23+
* Migrated away from unmaintainted dependency `mach2`.
2324

2425
### Fixed
2526
### Removed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ unescaper = "0.1.3"
2727
core-foundation = "=0.10.0"
2828
core-foundation-sys = "0.8.4"
2929
io-kit-sys = "0.4.0"
30-
mach2 = "0.4.1"
3130

3231
[target."cfg(windows)".dependencies.windows-sys]
3332
version = "0.52.0"

src/posix/enumerate.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,20 @@ cfg_if! {
2020
use io_kit_sys::serial::keys::*;
2121
use io_kit_sys::types::*;
2222
use io_kit_sys::usb::lib::*;
23-
use nix::libc::{c_char, c_void};
24-
use std::ffi::CStr;
25-
use std::mem::MaybeUninit;
23+
use core::ffi::{c_char, c_int, c_uint, c_void, CStr};
24+
use core::mem::MaybeUninit;
25+
26+
// NOTE: Do not use `mach` nor `mach2` crates, they're unmaintained,
27+
// and don't work on tvOS/watchOS/visionOS.
28+
//
29+
// Instead, define the types ourselves, we use sufficiently little
30+
// that this is not a very hard task.
31+
#[allow(non_camel_case_types)]
32+
type kern_return_t = c_int;
33+
#[allow(non_camel_case_types)]
34+
type mach_port_t = c_uint;
35+
const KERN_SUCCESS: kern_return_t = 0;
36+
const MACH_PORT_NULL: mach_port_t = 0;
2637
}
2738
}
2839

@@ -265,7 +276,6 @@ fn get_parent_device_by_type(
265276
parent_type: *const c_char,
266277
) -> Option<io_registry_entry_t> {
267278
let parent_type = unsafe { CStr::from_ptr(parent_type) };
268-
use mach2::kern_return::KERN_SUCCESS;
269279
let mut device = device;
270280
loop {
271281
let mut class_name = MaybeUninit::<[c_char; 128]>::uninit();
@@ -379,9 +389,6 @@ cfg_if! {
379389
/// Scans the system for serial ports and returns a list of them.
380390
/// The `SerialPortInfo` struct contains the name of the port which can be used for opening it.
381391
pub fn available_ports() -> Result<Vec<SerialPortInfo>> {
382-
use mach2::kern_return::KERN_SUCCESS;
383-
use mach2::port::{mach_port_t, MACH_PORT_NULL};
384-
385392
let mut vec = Vec::new();
386393
unsafe {
387394
// Create a dictionary for specifying the search terms against the IOService

0 commit comments

Comments
 (0)