Add iOS/ipadOS support - #957
Conversation
- sdl.zig: route iOS through SDL's callback-loop path (same as macOS/Windows) instead of the blocking main()/SDL_PollEvent loop. On iOS, SDL_PollEvent is what pumps UIKit_PumpEvents, so the first paint happened before UIKit had laid out the view/drawable, producing a black screen. - ios-example main.zig: run dvui's shared demo/gallery app (dvui.Examples.demo) instead of a static "Hello" label, matching the android-example pattern. - xcode-project: add the zig-project side (build.zig, main.zig) and the xcodegen project.yml/Info.plist/main.c that the Xcode project is generated from; the .xcodeproj itself is generated on demand by tools/build-apple/run-sim.sh, not committed. Verified on iPhone 16 Pro Simulator: rebuilt the simulator static lib, rebuilt the Xcode project, installed and launched, and confirmed via screenshot that the full demo app renders correctly.
Replace the .path dependency on vendor/sdl3-ios (a patched copy of the SDL3
fork with an .ios build.zig case hand-added) with a fetched dependency on
nat3Github/lib-sdl3-dev-fork's ios-support branch, which carries the same
patch. linkSdl3 no longer special-cases which sdl3 dependency to use per
target -- one dependency covers every target, iOS included -- and exposes
the SDL3 static lib + headers via a new installIosSdl3() helper so the iOS
example's build.zig doesn't need its own sdl3 dependency.
Add tools/build-apple/{build_apple.zig,run-sim.sh}, wiring a `zig build
run-sdl3-ios` step (macOS host only) that builds the Xcode project and boots
it in a Simulator.
Fix a UBSan runtime-not-bundled link failure this surfaced: on iOS, Xcode's
linker (not zig) links the app's static lib against SDL3's separately-built
static lib, so a default sanitize_c (full in Debug) leaves libSDL3.a with
__ubsan_handle_* symbols zig never bundled a runtime for. Every other target
links through zig itself, which bundles ubsan into the one binary, so this
is iOS-only -- turn sanitize_c off for iOS in linkSdl3's sdl3 dependency and
addDvuiModule's own C sources (stb_image).
Verified end-to-end: `zig build run-sdl3-ios` builds, installs, and launches
the demo app in an iPhone simulator.
SDL_StartTextInput unconditionally re-applies text input properties on every call, which on iOS tears the hidden UITextField out of the view hierarchy and re-adds it. sdl.zig called it every frame while a field had focus, thrashing the keyboard so it never settled into view. Only call through on an actual rect change now, mirroring the existing cursor_last dedup. Also stop rendering every CADisplayLink tick unconditionally on iOS; throttle using dvui's own wait_event_micros instead, while still responding immediately to real input events. Add UIApplicationSupportsIndirectInputEvents to the example Info.plist so trackpad/mouse input works when a pointer is attached (e.g. iPad).
|
This is awesome, and I'm trying to verify it using the simulator on my mac, but hitting this error ("could not find a scheme"): Any ideas? |
what comes up if you run apparently my xcode setup is different from yours, xcodegen created the project but without scheme and my xcodebuild had no issue with that. |
This is confusing - I get: Some searching suggests I need to do: After that: Looks like my xcode version I'm good with you merging this, we'll have to wait for someone else to verify it. Thank you! |
towards #953
note: support enabled via sdl3 in this branch https://github.com/nat3Github/lib-sdl3-dev-fork (which is pinned in .zon)
xcode is required and a mac of course.
update 2:
ive gotten it to run on my iphone SE2 device, (open xcode project, setup credentials, connect/setup iphone and click play),
update 3:
it works also on my iPad device (note: iphone/ipad developer mode has to be enabled for testing, but its mainly friction less using the xcode app)
todo: