Files
punktfunk/scripts/build-xcframework.sh
T
enricobuehler e1af4d57c6
ci / rust (push) Has been cancelled
feat(apple): iOS/iPadOS client — touch, pointer lock, shared SwiftUI shell
The whole client now runs on iPadOS/iOS from the same sources, first-lit live in the
iPad simulator against the real host at 1280x720@60 (60 fps on the HUD, capture state
machine active, mic permission flow shown).

- PunktfunkCore.xcframework grows iOS device + universal-simulator slices
  (BUILD_IOS=1; rustup targets aarch64-apple-ios{,-sim} + x86_64-apple-ios).
- The decode pump is extracted into a shared StreamPump (identical IDR re-gate logic on
  both platforms); the iOS StreamView (StreamViewIOS.swift) has the same name/signature
  as the macOS one, so ContentView & co. are byte-identical across platforms — hosted
  in a UIViewController for prefersPointerLocked (the iPadOS cursor capture; see README
  note 9 for the UIHostingController forwarding caveat).
- Touch is always forwarded: per-finger wire ids, coordinates mapped through the
  aspect-fit letterbox into LIVE host-mode pixels (surface == host mode, identity
  rescale host-side; follows mid-stream requestMode switches).
- InputCapture is cross-platform: GC works the same on iPadOS, ⌘⎋ is detected from the
  HID stream there; stale-⌘ tracking after focus loss fixed on both platforms
  (releaseAll now drops the modifier/latch state — a ⌘ released in another app
  otherwise hijacked Esc forever).
- SessionAudio: AVAudioSession on iOS (.playAndRecord + .defaultToSpeaker — without it
  iPhones route host audio to the EARPIECE; deactivated with
  notifyOthersOnDeactivation on stop so interrupted background audio resumes); HAL
  device pinning + the Settings pickers stay macOS-only.
- New Punktfunk-iOS app target (shared synchronized sources, generated Info.plist with
  mic + local-network usage descriptions — QUIC to a LAN host trips local network
  privacy on real devices — scene manifest + indirect input events for Stage Manager /
  external displays), shared scheme, macOS min-window frames gated off iOS.

For the iPad-on-an-external-screen idea: with multiple scenes + indirect input enabled,
Stage Manager iPads can drag the punktfunk window onto the external display and drive
the PC with keyboard/mouse/touch. Known gaps (README note 9): the pointer-lock
preference isn't consulted through UIHostingController (relative mouse works, the local
cursor just stays visible) and AVAudioSession interruptions don't auto-restart audio.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 11:18:25 +02:00

78 lines
3.5 KiB
Bash

#!/usr/bin/env bash
# Build PunktfunkCore.xcframework for the Apple clients — run ON A MAC with Xcode + rustup.
#
# rustup target add aarch64-apple-darwin x86_64-apple-darwin # + aarch64-apple-ios for iOS
# bash scripts/build-xcframework.sh
#
# Output: clients/apple/PunktfunkCore.xcframework (consumed by clients/apple/Package.swift).
# The library is built WITH the `quic` feature (the punktfunk/1 connection API), so the bundled
# header gets PUNKTFUNK_FEATURE_QUIC pre-defined — Swift sees punktfunk_connect & co. unconditionally.
set -euo pipefail
cd "$(dirname "$0")/.."
TARGETS_MAC=(aarch64-apple-darwin x86_64-apple-darwin)
BUILD_IOS="${BUILD_IOS:-0}" # BUILD_IOS=1 adds iOS device + simulator slices (rustup targets aarch64-apple-ios{,-sim})
# Deployment targets must match Package.swift's platforms, or every consumer link emits
# "object file was built for newer macOS version" warnings.
for t in "${TARGETS_MAC[@]}"; do
MACOSX_DEPLOYMENT_TARGET=14.0 cargo build --release -p punktfunk-core --features quic --target "$t"
done
if [[ "$BUILD_IOS" == "1" ]]; then
IPHONEOS_DEPLOYMENT_TARGET=17.0 cargo build --release -p punktfunk-core --features quic --target aarch64-apple-ios
IPHONEOS_DEPLOYMENT_TARGET=17.0 cargo build --release -p punktfunk-core --features quic --target aarch64-apple-ios-sim
IPHONEOS_DEPLOYMENT_TARGET=17.0 cargo build --release -p punktfunk-core --features quic --target x86_64-apple-ios
fi
STAGE="$(mktemp -d)"
trap 'rm -rf "$STAGE"' EXIT
# Universal macOS static lib.
mkdir -p "$STAGE/macos"
lipo -create \
target/aarch64-apple-darwin/release/libpunktfunk_core.a \
target/x86_64-apple-darwin/release/libpunktfunk_core.a \
-output "$STAGE/macos/libpunktfunk_core.a"
# Headers dir: the generated C header (with the quic API force-enabled) + a modulemap so
# Swift can `import PunktfunkCore`.
mkdir -p "$STAGE/include"
{
echo "#define PUNKTFUNK_FEATURE_QUIC 1"
cat include/punktfunk_core.h
} > "$STAGE/include/punktfunk_core.h"
cat > "$STAGE/include/module.modulemap" <<'EOF'
module PunktfunkCore {
header "punktfunk_core.h"
export *
}
EOF
ARGS=(-library "$STAGE/macos/libpunktfunk_core.a" -headers "$STAGE/include")
if [[ "$BUILD_IOS" == "1" ]]; then
# Universal simulator lib (arm64 Macs run arm64 sims, but generic builds link x86_64 too).
mkdir -p "$STAGE/iossim"
lipo -create \
target/aarch64-apple-ios-sim/release/libpunktfunk_core.a \
target/x86_64-apple-ios/release/libpunktfunk_core.a \
-output "$STAGE/iossim/libpunktfunk_core.a"
ARGS+=(-library target/aarch64-apple-ios/release/libpunktfunk_core.a -headers "$STAGE/include")
ARGS+=(-library "$STAGE/iossim/libpunktfunk_core.a" -headers "$STAGE/include")
fi
# Cargo does NOT fingerprint MACOSX_DEPLOYMENT_TARGET — units cached from a build without
# it keep their old minos forever. Refuse to ship anything newer than the package floor
# (objects BELOW it, e.g. rustup's precompiled std at 11.0, are fine and unavoidable).
for obj in "$STAGE"/macos/libpunktfunk_core.a; do
bad=$(otool -l "$obj" 2>/dev/null | awk '/minos/ {print $2}' | sort -uV | awk -F. '$1 > 14' | head -1)
if [[ -n "$bad" ]]; then
echo "ERROR: $obj contains objects built for macOS $bad (> 14.0)." >&2
echo "Stale cache — rm -rf target/{aarch64,x86_64}-apple-darwin and rebuild." >&2
exit 1
fi
done
rm -rf clients/apple/PunktfunkCore.xcframework
xcodebuild -create-xcframework "${ARGS[@]}" -output clients/apple/PunktfunkCore.xcframework
echo "OK: clients/apple/PunktfunkCore.xcframework"