Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(native): iOS app target — the JS host on iPhone

esenginef8b5293895fb
diff --git a/.gitignore b/.gitignore
index a34d3d9ef..a49498dd7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -122,3 +122,6 @@ docs/REARCH_*.md
**/.esengine/play/
**/.esengine/sdk/
**/.esengine/editor/
+
+# Generated by xcodegen from native/ios/project.yml
+native/ios/*.xcodeproj/
diff --git a/build-tools/cli.js b/build-tools/cli.js
index 5bd54880f..649f3b55d 100644
--- a/build-tools/cli.js
+++ b/build-tools/cli.js
@@ -159,22 +159,26 @@ program
program
.command('native')
- .description('Build the native (embedded-Dawn) host for Android arm64')
+ .description('Build the native (embedded-Dawn) host for Android or iOS arm64')
+ .option('--target <target>', 'android or ios', 'android')
.option('--dawn <dir>', 'Dawn source dir (or ESTELLA_DAWN_DIR); see native/README.md')
- .option('--dawn-build <dir>', 'Dawn arm64 build dir (or ESTELLA_DAWN_BUILD)')
+ .option('--dawn-build <dir>', 'Dawn arm64 build dir for this target (or ESTELLA_DAWN_BUILD)')
.option('--quickjs <dir>', 'QuickJS-ng source dir (or ESTELLA_QUICKJS_DIR); also builds the JS host')
.option('--abi <abi>', 'Android ABI', 'arm64-v8a')
.option('--platform <platform>', 'Android platform', 'android-33')
+ .option('--ios-min <version>', 'iOS deployment target', '17.0')
.option('-v, --verbose', 'Verbose output', false)
.action(async (options) => {
logger.setVerbose(options.verbose);
try {
await buildNative({
+ target: options.target,
dawn: options.dawn,
dawnBuild: options.dawnBuild,
quickjs: options.quickjs,
abi: options.abi,
platform: options.platform,
+ iosMin: options.iosMin,
});
} catch (err) {
logger.error(err.message);
diff --git a/build-tools/tasks/native.js b/build-tools/tasks/native.js
index ec1d7e5ee..eaee39f68 100644
--- a/build-tools/tasks/native.js
+++ b/build-tools/tasks/native.js
@@ -2,10 +2,11 @@
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
//
// The native (embedded-Dawn) host build — the arm64 sibling of the emscripten
-// wasm build. It drives native/CMakeLists.txt through the NDK toolchain, sharing
-// cmake/ESEngineSources.cmake with the web build so the engine source list never
-// drifts. Dawn is fetched + built separately (see native/README.md); pass its
-// paths via --dawn / --dawn-build or ESTELLA_DAWN_DIR / ESTELLA_DAWN_BUILD.
+// wasm build. It drives native/CMakeLists.txt: through the NDK toolchain for
+// Android, through the iOS SDK for iPhone. Both share cmake/ESEngineSources.cmake
+// with the web build so the engine source list never drifts. Dawn is fetched +
+// built separately, per platform (see native/README.md); pass its paths via
+// --dawn / --dawn-build or ESTELLA_DAWN_DIR / ESTELLA_DAWN_BUILD.
import path from 'path';
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'fs';
@@ -78,7 +79,38 @@ async function generateSdkBundle(rootDir, genDir) {
return headerPath;
}
-export async function buildNative(options = {}) {
+// Both generated artifacts go in the build tree; nothing committed can drift from
+// the reflection / SDK source.
+async function prepareGenerated(rootDir, buildDir, quickjs) {
+ if (!existsSync(quickjs)) {
+ throw new Error(`QuickJS source dir not found: ${quickjs}. Clone `
+ + 'https://github.com/quickjs-ng/quickjs (see native/README.md).');
+ }
+ const genDir = path.join(buildDir, 'gen');
+ await mkdir(genDir, { recursive: true });
+ const python = await resolvePython() ?? 'python3';
+ logger.step('Generating native ECS bindings (EHT, single reflection source)...');
+ await generateNativeBindings(rootDir, genDir, python);
+ logger.step('Embedding the real SDK bundle (dist/index.native.bundled.js)...');
+ await generateSdkBundle(rootDir, genDir);
+ return genDir;
+}
+
+function dawnPaths(options) {
+ const dawnDir = options.dawn || process.env.ESTELLA_DAWN_DIR;
+ const dawnBuild = options.dawnBuild || process.env.ESTELLA_DAWN_BUILD;
+ if (!dawnDir || !dawnBuild) {
+ throw new Error('Dawn not configured. Pass --dawn <src> --dawn-build <arm64 build>, or set '
+ + 'ESTELLA_DAWN_DIR / ESTELLA_DAWN_BUILD. Build Dawn per native/README.md.');
+ }
+ return { dawnDir, dawnBuild };
+}
+
+// CMake parses backslashes in -D string values as escapes (F:\estella -> \e), so
+// hand it forward-slash paths (valid on Windows too).
+const fwd = (p) => p.replace(/\\/g, '/');
+
+async function buildAndroidHost(options) {
const { abi = 'arm64-v8a', platform = 'android-33' } = options;
const rootDir = config.paths.root;
@@ -88,12 +120,7 @@ export async function buildNative(options = {}) {
if (!ndk) throw new Error(`No NDK under ${sdk}/ndk. Install one via Android Studio's SDK Manager.`);
const toolchain = path.join(ndk, 'build', 'cmake', 'android.toolchain.cmake');
- const dawnDir = options.dawn || process.env.ESTELLA_DAWN_DIR;
- const dawnBuild = options.dawnBuild || process.env.ESTELLA_DAWN_BUILD;
- if (!dawnDir || !dawnBuild) {
- throw new Error('Dawn not configured. Pass --dawn <src> --dawn-build <arm64 build>, or set '
- + 'ESTELLA_DAWN_DIR / ESTELLA_DAWN_BUILD. Build Dawn per native/README.md.');
- }
+ const { dawnDir, dawnBuild } = dawnPaths(options);
const { cmake, ninja } = sdkCmake(sdk);
const buildDir = path.join(rootDir, 'build-native');
@@ -101,23 +128,9 @@ export async function buildNative(options = {}) {
// JS host (opt-in): pass --quickjs <dir> (or ESTELLA_QUICKJS_DIR) to also build
// the QuickJS host — a game script driving the engine through the generated
- // bindings + the real SDK ptrAccessors. Both generated artifacts go in the
- // build tree; nothing committed can drift from the reflection / SDK source.
+ // bindings + the real SDK ptrAccessors.
const quickjs = options.quickjs || process.env.ESTELLA_QUICKJS_DIR;
- let genDir = null;
- if (quickjs) {
- if (!existsSync(quickjs)) {
- throw new Error(`QuickJS source dir not found: ${quickjs}. Clone `
- + 'https://github.com/quickjs-ng/quickjs (see native/README.md).');
- }
- genDir = path.join(buildDir, 'gen');
- await mkdir(genDir, { recursive: true });
- const python = await resolvePython() ?? 'python3';
- logger.step('Generating native ECS bindings (EHT, single reflection source)...');
- await generateNativeBindings(rootDir, genDir, python);
- logger.step('Embedding the real SDK bundle (dist/index.native.bundled.js)...');
- await generateSdkBundle(rootDir, genDir);
- }
+ const genDir = quickjs ? await prepareGenerated(rootDir, buildDir, quickjs) : null;
logger.step(`Configuring native host (${abi}, ${platform})...`);
const configureArgs = [
@@ -138,9 +151,6 @@ export async function buildNative(options = {}) {
];
if (ninja) configureArgs.push(`-DCMAKE_MAKE_PROGRAM=${ninja}`);
if (quickjs) {
- // CMake parses backslashes in -D string values as escapes (F:\estella -> \e),
- // so hand it forward-slash paths (valid on Windows too).
- const fwd = (p) => p.replace(/\\/g, '/');
configureArgs.push(`-DESTELLA_QUICKJS_DIR=${fwd(quickjs)}`, `-DESTELLA_NATIVE_GEN_DIR=${fwd(genDir)}`);
}
await runCommand(cmake, configureArgs, { cwd: rootDir });
@@ -153,3 +163,69 @@ export async function buildNative(options = {}) {
logger.success(`JS host: ${path.join('build-native', 'libestella_js_host.so')}`);
}
}
+
+// Xcode ships the iPhoneOS SDK; the Command Line Tools alone do not. Point the
+// toolchain at Xcode when the active developer dir can't produce one, so a machine
+// left on `xcode-select -s /Library/Developer/CommandLineTools` still builds.
+async function iosDeveloperDir() {
+ const probe = await runCommand('xcrun', ['--sdk', 'iphoneos', '--show-sdk-path'], { silent: true })
+ .catch(() => null);
+ if (probe?.stdout?.trim()) return null;
+ const xcode = '/Applications/Xcode.app/Contents/Developer';
+ if (!existsSync(xcode)) {
+ throw new Error('No iPhoneOS SDK. Install Xcode (the Command Line Tools alone cannot build for iOS).');
+ }
+ return xcode;
+}
+
+async function buildIosHost(options) {
+ if (process.platform !== 'darwin') throw new Error('The iOS host builds on macOS only.');
+ const rootDir = config.paths.root;
+ const { dawnDir, dawnBuild } = dawnPaths(options);
+
+ // Unlike Android there is no pure-C++ reference host for iOS: the app IS the
+ // JS host, so QuickJS is required rather than opt-in.
+ const quickjs = options.quickjs || process.env.ESTELLA_QUICKJS_DIR;
+ if (!quickjs) {
+ throw new Error('The iOS host needs QuickJS: pass --quickjs <dir> (or set ESTELLA_QUICKJS_DIR).');
+ }
+
+ const developerDir = await iosDeveloperDir();
+ const env = developerDir ? { DEVELOPER_DIR: developerDir } : undefined;
+ if (developerDir) logger.info(`Using DEVELOPER_DIR=${developerDir} (the active one has no iPhoneOS SDK)`);
+
+ const buildDir = path.join(rootDir, 'build-native-ios');
+ await mkdir(buildDir, { recursive: true });
+ const genDir = await prepareGenerated(rootDir, buildDir, quickjs);
+
+ const deploymentTarget = options.iosMin || '17.0';
+ logger.step(`Configuring iOS host (arm64, iOS ${deploymentTarget})...`);
+ await runCommand('cmake', [
+ '-S', path.join(rootDir, 'native'),
+ '-B', buildDir,
+ '-G', 'Ninja',
+ '-DCMAKE_SYSTEM_NAME=iOS',
+ '-DCMAKE_OSX_ARCHITECTURES=arm64',
+ `-DCMAKE_OSX_DEPLOYMENT_TARGET=${deploymentTarget}`,
+ '-DCMAKE_OSX_SYSROOT=iphoneos',
+ '-DCMAKE_BUILD_TYPE=Release',
+ '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
+ `-DESTELLA_DAWN_DIR=${fwd(dawnDir)}`,
+ `-DESTELLA_DAWN_BUILD=${fwd(dawnBuild)}`,
+ `-DESTELLA_QUICKJS_DIR=${fwd(quickjs)}`,
+ `-DESTELLA_NATIVE_GEN_DIR=${fwd(genDir)}`,
+ ], { cwd: rootDir, env });
+
+ logger.step('Building iOS host...');
+ await runCommand('cmake', ['--build', buildDir, '-j', String(getCpuCount())], { cwd: rootDir, env });
+
+ logger.success(`iOS host: ${path.join('build-native-ios', 'libestella_js_host.a')}`);
+ logger.info('Next: cd native/ios && xcodegen && open EstellaiOS.xcodeproj — pick your Team, then Run.');
+}
+
+export async function buildNative(options = {}) {
+ const target = (options.target || 'android').toLowerCase();
+ if (target === 'ios') return buildIosHost(options);
+ if (target !== 'android') throw new Error(`Unknown --target ${target} (expected android or ios).`);
+ return buildAndroidHost(options);
+}
diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt
index a1a4780b8..030b0a96a 100644
--- a/native/CMakeLists.txt
+++ b/native/CMakeLists.txt
@@ -1,7 +1,9 @@
# Estella native host — the engine C++ core compiled arm64 + linked against an
# embedded Dawn. Requires a Dawn checkout + arm64 build (see README.md):
# -DESTELLA_DAWN_DIR=<dawn source> -DESTELLA_DAWN_BUILD=<dawn arm64 build dir>
-# Invoke through the NDK toolchain file. NOT part of the web/emscripten build.
+# Android: invoke through the NDK toolchain file (Vulkan Dawn, shared library host).
+# iOS: -DCMAKE_SYSTEM_NAME=iOS (Metal Dawn, static library linked by a thin app).
+# NOT part of the web/emscripten build.
cmake_minimum_required(VERSION 3.22)
project(estella_native_host C CXX)
@@ -12,14 +14,39 @@ if(NOT ESTELLA_DAWN_DIR OR NOT ESTELLA_DAWN_BUILD)
message(FATAL_ERROR "Set ESTELLA_DAWN_DIR (Dawn source) and ESTELLA_DAWN_BUILD (Dawn arm64 build). See native/README.md.")
endif()
+if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
+ set(ESTELLA_IOS ON)
+elseif(NOT ANDROID)
+ message(FATAL_ERROR "Unsupported platform: configure with the NDK toolchain (Android) or -DCMAKE_SYSTEM_NAME=iOS.")
+endif()
+
set(REPO "${CMAKE_CURRENT_SOURCE_DIR}/..")
set(SRC "${REPO}/src")
set(TP "${REPO}/third_party")
-# Prebuilt monolithic Dawn (libwebgpu_dawn.so).
-add_library(webgpu_dawn SHARED IMPORTED)
-set_target_properties(webgpu_dawn PROPERTIES
- IMPORTED_LOCATION "${ESTELLA_DAWN_BUILD}/src/dawn/native/libwebgpu_dawn.so")
+# Prebuilt monolithic Dawn: a shared library on Android, a static one on iOS (where
+# the app embeds everything). Override ESTELLA_DAWN_LIB if your build lays it out
+# elsewhere.
+if(ESTELLA_IOS)
+ if(NOT ESTELLA_DAWN_LIB)
+ set(ESTELLA_DAWN_LIB "${ESTELLA_DAWN_BUILD}/src/dawn/native/libwebgpu_dawn.a")
+ endif()
+ add_library(webgpu_dawn STATIC IMPORTED)
+else()
+ if(NOT ESTELLA_DAWN_LIB)
+ set(ESTELLA_DAWN_LIB "${ESTELLA_DAWN_BUILD}/src/dawn/native/libwebgpu_dawn.so")
+ endif()
+ add_library(webgpu_dawn SHARED IMPORTED)
+endif()
+if(NOT EXISTS "${ESTELLA_DAWN_LIB}")
+ message(FATAL_ERROR "Dawn library not found: ${ESTELLA_DAWN_LIB}. Build Dawn for this platform (see native/README.md) or pass -DESTELLA_DAWN_LIB=<path>.")
+endif()
+set_target_properties(webgpu_dawn PROPERTIES IMPORTED_LOCATION "${ESTELLA_DAWN_LIB}")
+if(ESTELLA_IOS)
+ # Dawn's Metal backend pulls these in; a static Dawn does not carry them along.
+ set_target_properties(webgpu_dawn PROPERTIES
+ INTERFACE_LINK_LIBRARIES "-framework Metal;-framework QuartzCore;-framework Foundation;-framework IOSurface;-framework CoreGraphics")
+endif()
# glm + yoga (the engine's non-emscripten third-party deps).
add_library(glm INTERFACE)
@@ -31,10 +58,12 @@ add_library(yogacore STATIC ${YOGA_SOURCES})
target_include_directories(yogacore PUBLIC "${TP}")
target_compile_options(yogacore PRIVATE -Wno-unused-parameter)
-add_library(native_app_glue STATIC
- "${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c")
-target_include_directories(native_app_glue PUBLIC
- "${ANDROID_NDK}/sources/android/native_app_glue")
+if(ANDROID)
+ add_library(native_app_glue STATIC
+ "${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c")
+ target_include_directories(native_app_glue PUBLIC
+ "${ANDROID_NDK}/sources/android/native_app_glue")
+endif()
# The engine core, native arm64. The source list is the SAME single-source file the
# web build uses (cmake/ESEngineSources.cmake) — selecting the WebGPU backend and
@@ -60,9 +89,11 @@ target_link_libraries(esengine PUBLIC glm yogacore webgpu_dawn)
# Reference host: boots EstellaContext with an injected WebGPUDevice over the
# NativeActivity's ANativeWindow and renders one ECS scene. See host/main.cpp.
-add_library(estella_host SHARED host/main.cpp)
-target_link_libraries(estella_host esengine native_app_glue android log)
-set_target_properties(estella_host PROPERTIES LINK_FLAGS "-u ANativeActivity_onCreate")
+if(ANDROID)
+ add_library(estella_host SHARED host/main.cpp)
+ target_link_libraries(estella_host esengine native_app_glue android log)
+ set_target_properties(estella_host PROPERTIES LINK_FLAGS "-u ANativeActivity_onCreate")
+endif()
# JS host (opt-in): a QuickJS game script drives the engine through the
# EHT-generated bindings + the real SDK ptrAccessors. Built only when QuickJS is
@@ -90,11 +121,26 @@ if(ESTELLA_QUICKJS_DIR)
# js/host_core.cpp is the platform-independent host; each platform adds its own
# glue TU (the event loop, the window, the packaged assets).
- add_library(estella_js_host SHARED js/host_core.cpp js/main_android.cpp "${NATIVE_BINDINGS}")
+ if(ESTELLA_IOS)
+ # Static: the thin Xcode app (native/ios) links this plus the libraries
+ # below. -ObjC on the app keeps the Obj-C classes in main_ios.mm alive.
+ add_library(estella_js_host STATIC js/host_core.cpp js/main_ios.mm "${NATIVE_BINDINGS}")
+ target_link_libraries(estella_js_host esengine qjs
+ "-framework UIKit" "-framework QuartzCore" "-framework Foundation")
+ # Merge host + engine + deps + Dawn into ONE archive, so the Xcode app is a
+ # thin shell that links a single library at a fixed path (native/ios).
+ add_custom_command(TARGET estella_js_host POST_BUILD
+ COMMAND libtool -static -o "${CMAKE_BINARY_DIR}/libestella_ios.a"
+ $<TARGET_FILE:estella_js_host> $<TARGET_FILE:esengine>
+ $<TARGET_FILE:qjs> $<TARGET_FILE:yogacore> "${ESTELLA_DAWN_LIB}"
+ COMMENT "Merging the iOS host, engine and Dawn into libestella_ios.a")
+ else()
+ add_library(estella_js_host SHARED js/host_core.cpp js/main_android.cpp "${NATIVE_BINDINGS}")
+ target_link_libraries(estella_js_host esengine qjs native_app_glue android log)
+ set_target_properties(estella_js_host PROPERTIES LINK_FLAGS "-u ANativeActivity_onCreate")
+ endif()
# js/ holds esn_shim.hpp + host_core.hpp (the generated TU includes the shim);
# the gen dir holds ptraccessors_js.h and the embedded SDK bundle.
target_include_directories(estella_js_host PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/js" "${ESTELLA_NATIVE_GEN_DIR}")
- target_link_libraries(estella_js_host esengine qjs native_app_glue android log)
- set_target_properties(estella_js_host PROPERTIES LINK_FLAGS "-u ANativeActivity_onCreate")
endif()
diff --git a/native/README.md b/native/README.md
index 2407b33e9..3d922e19c 100644
--- a/native/README.md
+++ b/native/README.md
@@ -10,12 +10,20 @@ engine runs native (full speed), so only the game script is interpreted.
This directory holds two reference hosts + the build recipe:
- **`host/`** — a pure-C++ host that renders one ECS scene (no JS). A smoke test
- for the engine core on native Dawn. Always built.
+ for the engine core on native Dawn. Android only; always built there.
- **`js/`** — the JS host: a QuickJS game script drives the engine through the
**real esengine SDK**. The SDK is bundled to one file
(`dist/index.native.bundled.js`, installing `ESEngine`) and the game authors with
`ESEngine.createNativeWorld()` — the same `World` the web build uses. Built when
- you pass `--quickjs` (this is the product-shaped runtime).
+ you pass `--quickjs` (this is the product-shaped runtime). It is one host with a
+ platform seam, not one per OS:
+ - `js/host_core.{hpp,cpp}` — Dawn bring-up, the `es_*` bindings, the SDK bundle
+ and the frame. Platform-independent; everything that differs sits behind
+ `eshost::Platform`.
+ - `js/main_android.cpp` — NativeActivity, APK assets, Vulkan, the ALooper loop.
+ - `js/main_ios.mm` — a CAMetalLayer view, bundle assets, Metal, CADisplayLink.
+- **`ios/`** — the Xcode app shell (xcodegen) that signs and packages the iOS
+ build. It is only an entry point; the app lives in the static library.
Dawn and QuickJS are **not vendored** (multi-GB / separate project); the recipe
fetches them, the way Dawn fetches its own deps. Nothing here is compiled by the
@@ -33,6 +41,7 @@ the tree:
| GL / text gates | `EstellaContext` under `ES_PLATFORM_WEB` / `ES_ENABLE_BITMAP_TEXT` | native drops the WebGL entry + optional bitmap text |
| Bindings | `python -m eht --native-output` | `es_set_<C>` / `es_<C>_buffer` from the same reflection as the web embind bindings |
| Data marshalling | `sdk/src/ecs/ptrAccessors.generated.ts` | POD components are wasm32/arm64 layout-identical → the generated accessors write native component memory unchanged (via a zero-copy `ArrayBuffer`) |
+| Host platform | `eshost::Platform` (`js/host_core.hpp`) | packaged assets, cache dir, backend, window surface + size, log — the only things the two OS glue files answer differently |
## Build (Android arm64)
@@ -83,6 +92,44 @@ Package the APK by hand (no gradle): `aapt2 link` the matching manifest
`lib/arm64-v8a/{libestella*_host.so,libwebgpu_dawn.so,libc++_shared.so}` (strip
Dawn with `llvm-strip`), `zipalign -f 4`, `apksigner sign`.
+## Build (iOS arm64)
+
+Toolchain: Xcode (the Command Line Tools alone have no iPhoneOS SDK — `cli native`
+falls back to `/Applications/Xcode.app` automatically), CMake ≥ 3.22, Ninja, and
+[xcodegen](https://github.com/yonaskolb/XcodeGen) (`brew install xcodegen`).
+
+**One-time: build Dawn for iOS arm64** (Metal, *static* — an app embeds it):
+
+```sh
+cmake -S "$DAWN" -B "$DAWN/out-ios" -G Ninja \
+ -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES=arm64 \
+ -DCMAKE_OSX_DEPLOYMENT_TARGET=17.0 -DCMAKE_OSX_SYSROOT=iphoneos \
+ -DDAWN_ENABLE_METAL=ON -DDAWN_ENABLE_VULKAN=OFF -DDAWN_ENABLE_D3D12=OFF \
+ -DDAWN_ENABLE_NULL=OFF -DDAWN_ENABLE_OPENGLES=OFF -DDAWN_ENABLE_DESKTOP_GL=OFF \
+ -DDAWN_BUILD_SAMPLES=OFF -DDAWN_BUILD_TESTS=OFF -DTINT_BUILD_TESTS=OFF \
+ -DDAWN_BUILD_PROTOBUF=OFF -DTINT_BUILD_IR_BINARY=OFF \
+ -DDAWN_BUILD_MONOLITHIC_LIBRARY=STATIC -DDAWN_FETCH_DEPENDENCIES=OFF
+cmake --build "$DAWN/out-ios" --target webgpu_dawn
+```
+
+**Build the host, then run it from Xcode.** There is no pure-C++ reference host on
+iOS — the app *is* the JS host, so `--quickjs` is required:
+
+```sh
+(cd sdk && pnpm run build)
+node build-tools/cli.js native --target ios \
+ --dawn "$DAWN" --dawn-build "$DAWN/out-ios" --quickjs "$QJS"
+
+cd native/ios && xcodegen && open EstellaiOS.xcodeproj
+```
+
+Then pick your Team under *Signing & Capabilities*, select your device and Run.
+The CMake build merges host + engine + QuickJS + Dawn into one archive
+(`build-native-ios/libestella_ios.a`), so the Xcode project is a signing and
+packaging shell: `App/main.m` calls `EstellaRunApp()`, and the game (`js/game.js`,
+`js/logo.png`) ships as bundle resources — the same project-relative paths the APK
+serves from `assets/`.
+
## Gotchas (all resolved; each cost a build)
1. Dawn cross-compile wants a host `protoc` — `-DDAWN_BUILD_PROTOBUF=OFF`.
@@ -96,8 +143,13 @@ Dawn with `llvm-strip`), `zipalign -f 4`, `apksigner sign`.
## Status
-The engine core + render path are proven on device (Snapdragon 8 Elite / Adreno
-830, 120 fps). The JS host runs the **real SDK**: `ESEngine.createNativeApp()`
+**Android** is proven on device (Snapdragon 8 Elite / Adreno 830, 120 fps).
+**iOS** has its glue, its CMake target and its app shell, and compiles for
+arm64 — but it has not run on a device yet; it needs a Dawn-for-iOS build and
+your signing.
+
+The engine core + render path are proven on device. The JS host runs the **real
+SDK**: `ESEngine.createNativeApp()`
returns the same `App` + `World` the web build uses, connected to the native core
through the generated registry + memory backend; the host binds the entity /
hierarchy / component functions the SDK reads off `globalThis`, plus the input and
diff --git a/native/ios/App/Info.plist b/native/ios/App/Info.plist
new file mode 100644
index 000000000..e5327a2ba
--- /dev/null
+++ b/native/ios/App/Info.plist
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>Estella</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>UILaunchScreen</key>
+ <dict/>
+ <key>UIRequiredDeviceCapabilities</key>
+ <array>
+ <string>arm64</string>
+ <string>metal</string>
+ </array>
+ <key>UIStatusBarHidden</key>
+ <true/>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+ <key>UISupportedInterfaceOrientations~ipad</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+</dict>
+</plist>
diff --git a/native/ios/App/main.m b/native/ios/App/main.m
new file mode 100644
index 000000000..f373abcb8
--- /dev/null
+++ b/native/ios/App/main.m
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+//
+// The whole app target: the window, the view, the engine and the game all live in
+// libestella_ios.a (native/js/main_ios.mm). This is only an entry point, so the
+// Xcode project stays a signing + packaging shell.
+
+extern int EstellaRunApp(int argc, char** argv);
+
+int main(int argc, char** argv) {
+ return EstellaRunApp(argc, argv);
+}
diff --git a/native/ios/project.yml b/native/ios/project.yml
new file mode 100644
index 000000000..a560d22ea
--- /dev/null
+++ b/native/ios/project.yml
@@ -0,0 +1,47 @@
+# The iOS app shell: signing + packaging around libestella_ios.a, which
+# `node build-tools/cli.js native --target ios --dawn ... --quickjs ...` produces
+# in build-native-ios/ (host + engine + QuickJS + Dawn, merged).
+#
+# brew install xcodegen && cd native/ios && xcodegen && open EstellaiOS.xcodeproj
+#
+# Then pick your Team under Signing & Capabilities and Run on a device. The game
+# (game.js) and its content ship as bundle resources, the way the APK ships them
+# under assets/ — the host reads both through the same project-relative paths.
+name: EstellaiOS
+
+options:
+ bundleIdPrefix: com.estella
+ deploymentTarget:
+ iOS: "17.0"
+ createIntermediateGroups: true
+
+targets:
+ EstellaiOS:
+ type: application
+ platform: iOS
+ sources:
+ - path: App
+ - path: ../js/game.js
+ buildPhase: resources
+ type: file
+ - path: ../js/logo.png
+ buildPhase: resources
+ type: file
+ settings:
+ base:
+ PRODUCT_BUNDLE_IDENTIFIER: com.estella.EstellaiOS
+ INFOPLIST_FILE: App/Info.plist
+ # -ObjC keeps the view controller / app delegate classes in the static
+ # library alive; the linker would otherwise drop TUs nothing references.
+ OTHER_LDFLAGS: -ObjC -lc++
+ TARGETED_DEVICE_FAMILY: "1,2"
+ ENABLE_BITCODE: NO
+ dependencies:
+ - framework: ../../build-native-ios/libestella_ios.a
+ embed: false
+ - sdk: UIKit.framework
+ - sdk: Metal.framework
+ - sdk: QuartzCore.framework
+ - sdk: IOSurface.framework
+ - sdk: CoreGraphics.framework
+ - sdk: Foundation.framework
diff --git a/native/js/main_ios.mm b/native/js/main_ios.mm
new file mode 100644
index 000000000..716f7dd6b
--- /dev/null
+++ b/native/js/main_ios.mm
@@ -0,0 +1,193 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file main_ios.mm
+ * @brief The iOS glue for the JS host: a CAMetalLayer-backed view, the app
+ * bundle's assets, Metal-backed Dawn, touch, and a CADisplayLink loop.
+ * @details The Android sibling of this file is main_android.cpp; everything they
+ * share — Dawn bring-up, the es_* bindings, the SDK bundle and the frame —
+ * is in host_core.cpp. Obj-C++ so UIKit and the C++ host meet directly,
+ * with no bridging layer.
+ *
+ * The app target is a thin shell: its main() calls EstellaRunApp(), and
+ * the delegate + view controller below (compiled into the static host
+ * library) own the window. Link the app with -ObjC so these classes
+ * survive dead-stripping.
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the Apache License, Version 2.0.
+ */
+#import <UIKit/UIKit.h>
+#import <QuartzCore/CAMetalLayer.h>
+
+#include "host_core.hpp"
+
+using esengine::u32;
+using esengine::u8;
+using esengine::WebGPUDevice;
+
+@class EstellaViewController;
+
+namespace {
+
+struct IOSPlatform final : eshost::Platform {
+ CAMetalLayer* layer = nil;
+
+ // A file shipped inside the .app bundle — the packaged-asset analog of the
+ // APK's assets/. Paths are project-relative ("game.js", "logo.png"), so they
+ // resolve the same way on both platforms.
+ std::vector<u8> readAsset(const char* path) override {
+ std::vector<u8> out;
+ NSString* rel = [NSString stringWithUTF8String:path];
+ NSString* full = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:rel];
+ NSData* data = [NSData dataWithContentsOfFile:full];
+ if (!data) return out;
+ out.resize(data.length);
+ memcpy(out.data(), data.bytes, data.length);
+ return out;
+ }
+
+ std::string cacheDir() override {
+ NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+ if (dirs.count == 0) return {};
+ return std::string([dirs[0] UTF8String]);
+ }
+
+ WGPUBackendType backend() const override { return WGPUBackendType_Metal; }
+
+ WebGPUDevice::NativeSurface surface() override {
+ return {WebGPUDevice::NativeWindowKind::MetalLayer, (__bridge void*)layer};
+ }
+
+ void surfaceSize(u32& width, u32& height) override {
+ width = layer ? (u32)layer.drawableSize.width : 0;
+ height = layer ? (u32)layer.drawableSize.height : 0;
+ }
+
+ void log(bool error, const char* message) override {
+ NSLog(@"[Estella]%s %s", error ? " ERROR:" : "", message);
+ }
+};
+
+IOSPlatform g_platform;
+
+} // namespace
+
+/// A view whose backing layer is the CAMetalLayer Dawn renders into.
+@interface EstellaMetalView : UIView
+@end
+
+@implementation EstellaMetalView
++ (Class)layerClass { return [CAMetalLayer class]; }
+@end
+
+@interface EstellaViewController : UIViewController
+@end
+
+@implementation EstellaViewController {
+ CADisplayLink* _displayLink;
+ BOOL _booted;
+}
+
+- (void)loadView {
+ self.view = [[EstellaMetalView alloc] initWithFrame:UIScreen.mainScreen.bounds];
+ self.view.multipleTouchEnabled = NO; // the host feeds one touch id, as Android does
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(step:)];
+ [_displayLink addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
+
+ NSNotificationCenter* nc = NSNotificationCenter.defaultCenter;
+ [nc addObserver:self selector:@selector(appBackgrounded)
+ name:UIApplicationDidEnterBackgroundNotification object:nil];
+ [nc addObserver:self selector:@selector(appForegrounded)
+ name:UIApplicationWillEnterForegroundNotification object:nil];
+}
+
+// The layer's drawable size is in pixels; the engine's viewport and the touch
+// coordinates it receives are in those same pixels.
+- (void)viewDidLayoutSubviews {
+ [super viewDidLayoutSubviews];
+ CAMetalLayer* layer = (CAMetalLayer*)self.view.layer;
+ UIScreen* screen = self.view.window.screen ?: UIScreen.mainScreen;
+ const CGFloat scale = screen.scale;
+ layer.contentsScale = scale;
+ const CGSize size = CGSizeMake(self.view.bounds.size.width * scale,
+ self.view.bounds.size.height * scale);
+ if (size.width <= 0 || size.height <= 0) return;
+
+ const BOOL resized = !CGSizeEqualToSize(layer.drawableSize, size);
+ layer.drawableSize = size;
+ g_platform.layer = layer;
+
+ // Boot on the first laid-out frame: Dawn needs a layer with a real size to
+ // configure a surface against. Later layouts (rotation) just rebind.
+ if (!_booted) {
+ _booted = eshost::boot(g_platform);
+ } else if (resized) {
+ eshost::bindSurface();
+ }
+}
+
+- (void)step:(CADisplayLink*)link { eshost::frame(); }
+
+- (void)appBackgrounded {
+ _displayLink.paused = YES;
+ eshost::surfaceLost();
+}
+
+- (void)appForegrounded {
+ if (_booted && eshost::bindSurface()) _displayLink.paused = NO;
+}
+
+// UIKit touches are in points, top-left origin; the host contract is surface
+// pixels with the same origin (as on the web), so scale them here.
+- (void)dispatchTouches:(NSSet<UITouch*>*)touches type:(int)type {
+ UITouch* t = touches.anyObject;
+ if (!t) return;
+ const CGPoint p = [t locationInView:self.view];
+ const CGFloat scale = self.view.contentScaleFactor;
+ eshost::touch(type, 0, (float)(p.x * scale), (float)(p.y * scale));
+}
+
+- (void)touchesBegan:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
+ [self dispatchTouches:touches type:0];
+}
+- (void)touchesMoved:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
+ [self dispatchTouches:touches type:1];
+}
+- (void)touchesEnded:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
+ [self dispatchTouches:touches type:2];
+}
+- (void)touchesCancelled:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
+ [self dispatchTouches:touches type:3];
+}
+
+- (BOOL)prefersStatusBarHidden { return YES; }
+
+@end
+
+@interface EstellaAppDelegate : UIResponder <UIApplicationDelegate>
+@property(nonatomic, strong) UIWindow* window;
+@end
+
+@implementation EstellaAppDelegate
+- (BOOL)application:(UIApplication*)application
+ didFinishLaunchingWithOptions:(NSDictionary*)options {
+ self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
+ self.window.rootViewController = [[EstellaViewController alloc] init];
+ [self.window makeKeyAndVisible];
+ return YES;
+}
+@end
+
+extern "C" int EstellaRunApp(int argc, char** argv) {
+ @autoreleasepool {
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([EstellaAppDelegate class]));
+ }
+}