Skip to content

Add iOS/ipadOS support - #957

Open
nat3Github wants to merge 4 commits into
david-vanderson:mainfrom
nat3Github:mobile
Open

Add iOS/ipadOS support#957
nat3Github wants to merge 4 commits into
david-vanderson:mainfrom
nat3Github:mobile

Conversation

@nat3Github

@nat3Github nat3Github commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator

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.

zig build  run-sdl3-ios   Build and run the SDL3 iOS/iPadOS example app in a Simulator (macOS host only)

update 2:
ive gotten it to run on my iphone SE2 device, (open xcode project, setup credentials, connect/setup iphone and click play),

  • runs and displays the demo app,
  • touch interaction works.
  • keyboard shows up for text inputs
  • variable framerate is working properly

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:

  • testing text input from external keyboard like magic keyboard (dont have one of those unfortunately, anyone?)

- 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).
@david-vanderson

Copy link
Copy Markdown
Owner

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"):

dvanderson@Davids-Air dvui % zig build run-sdl3-ios
No .xcodeproj found in examples/ios-example/xcode-project -- generating from project.yml...
⚙️  Generating plists...
⚙️  Generating project...
⚙️  Writing project...
Created project at /Users/dvanderson/code/dvui/examples/ios-example/xcode-project/dvui-ios-hello.xcodeproj
error: could not find a scheme in examples/ios-example/xcode-project/dvui-ios-hello.xcodeproj
run-sdl3-ios
└─ run sh failure
error: process exited with error code 1
failed command: XCODE_PROJECT_DIR=examples/ios-example/xcode-project CONFIGURATION=Debug ZIG_OPTIMIZE=Debug SIMULATOR_DEVICE_FILTER=iPhone sh tools/build-apple/run-sim.sh

Build Summary: 0/2 steps succeeded (1 failed)
run-sdl3-ios transitive failure
└─ run sh failure

error: the following build command failed with exit code 1:
.zig-cache/o/ec6660d10daf24ba266f8d15122b4d60/build /Users/dvanderson/apps/zig-aarch64-macos-0.16.0/zig /Users/dvanderson/apps/zig-aarch64-macos-0.16.0/lib /Users/dvanderson/code/dvui .zig-cache /Users/dvanderson/.cache/zig --seed 0xd15ccaf -Zefd7e452a1254bf5 run-sdl3-ios

Any ideas?

@nat3Github

nat3Github commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

Any ideas?

what comes up if you run

cd examples/ios-example/xcode-project/
xcodebuild -list

apparently my xcode setup is different from yours, xcodegen created the project but without scheme and my xcodebuild had no issue with that.
could you pull and retry running

zig build run-sdl3-ios

@david-vanderson

Copy link
Copy Markdown
Owner

what comes up if you run

cd examples/ios-example/xcode-project/
xcodebuild -list

This is confusing - I get:
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

Some searching suggests I need to do:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

After that:

dvanderson@Davids-Air xcode-project % xcodebuild -list                                                     
Command line invocation:
    /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -list

User defaults from command line:
    IDEPackageSupportUseBuiltinSCM = YES

2026-08-21 08:56:36.687 xcodebuild[91421:36074417] Writing error result bundle to /var/folders/h8/zhz6g77j6sj6w9rghz8f917c0000gn/T/ResultBundle_2026-21-08_08-56-0036.xcresult
xcodebuild: error: Unable to read project 'dvui-ios-hello.xcodeproj'.
	Reason: The project ‘dvui-ios-hello’ cannot be opened because it is in a future Xcode project file format (77). Adjust the project format using a compatible version of Xcode to allow it to be opened by this version of Xcode.

Looks like my xcode version Version 15.4 (15F31d) is too old, and my mac is too old to update.

I'm good with you merging this, we'll have to wait for someone else to verify it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants