From 6575dddac7833835401074d9b18df135679a9f7c Mon Sep 17 00:00:00 2001 From: enricobuehler Date: Thu, 11 Jun 2026 09:07:48 +0200 Subject: [PATCH] fix: keep the workspace green on macOS after the mic/touch/rich-input batch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new features were Linux-built only and broke the documented macOS gate (cargo build/test/clippy --workspace) four ways, all fixed following the existing platform-gating conventions: - m3.rs: mic_service_thread split into the Linux worker and a non-Linux stub that drains and drops (sessions still count the datagrams) — opus/PipeWire are Linux-gated deps, same pattern as audio_thread. - punktfunk-client-rs: the new `opus` dependency moved into the Linux target table and --mic-test gated with a warn-and-skip stub (only the synthetic-tone test rig needs the encoder; the mic uplink itself is portable). - gamestream/audio.rs: SAMPLE_RATE import gated to any(linux, test) (the frame_sizing test uses it everywhere, the data plane only on Linux). - tests/c_abi.rs: the harness's macOS link flags gained Security + CoreFoundation — the quic feature now pulls rustls's platform verifier into the staticlib. Also: two clippy match-ref-pats lints in the new rich-input/HID-output decoders (clippy -D warnings is the repo gate), the regenerated punktfunk_core.h committed (the checked-in copy predated the rich-input/HID-output constants — CI fails on drift), and web's inlang cache dir gitignored. cargo build/test/clippy/fmt --workspace: green on macOS, 122 tests passing. Co-Authored-By: Claude Fable 5 --- crates/punktfunk-client-rs/Cargo.toml | 6 +++++- crates/punktfunk-client-rs/src/main.rs | 5 +++++ crates/punktfunk-core/src/quic.rs | 14 +++++++------- crates/punktfunk-core/tests/c_abi.rs | 11 ++++++++++- crates/punktfunk-host/src/gamestream/audio.rs | 1 + crates/punktfunk-host/src/m3.rs | 12 ++++++++++++ include/punktfunk_core.h | 17 ++++++++++++++++- web/.gitignore | 3 +++ 8 files changed, 59 insertions(+), 10 deletions(-) diff --git a/crates/punktfunk-client-rs/Cargo.toml b/crates/punktfunk-client-rs/Cargo.toml index 3d7c413..cb248b5 100644 --- a/crates/punktfunk-client-rs/Cargo.toml +++ b/crates/punktfunk-client-rs/Cargo.toml @@ -13,6 +13,10 @@ punktfunk-core = { path = "../punktfunk-core", features = ["quic"] } quinn = "0.11" tokio = { version = "1", features = ["rt-multi-thread", "net", "time", "macros"] } anyhow = "1" -opus = "0.3" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } + +# Linux-only: --mic-test's Opus encoder (libopus). The mic UPLINK itself is portable — +# only this synthetic-tone test rig needs the encoder. +[target.'cfg(target_os = "linux")'.dependencies] +opus = "0.3" diff --git a/crates/punktfunk-client-rs/src/main.rs b/crates/punktfunk-client-rs/src/main.rs index d71f14e..6dad850 100644 --- a/crates/punktfunk-client-rs/src/main.rs +++ b/crates/punktfunk-client-rs/src/main.rs @@ -360,6 +360,11 @@ async fn session(args: Args) -> Result<()> { // Mic plane: stream a synthetic 440 Hz tone as the mic uplink (0xCB), Opus-encoded 5 ms // stereo frames — proves client→host mic passthrough end to end without a real microphone // (the host decodes it into its virtual PipeWire source; record that source to hear the tone). + #[cfg(not(target_os = "linux"))] + if args.mic_test { + tracing::warn!("--mic-test requires Linux (libopus) — skipped"); + } + #[cfg(target_os = "linux")] if args.mic_test { let conn2 = conn.clone(); tokio::spawn(async move { diff --git a/crates/punktfunk-core/src/quic.rs b/crates/punktfunk-core/src/quic.rs index b2b2617..7feb26e 100644 --- a/crates/punktfunk-core/src/quic.rs +++ b/crates/punktfunk-core/src/quic.rs @@ -690,15 +690,15 @@ impl RichInput { if b.first() != Some(&RICH_INPUT_MAGIC) { return None; } - match b.get(1)? { - &RICH_TOUCHPAD if b.len() >= 9 => Some(RichInput::Touchpad { + match *b.get(1)? { + RICH_TOUCHPAD if b.len() >= 9 => Some(RichInput::Touchpad { pad: b[2], finger: b[3], active: b[4] != 0, x: u16::from_le_bytes([b[5], b[6]]), y: u16::from_le_bytes([b[7], b[8]]), }), - &RICH_MOTION if b.len() >= 15 => { + RICH_MOTION if b.len() >= 15 => { let i16at = |o: usize| i16::from_le_bytes([b[o], b[o + 1]]); Some(RichInput::Motion { pad: b[2], @@ -751,18 +751,18 @@ impl HidOutput { if b.first() != Some(&HIDOUT_MAGIC) { return None; } - match b.get(1)? { - &HIDOUT_LED if b.len() >= 6 => Some(HidOutput::Led { + match *b.get(1)? { + HIDOUT_LED if b.len() >= 6 => Some(HidOutput::Led { pad: b[2], r: b[3], g: b[4], b: b[5], }), - &HIDOUT_PLAYER_LEDS if b.len() >= 4 => Some(HidOutput::PlayerLeds { + HIDOUT_PLAYER_LEDS if b.len() >= 4 => Some(HidOutput::PlayerLeds { pad: b[2], bits: b[3], }), - &HIDOUT_TRIGGER if b.len() >= 4 => Some(HidOutput::Trigger { + HIDOUT_TRIGGER if b.len() >= 4 => Some(HidOutput::Trigger { pad: b[2], which: b[3], effect: b[4..].to_vec(), diff --git a/crates/punktfunk-core/tests/c_abi.rs b/crates/punktfunk-core/tests/c_abi.rs index b35f353..2cf0a0b 100644 --- a/crates/punktfunk-core/tests/c_abi.rs +++ b/crates/punktfunk-core/tests/c_abi.rs @@ -12,7 +12,16 @@ use std::process::Command; /// `rustc --print native-static-libs`. fn native_libs() -> &'static [&'static str] { if cfg!(target_os = "macos") { - &["-liconv", "-lm"] + // The workspace build unifies features into the staticlib, and `quic` pulls + // rustls's platform verifier → Security/CoreFoundation. + &[ + "-liconv", + "-lm", + "-framework", + "Security", + "-framework", + "CoreFoundation", + ] } else if cfg!(target_os = "linux") { &["-lgcc_s", "-lutil", "-lrt", "-lpthread", "-lm", "-ldl"] } else { diff --git a/crates/punktfunk-host/src/gamestream/audio.rs b/crates/punktfunk-host/src/gamestream/audio.rs index 65f0691..3f665a1 100644 --- a/crates/punktfunk-host/src/gamestream/audio.rs +++ b/crates/punktfunk-host/src/gamestream/audio.rs @@ -17,6 +17,7 @@ //! data packets are consumed immediately and missing parity only costs loss recovery — so //! the validated stereo path stays byte-identical (data packets only, exactly as before). +#[cfg(any(target_os = "linux", test))] use crate::audio::SAMPLE_RATE; #[cfg(target_os = "linux")] use { diff --git a/crates/punktfunk-host/src/m3.rs b/crates/punktfunk-host/src/m3.rs index 40c0a78..dcd439d 100644 --- a/crates/punktfunk-host/src/m3.rs +++ b/crates/punktfunk-host/src/m3.rs @@ -806,10 +806,22 @@ impl MicService { } } +/// Stub — mic passthrough needs Linux (PipeWire source + libopus); non-Linux dev builds +/// drain and drop the frames (sessions still count the datagrams), same as when the +/// source fails to open. +#[cfg(not(target_os = "linux"))] +fn mic_service_thread(rx: std::sync::mpsc::Receiver>) { + tracing::warn!( + "punktfunk/1 mic passthrough requires Linux (PipeWire + libopus) — frames dropped" + ); + for _ in rx {} +} + /// The host-lifetime mic worker: lazily open the virtual mic + decoder, then Opus-decode each /// forwarded frame and push the PCM into the source. Reopen (after [`INJECTOR_REOPEN_BACKOFF`]) /// on open failure or a decode error. Exits when every session sender and the service's own /// sender drop (host shutdown), tearing the PipeWire source down. +#[cfg(target_os = "linux")] fn mic_service_thread(rx: std::sync::mpsc::Receiver>) { let mut mic: Option> = None; let mut decoder: Option = None; diff --git a/include/punktfunk_core.h b/include/punktfunk_core.h index df6ed8f..3875db3 100644 --- a/include/punktfunk_core.h +++ b/include/punktfunk_core.h @@ -137,7 +137,8 @@ // Datagram wire tags. Video rides UDP; everything low-rate rides QUIC datagrams, // demultiplexed by the first byte: input = [`crate::input::INPUT_MAGIC`] (0xC8, client→host), // audio = [`AUDIO_MAGIC`] (0xC9, host→client), rumble = [`RUMBLE_MAGIC`] (0xCA, host→client), -// mic = [`MIC_MAGIC`] (0xCB, client→host). +// mic = [`MIC_MAGIC`] (0xCB, client→host), rich-input = [`RICH_INPUT_MAGIC`] (0xCC, client→host), +// HID-output = [`HIDOUT_MAGIC`] (0xCD, host→client). #define PUNKTFUNK_AUDIO_MAGIC 201 #endif @@ -151,6 +152,20 @@ #define MIC_MAGIC 203 #endif +#if defined(PUNKTFUNK_FEATURE_QUIC) +// Rich client→host input: events too big for the fixed 18-byte [`InputEvent`] +// (crate::input::InputEvent) — the DualSense touchpad and motion sensors. Variable-length, +// kind-tagged (see [`RichInput`]). +#define RICH_INPUT_MAGIC 204 +#endif + +#if defined(PUNKTFUNK_FEATURE_QUIC) +// HID output, host → client: DualSense feedback a game wrote to the host's virtual controller +// (lightbar, player LEDs, adaptive triggers) — the rich analog of [`RUMBLE_MAGIC`]. See +// [`HidOutput`]. +#define HIDOUT_MAGIC 205 +#endif + // Stable C ABI status codes. `Ok` is 0; all errors are negative so callers can // test `rc < 0`. Do not renumber existing variants — only append. enum PunktfunkStatus diff --git a/web/.gitignore b/web/.gitignore index b43183e..875cb46 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -12,3 +12,6 @@ src/paraglide # local env (PUNKTFUNK_UI_PASSWORD etc.) .env + +# Paraglide/inlang machine-local cache: +project.inlang/cache