From 4b5fa2ea6b86a7766c9503f01524681602732656 Mon Sep 17 00:00:00 2001 From: Fo <26b95bff27431f3eaab8@wajo.ai> Date: Sun, 25 Oct 2026 14:28:55 +0000 Subject: [PATCH 1/2] build: make horizon-dualsense compile on iOS hidapi 2.6.7 has no iOS backend, so the crate failed to build for aarch64-apple-ios (hidapi's build script looked for hid.h). Gate the hidapi and cpal dependencies plus all HID device/haptics code behind cfg(not(target_os = "ios")) and provide an inert stub on iOS (Link::start() is a no-op), mirroring how horizon-gamecontroller already compiles empty on iOS. Verified with cargo check -p horizon-dualsense --target aarch64-apple-ios: clean, no warnings. Host clippy/tests are left to CI (this sandbox has no C toolchain for the host target). Co-Authored-By: Fo <26b95bff27431f3eaab8@wajo.ai> --- crates/horizon-dualsense/Cargo.toml | 8 +++- crates/horizon-dualsense/src/device.rs | 47 ++++++++++++++++---- crates/horizon-dualsense/src/haptics_stub.rs | 21 +++++++++ crates/horizon-dualsense/src/lib.rs | 6 +++ 4 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 crates/horizon-dualsense/src/haptics_stub.rs diff --git a/crates/horizon-dualsense/Cargo.toml b/crates/horizon-dualsense/Cargo.toml index fe05b4f59..1a41e5703 100644 --- a/crates/horizon-dualsense/Cargo.toml +++ b/crates/horizon-dualsense/Cargo.toml @@ -7,10 +7,16 @@ rust-version = "1.85" description = "The DualSense's output over HID: rumble, adaptive triggers, lightbar and player LEDs" [dependencies] +log = "0.4" + +# hidapi has no iOS backend and its build script stops there, so the output's two +# dependencies go only to the targets that have one. On iOS the crate builds empty: pads +# are read through GameController (horizon-gamecontroller), which only reads, and the +# DualSense's own output waits for a desktop. +[target.'cfg(not(target_os = "ios"))'.dependencies] # MIT; bundles the C hidapi under its BSD licence option. hidraw on Linux (libudev, as gilrs), # IOKit on macOS (opened shared, so gilrs keeps reading the pad), the HID API on Windows. hidapi = { version = "2.6.7", default-features = false, features = ["linux-static-hidraw", "macos-shared-device"] } -log = "0.4" # HD haptics through the pad's own audio device (USB). cpal = "0.16" diff --git a/crates/horizon-dualsense/src/device.rs b/crates/horizon-dualsense/src/device.rs index 97c6ec72b..0b11ac415 100644 --- a/crates/horizon-dualsense/src/device.rs +++ b/crates/horizon-dualsense/src/device.rs @@ -1,14 +1,21 @@ //! The pad over hidapi, and the thread that writes to it: writes block (a Bluetooth report can //! take milliseconds), so the game only hands over what the pad should do. -use crate::{ - DEFAULT_LIGHTBAR, Output, PLAYER_1, TRIGGER_OFF, TriggerEffect, Vibration, is_dualsense, -}; +#[cfg(not(target_os = "ios"))] +use crate::{DEFAULT_LIGHTBAR, Output, PLAYER_1, Vibration, is_dualsense}; +use crate::{TRIGGER_OFF, TriggerEffect}; +#[cfg(not(target_os = "ios"))] use hidapi::{BusType, HidApi, HidDevice, HidResult}; use std::sync::Arc; -use std::sync::atomic::{AtomicBool, AtomicU8, Ordering}; -use std::sync::mpsc::{self, RecvTimeoutError, Sender}; +#[cfg(not(target_os = "ios"))] +use std::sync::atomic::AtomicBool; +use std::sync::atomic::{AtomicU8, Ordering}; +use std::sync::mpsc::Sender; +#[cfg(not(target_os = "ios"))] +use std::sync::mpsc::{self, RecvTimeoutError}; use std::thread::JoinHandle; -use std::time::{Duration, Instant}; +use std::time::Duration; +#[cfg(not(target_os = "ios"))] +use std::time::Instant; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Transport { @@ -17,6 +24,7 @@ pub enum Transport { } /// An open DualSense. +#[cfg(not(target_os = "ios"))] pub struct DualSense { device: HidDevice, transport: Transport, @@ -34,6 +42,7 @@ pub fn bluetooth_allowed() -> bool { cfg!(target_os = "linux") || std::env::var_os("HORIZON_DUALSENSE_BT").is_some_and(|v| v == "1") } +#[cfg(not(target_os = "ios"))] impl DualSense { /// The first DualSense hidapi lists, USB before Bluetooth (as SDL); `None` when there is /// none, an error when it can't be opened (Linux without access to its hidraw node). @@ -119,13 +128,17 @@ impl Default for State { /// A vibration: the motors' levels (left, right), each for a while, in order. pub type Rumble = Vec<([u8; 2], Duration)>; +// On iOS no thread reads the queue (the Link never opens); the variants stay so the +// Link's API is the same everywhere. +#[cfg_attr(target_os = "ios", allow(dead_code))] enum Message { State(State), Rumble(Rumble), Scan, } -/// The writer thread. Dropping it frees the triggers and stops the motors before it ends. +/// The output thread. Dropping it frees the triggers and stops the motors before it ends; on +/// iOS there is none (no hidapi backend) and the Link stays closed. pub struct Link { tx: Option>, /// 0: no pad open, else 1 + the transport. @@ -135,6 +148,7 @@ pub struct Link { impl Link { /// Start the thread and look for a DualSense. + #[cfg(not(target_os = "ios"))] pub fn start() -> Link { let (tx, rx) = mpsc::channel(); let open = Arc::new(AtomicU8::new(0)); @@ -151,6 +165,17 @@ impl Link { } } + /// No output on iOS: hidapi has no backend there, and iOS reads pads through + /// GameController (horizon-gamecontroller), which only reads. The Link never opens. + #[cfg(target_os = "ios")] + pub fn start() -> Link { + Link { + tx: None, + open: Arc::new(AtomicU8::new(0)), + thread: None, + } + } + /// The pad's transport while one is open and taking reports. pub fn open(&self) -> Option { match self.open.load(Ordering::Relaxed) { @@ -194,8 +219,10 @@ impl Drop for Link { /// Looks for the pad this many more times, a second apart, after a scan finds nothing (its /// hidraw node may appear after the controller does). +#[cfg(not(target_os = "ios"))] const SCAN_TRIES: u32 = 5; +#[cfg(not(target_os = "ios"))] struct Writer { api: Option, pad: Option, @@ -213,6 +240,7 @@ struct Writer { next_scan: Instant, } +#[cfg(not(target_os = "ios"))] #[derive(Clone, Copy, Debug, PartialEq)] enum Lights { /// Over Bluetooth, until the pad's clock says its animation is over (or this long after @@ -225,11 +253,13 @@ enum Lights { /// The pad's sensor clock once its Bluetooth connection animation is over (SDL_hidapi_ps5.c's /// `HIDAPI_DriverPS5_CheckPendingLEDReset`). +#[cfg(not(target_os = "ios"))] const ANIMATION_OVER: u32 = 10_200_000; /// The sensor clock of a Bluetooth input report 0x31: its state block starts at byte 2 and /// holds the clock at 27..31, little-endian (SDL's `PS5StatePacketCommon_t`, the kernel's /// `dualsense_input_report`). +#[cfg(not(target_os = "ios"))] fn bluetooth_clock(report: &[u8]) -> Option { match report { [0x31, _, state @ ..] if state.len() >= 31 => { @@ -239,6 +269,7 @@ fn bluetooth_clock(report: &[u8]) -> Option { } } +#[cfg(not(target_os = "ios"))] impl Writer { fn new(open: Arc) -> Self { Writer { @@ -451,7 +482,7 @@ impl Writer { } } -#[cfg(test)] +#[cfg(all(test, not(target_os = "ios")))] mod tests { use super::*; diff --git a/crates/horizon-dualsense/src/haptics_stub.rs b/crates/horizon-dualsense/src/haptics_stub.rs new file mode 100644 index 000000000..7afc944ca --- /dev/null +++ b/crates/horizon-dualsense/src/haptics_stub.rs @@ -0,0 +1,21 @@ +//! No HD haptics on iOS: the trick plays vibrations through the pad's own four-channel audio +//! device over USB, and a phone has neither that device nor the audio stack the real module +//! needs. The motors' rumble through [`crate::Link`] covers vibration instead. + +/// The pad's audio output, playing the queued samples (left, right actuator). +pub struct Haptics; + +impl Haptics { + /// The DualSense's audio device, if one is there with its four channels (USB). A phone + /// has none. + pub fn open() -> Option { + None + } + + /// Play a vibration (heavy and light levels, 0..1, each for a while), replacing the one + /// playing. Nothing plays on iOS. + pub fn play(&self, _steps: &[(f32, f32, std::time::Duration)]) {} + + /// Stop at once. Nothing plays on iOS. + pub fn stop(&self) {} +} diff --git a/crates/horizon-dualsense/src/lib.rs b/crates/horizon-dualsense/src/lib.rs index 438d8f6fe..80831ee00 100644 --- a/crates/horizon-dualsense/src/lib.rs +++ b/crates/horizon-dualsense/src/lib.rs @@ -1,12 +1,18 @@ //! The DualSense's output report, built by hand (docs/controllers.md "DualSense output"): the //! compatible-vibration motors, the adaptive triggers, the lightbar and the player LEDs. Gilrs //! keeps reading the pad; this crate only writes to it, over hidapi ([`device`]). +//! On iOS the crate builds without hidapi, which has no backend there: [`Link`] never opens, +//! and the pad is read through GameController, which only reads. //! //! The byte layout is the one documented by the Linux kernel's `hid-playstation.c` and SDL's //! `SDL_hidapi_ps5.c`: a 47-byte block shared by both transports, sent as report 0x02 over USB //! and as report 0x31 over Bluetooth, where a sequence tag leads it and a CRC-32 (seeded with //! the byte 0xA2) closes it. pub mod device; +#[cfg(not(target_os = "ios"))] +pub mod haptics; +#[cfg(target_os = "ios")] +#[path = "haptics_stub.rs"] pub mod haptics; pub mod trigger; From 5ee1130719904c4101a0b13748fc53b1adaab1ee Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 17:53:13 +0100 Subject: [PATCH 2/2] horizon-dualsense: iOS comments name only what exists The repo has no horizon-gamecontroller crate, and on iOS the Link never opens, so no rumble covers vibration there. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-dualsense/Cargo.toml | 5 ++--- crates/horizon-dualsense/src/device.rs | 3 +-- crates/horizon-dualsense/src/haptics_stub.rs | 5 ++--- crates/horizon-dualsense/src/lib.rs | 3 +-- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/crates/horizon-dualsense/Cargo.toml b/crates/horizon-dualsense/Cargo.toml index 1a41e5703..feb25026b 100644 --- a/crates/horizon-dualsense/Cargo.toml +++ b/crates/horizon-dualsense/Cargo.toml @@ -10,9 +10,8 @@ description = "The DualSense's output over HID: rumble, adaptive triggers, light log = "0.4" # hidapi has no iOS backend and its build script stops there, so the output's two -# dependencies go only to the targets that have one. On iOS the crate builds empty: pads -# are read through GameController (horizon-gamecontroller), which only reads, and the -# DualSense's own output waits for a desktop. +# dependencies go only to the targets that have one. On iOS the crate builds without +# output: the Link never opens. [target.'cfg(not(target_os = "ios"))'.dependencies] # MIT; bundles the C hidapi under its BSD licence option. hidraw on Linux (libudev, as gilrs), # IOKit on macOS (opened shared, so gilrs keeps reading the pad), the HID API on Windows. diff --git a/crates/horizon-dualsense/src/device.rs b/crates/horizon-dualsense/src/device.rs index 0b11ac415..f8e544ea6 100644 --- a/crates/horizon-dualsense/src/device.rs +++ b/crates/horizon-dualsense/src/device.rs @@ -165,8 +165,7 @@ impl Link { } } - /// No output on iOS: hidapi has no backend there, and iOS reads pads through - /// GameController (horizon-gamecontroller), which only reads. The Link never opens. + /// No output on iOS: hidapi has no backend there. The Link never opens. #[cfg(target_os = "ios")] pub fn start() -> Link { Link { diff --git a/crates/horizon-dualsense/src/haptics_stub.rs b/crates/horizon-dualsense/src/haptics_stub.rs index 7afc944ca..dc4e61667 100644 --- a/crates/horizon-dualsense/src/haptics_stub.rs +++ b/crates/horizon-dualsense/src/haptics_stub.rs @@ -1,6 +1,5 @@ -//! No HD haptics on iOS: the trick plays vibrations through the pad's own four-channel audio -//! device over USB, and a phone has neither that device nor the audio stack the real module -//! needs. The motors' rumble through [`crate::Link`] covers vibration instead. +//! No HD haptics on iOS: they play through the pad's own four-channel audio device over USB, +//! which needs cpal, and cpal is left out there with hidapi (see Cargo.toml). /// The pad's audio output, playing the queued samples (left, right actuator). pub struct Haptics; diff --git a/crates/horizon-dualsense/src/lib.rs b/crates/horizon-dualsense/src/lib.rs index 80831ee00..4ae55de9a 100644 --- a/crates/horizon-dualsense/src/lib.rs +++ b/crates/horizon-dualsense/src/lib.rs @@ -1,8 +1,7 @@ //! The DualSense's output report, built by hand (docs/controllers.md "DualSense output"): the //! compatible-vibration motors, the adaptive triggers, the lightbar and the player LEDs. Gilrs //! keeps reading the pad; this crate only writes to it, over hidapi ([`device`]). -//! On iOS the crate builds without hidapi, which has no backend there: [`Link`] never opens, -//! and the pad is read through GameController, which only reads. +//! On iOS the crate builds without hidapi, which has no backend there: [`Link`] never opens. //! //! The byte layout is the one documented by the Linux kernel's `hid-playstation.c` and SDL's //! `SDL_hidapi_ps5.c`: a 47-byte block shared by both transports, sent as report 0x02 over USB