iOS Platform

engine-core, engine-platform, engine-render-device, engine-gfx, engine-ui, and the stage crates build for aarch64-apple-ios (device) and aarch64-apple-ios-sim (Apple silicon simulator). All iOS-specific code sits behind cfg(target_os = "ios") or the shared metal cfg used by macOS and iOS alike.

Differences from macOS

  • Metal — Uses the same Metal backend (objc2-metal). CAMetalDisplayLink requires iOS 17, so the default deployment target is 17.0 (IPHONEOS_DEPLOYMENT_TARGET).
  • SDL3 — Linked statically (libSDL3.a). sdl3-sys enables its no-link feature on iOS, and engine-gfx's build script links libSDL3.a and the required Apple frameworks once.
  • Entry point — UIKit owns the main thread: an app's main calls engine_platform::ios::run_app(app), and SDL invokes app on the main thread after launch.
  • Lifecycle — engine_platform::ios::watch_lifecycle (started by Platform::new) intercepts SDL_EVENT_WILL_ENTER_BACKGROUND and SDL_EVENT_DID_ENTER_FOREGROUND immediately so no GPU work submits while backgrounded (which iOS terminates). engine_ui::Host emits Event::Background and Event::Foreground, skips presentation while backgrounded, and redraws on return.
  • Touch, safe area, orientation, scale — Event::Touch { finger, phase, x, y, pressure } arrives in logical pixels alongside synthesized pointer events. Host::safe_area(), Host::orientation(), and Host::pixel_density() report display geometry; changes emit Event::Resize.
  • Bundle files — engine_platform::ios::bundle_directory() (SDL_GetBasePath) locates the app bundle; engine_assets::bundled_assets resolves assets/ inside it automatically.
  • Not available on iOS — Host::native_window is null, windows cannot be moved or resized, folder dialogs and system cursors are no-ops, and BC-compressed textures are unavailable on iOS GPUs.

Building Static SDL3

Build SDL3 from an official source release using CMake, Ninja, and Xcode (keep source and build output outside the repository):

sh
curl -LO https://github.com/libsdl-org/SDL/releases/download/release-3.4.20/SDL3-3.4.20.tar.gz
tar xzf SDL3-3.4.20.tar.gz
bun build/sdl3-ios.ts SDL3-3.4.20 sdl3-ios
export ENGINE_SDL3_IOS_DIR=$PWD/sdl3-ios   # contains iphoneos/ and iphonesimulator/ with libSDL3.a

Shaders

Compile Metal libraries for both iOS SDKs alongside macOS:

sh
bun build/build.ts shaders --ios

This writes metal-iphoneos/ and metal-iphonesimulator/ beside metal/ in the shader directory. Point ENGINE_SHADER_DIR to that directory when building for iOS; each crate's build script selects the matching SDK folder.

Host stage materials and post steps built with bun build/stage-materials.ts --ios select metal/, metal-iphonesimulator/, or metal-iphoneos/ automatically via cfg attributes, requiring no iOS-specific host build script logic.

Building & Running Samples

Run from the Xodó repository root:

sh
export ENGINE_SDL3_IOS_DIR=/path/to/sdl3-ios
export ENGINE_SHADER_DIR=$PWD/target/build/device-shaders
export IPHONEOS_DEPLOYMENT_TARGET=17.0

cargo build --locked --target aarch64-apple-ios-sim -p engine-ui
bun samples/ios-ui/run.ts --device "iPhone 17" --screenshot shot.png
bun samples/ios-stage/run.ts --device "iPhone 17" --screenshot shot.png

samples/ios-ui and samples/ios-stage are standalone workspaces. run.ts compiles for the simulator, bundles the .app, ad-hoc signs it, and installs/launches via xcrun simctl. For physical devices, compile for aarch64-apple-ios, package into a bundle with the same Info.plist, and sign with a development identity and provisioning profile.