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(editor): package for Android and iOS, not for "Mobile"

yhhbcd0e310e3e2
diff --git a/.gitignore b/.gitignore
index 3f770a009..5173d1dc7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,8 @@ dist-web/
dist-playable/
dist-wechat/
dist-native/
+dist-android/
+dist-ios/
# MCP config (user-specific)
.mcp.json
diff --git a/desktop/electron/exportGame.ts b/desktop/electron/exportGame.ts
index 24a55770b..e6ca1cf26 100644
--- a/desktop/electron/exportGame.ts
+++ b/desktop/electron/exportGame.ts
@@ -37,7 +37,7 @@ import type { OnExportProgress } from './exportProgress';
import { ESENGINE_EXTERNAL } from './esengineResolve';
import { orientationCss, orientationOverlayHtml, orientationLockScript, type ScreenOrientation } from './orientationHtml';
-import type { ExportPlatform } from '../src/project/format';
+import { isNativePlatform, type ExportPlatform } from '../src/project/platforms';
import { collectSubsystems, subsystemGapWarnings, targetGaps, type Subsystem } from '../src/project/targetSupport';
export type { ExportPlatform };
@@ -90,8 +90,8 @@ export async function discoverProjectScenes(root: string, entryScene: string, sc
/**
* Warn about content this target cannot render. The editor authors every
* subsystem the engine has, but a target may compile only some of them (the
- * native app leaves out tilemaps, particles, post-processing and text) — so an
- * export that says nothing writes a package quietly missing half a scene.
+ * native app leaves out tilemaps, particles and post-processing) — so an export
+ * that says nothing writes a package quietly missing half a scene.
*
* Scans the scenes and prefabs that were actually cooked, so the warning names
* the files responsible and a project that never authors a tilemap hears
@@ -466,7 +466,9 @@ export async function exportGame(opts: {
// The native app carries the runtime in its binary (engine core + SDK bundle),
// so its export is CONTENT: cooked assets, manifests, scenes, config — no host
// page, no SDK/wasm tree, and project scripts as a plain script the host evals.
- const nativeContent = platform === 'native';
+ // iOS and Android write the SAME payload — what differs is the toolchain that
+ // wraps it — so this asks what KIND of target it is, not which one.
+ const nativeContent = isNativePlatform(platform);
const warnings: string[] = [];
const errors: string[] = [];
await mkdir(payloadDir, { recursive: true });
diff --git a/desktop/electron/platformCatalog.ts b/desktop/electron/platformCatalog.ts
index 71f1c20ac..5a5f6458e 100644
--- a/desktop/electron/platformCatalog.ts
+++ b/desktop/electron/platformCatalog.ts
@@ -21,11 +21,12 @@
* vendor-neutral (exportMiniGame), so a project platform is a data literal
* merged over MINIGAME_PROFILE_DEFAULTS, not a fork of anything.
*/
-import { existsSync } from 'node:fs';
+import { existsSync, readdirSync } from 'node:fs';
import { readdir, mkdir, writeFile } from 'node:fs/promises';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { defaultMiniGameEntry } from './miniGameExportProfile';
+import { BUILTIN_PLATFORMS, type PlatformPrereq } from '../src/project/platforms';
import type { MiniGameExportProfile, MiniGameConfigContext } from './miniGameExportProfile';
/** Where a project keeps its own platform profiles. */
@@ -45,19 +46,10 @@ export interface PlatformStatus {
/** 'builtin' rows get their label/icon/blurb from the editor's i18n; 'project'
* rows carry their own, since the project named them. */
source: 'builtin' | 'project';
- /** The engine runtime this target needs is present. */
+ /** Everything this target needs to produce an installable package is present. */
ready: boolean;
- /** Present when `ready` is false. STRUCTURED, not prose: the main process has
- * no locale, so it reports the facts and the renderer writes the sentence. */
- prereq?: {
- kind: 'runtime-missing';
- /** Display path that was searched (project-relative where possible). */
- dir: string;
- /** Glue filenames looked for in it. */
- looked: string[];
- /** The build command that produces it — only when the editor ships that target. */
- command?: string;
- };
+ /** Present when `ready` is false. */
+ prereq?: PlatformPrereq;
/** Project platforms only — display data lifted from the profile. */
label?: string;
blurb?: string;
@@ -75,8 +67,31 @@ export interface PlatformStatus {
* Windows `build\wasm\acme` reads worse than `build/wasm/acme`. */
const posix = (p: string): string => p.split(path.sep).join('/');
+/**
+ * The Android SDK, the way `build-tools/utils/android.js` finds it. Duplicated
+ * rather than imported: build-tools is not shipped inside the packaged editor,
+ * and the two answer different questions — that module locates a tool it is
+ * about to RUN, this one reports whether the developer could run it at all.
+ */
+function androidSdkDir(): string | null {
+ const env = process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT;
+ if (env && existsSync(env)) return env;
+ const dflt = path.join(process.env.LOCALAPPDATA || process.env.HOME || '', 'Android', 'Sdk');
+ return existsSync(dflt) ? dflt : null;
+}
+
+/** Whether the SDK has an NDK — the APK's `.so` payload is cross-compiled with it. */
+function hasNdk(sdk: string): boolean {
+ const dir = path.join(sdk, 'ndk');
+ try {
+ return existsSync(dir) && readdirSync(dir).length > 0;
+ } catch {
+ return false;
+ }
+}
+
/** A built-in target's runtime dependency, as a real file probe. */
-function builtinReadiness(id: string, dirs: PlatformRuntimeDirs): { ready: boolean; prereq?: PlatformStatus['prereq'] } {
+function builtinReadiness(id: string, dirs: PlatformRuntimeDirs): { ready: boolean; prereq?: PlatformPrereq } {
const has = (dir: string, file: string) => existsSync(path.join(dir, file));
switch (id) {
@@ -99,18 +114,28 @@ function builtinReadiness(id: string, dirs: PlatformRuntimeDirs): { ready: boole
? { ready: true }
: { ready: false, prereq: { kind: 'runtime-missing', dir: posix(dirs.wechat), looked: ['esengine.wxgame.js'], command: 'node build-tools/cli.js build -t wechat' } };
- case 'native':
- // The native host is a C++ build with its own toolchain — not a file the
- // editor can stage, so this stays advisory rather than a probe.
- return { ready: true };
+ case 'android': {
+ // The app is built from source with the NDK; there is no staged runtime to
+ // probe, so the honest question is whether this machine has the toolchain
+ // that assembles the APK.
+ const sdk = androidSdkDir();
+ if (!sdk) return { ready: false, prereq: { kind: 'toolchain-missing', tool: 'android-sdk' } };
+ return hasNdk(sdk) ? { ready: true } : { ready: false, prereq: { kind: 'toolchain-missing', tool: 'android-ndk' } };
+ }
+
+ case 'ios':
+ // Apple's toolchain is macOS-only, so this row is honest about the machine
+ // it is running on rather than pretending every editor can finish the job.
+ if (process.platform !== 'darwin') return { ready: false, prereq: { kind: 'toolchain-missing', tool: 'macos' } };
+ return existsSync('/Applications/Xcode.app')
+ ? { ready: true }
+ : { ready: false, prereq: { kind: 'toolchain-missing', tool: 'xcode' } };
default:
return { ready: true };
}
}
-const BUILTIN_IDS = ['web', 'desktop', 'wechat', 'playable', 'native'] as const;
-
// =============================================================================
// Project platform profiles
// =============================================================================
@@ -318,7 +343,7 @@ export async function createProjectPlatform(
function idProblem(id: unknown): string | null {
if (typeof id !== 'string' || id.length === 0) return 'profile has no string `id`';
if (!/^[a-z0-9][a-z0-9-]*$/.test(id)) return `id "${id}" must be lowercase letters, digits and dashes`;
- if ((BUILTIN_IDS as readonly string[]).includes(id)) return `id "${id}" is a built-in platform`;
+ if ((BUILTIN_PLATFORMS as readonly string[]).includes(id)) return `id "${id}" is a built-in platform`;
return null;
}
@@ -390,7 +415,7 @@ export async function loadProjectPlatform(root: string, id: string, dirs: Platfo
* own — each with its readiness probed.
*/
export async function listPlatforms(root: string | null, dirs: PlatformRuntimeDirs): Promise<PlatformStatus[]> {
- const out: PlatformStatus[] = BUILTIN_IDS.map((id) => ({
+ const out: PlatformStatus[] = BUILTIN_PLATFORMS.map((id) => ({
id,
source: 'builtin' as const,
...builtinReadiness(id, dirs),
diff --git a/desktop/src/components/BuildDialog.tsx b/desktop/src/components/BuildDialog.tsx
index 548e46517..7b98768d1 100644
--- a/desktop/src/components/BuildDialog.tsx
+++ b/desktop/src/components/BuildDialog.tsx
@@ -26,9 +26,9 @@
import { useState, useEffect, useSyncExternalStore, type ReactNode } from 'react';
import {
Loader2, FolderOpen, CheckCircle2, AlertCircle, Boxes, Info, Copy, ExternalLink, Play,
- Globe, Monitor, MessageSquare, ChevronRight, Smartphone, Package, TriangleAlert, Plus,
+ Globe, Monitor, MessageSquare, ChevronRight, Smartphone, Apple, Package, TriangleAlert, Plus,
} from 'lucide-react';
-import type { ExportPlatform } from '@/project/format';
+import type { ExportPlatform, NativeToolchain, PlatformPrereq } from '@/project/platforms';
import { Modal } from '@/components/Modal';
import { Segmented } from '@/components/Segmented';
import { Button } from '@/components/Button';
@@ -83,6 +83,9 @@ interface PlatformDef {
sourceMaps: boolean;
/** A build prerequisite to surface BEFORE packaging (missing toolchain/runtime). */
prereq?: string;
+ /** What KIND of prerequisite — a missing engine runtime blocks the package, a
+ * missing native toolchain only blocks the final app assembly. */
+ prereqKind?: PlatformPrereq['kind'];
/** http-servable target → offer a loopback-http Preview (opening the build via
* file:// hits the browser's opaque-origin rules; http is its real surface). */
httpPreview?: boolean;
@@ -119,21 +122,39 @@ const BUILTIN_PLATFORMS: PlatformDef[] = [
defaultOut: 'dist-playable', sourceMaps: false, httpPreview: true,
next: () => t('build.next.playable'),
},
+ // The two mobile targets export the same content — a native app carries the
+ // engine and the SDK in its binary — but they are separate rows because
+ // everything AROUND that differs: the toolchain, whether this machine has it,
+ // and the command that turns the content into an installable app.
{
- id: 'native', label: t('build.plat.native'), ready: true, category: 'mobile', icon: <Smartphone size={17} />,
- blurb: t('build.blurb.native'),
- defaultOut: 'dist-native', sourceMaps: false,
- prereq: t('build.prereq.native'),
- next: (o) => t('build.next.native', { out: o }),
+ id: 'android', label: t('build.plat.android'), ready: true, category: 'mobile', icon: <Smartphone size={17} />,
+ blurb: t('build.blurb.android'),
+ defaultOut: 'dist-android', sourceMaps: false,
+ next: (o) => t('build.next.android', { out: o }),
+ },
+ {
+ id: 'ios', label: t('build.plat.ios'), ready: true, category: 'mobile', icon: <Apple size={17} />,
+ blurb: t('build.blurb.ios'),
+ defaultOut: 'dist-ios', sourceMaps: false,
+ next: (o) => t('build.next.ios', { out: o }),
},
];
const mb = (bytes: number): string => `${(bytes / 1024 / 1024).toFixed(1)} MB`;
-/** The main process reports WHERE it looked and FOR WHAT; the sentence is written
- * here, where the locale is. */
-function prereqText(r: { prereq?: { dir: string; looked: string[]; command?: string } }): string | undefined {
+/** Localized names for the native toolchain pieces the main process probes. */
+const TOOLCHAIN_TEXT: Record<NativeToolchain, string> = {
+ 'android-sdk': t('build.needAndroidSdk'),
+ 'android-ndk': t('build.needAndroidNdk'),
+ xcode: t('build.needXcode'),
+ macos: t('build.needMacos'),
+};
+
+/** The main process reports WHAT is missing; the sentence is written here, where
+ * the locale is. */
+function prereqText(r: { prereq?: PlatformPrereq }): string | undefined {
if (!r.prereq) return undefined;
+ if (r.prereq.kind === 'toolchain-missing') return TOOLCHAIN_TEXT[r.prereq.tool];
// A built-in target comes with the command that fixes it, and WHERE the editor
// keeps its runtime is not the developer's business — the command is. A project
// platform has no command (only the project knows how it builds one), so there
@@ -204,9 +225,11 @@ export function BuildDialog() {
const merged: PlatformDef[] = BUILTIN_PLATFORMS.map((p) => {
const r = byId.get(p.id);
if (!r) return p;
- // A probed prerequisite replaces the static one; `prereq` survives only
- // where there is nothing to probe (native's toolchain).
- return { ...p, ready: r.ready, prereq: prereqText(r) ?? p.prereq, fixCommand: r.prereq?.command };
+ // A probed prerequisite replaces the static one.
+ return {
+ ...p, ready: r.ready, prereq: prereqText(r), prereqKind: r.prereq?.kind,
+ fixCommand: r.prereq?.kind === 'runtime-missing' ? r.prereq.command : undefined,
+ };
});
for (const r of rows) {
if (r.source !== 'project') continue;
@@ -222,7 +245,10 @@ export function BuildDialog() {
defaultOut: r.defaultOut ?? `dist-${r.id}`,
sourceMaps: false,
prereq: prereqText(r),
- fixCommand: r.prereq?.command,
+ prereqKind: r.prereq?.kind,
+ // A project platform is always a runtime probe (it rides the mini-game
+ // pipeline), but read the kind rather than assume it.
+ fixCommand: r.prereq?.kind === 'runtime-missing' ? r.prereq.command : undefined,
next: (o) => t('build.next.custom', { out: o }),
});
}
@@ -284,7 +310,8 @@ export function BuildDialog() {
id: row.id, label: row.label ?? row.id, ready: row.ready, category: 'custom', custom: true,
loadError: row.error, icon: <Package size={17} />, blurb: row.blurb ?? t('build.customHint'),
defaultOut: row.defaultOut ?? `dist-${row.id}`, sourceMaps: false,
- prereq: prereqText(row), fixCommand: row.prereq?.command,
+ prereq: prereqText(row), prereqKind: row.prereq?.kind,
+ fixCommand: row.prereq?.kind === 'runtime-missing' ? row.prereq.command : undefined,
next: (o) => t('build.next.custom', { out: o }),
},
]);
@@ -504,7 +531,12 @@ export function BuildDialog() {
<TriangleAlert size={13} />
<div className="build__prereq-body">
<span className="selectable">{def.prereq ?? t('build.notReady')}</span>
- <span className="build__prereq-hint">{t('build.notReadyHint')}</span>
+ {/* A missing engine runtime means no package at all; a missing
+ native toolchain still exports the app's content — only the
+ assembly step (which may run on another machine) needs it. */}
+ <span className="build__prereq-hint">
+ {def.prereqKind === 'toolchain-missing' ? t('build.toolchainHint') : t('build.notReadyHint')}
+ </span>
{def.fixCommand && (
<div className="build__fix">
<code className="selectable">{def.fixCommand}</code>
@@ -517,13 +549,6 @@ export function BuildDialog() {
</div>
)}
- {/* Nothing to probe (native's toolchain) — advisory, and only when ready. */}
- {def.ready && def.prereq && (
- <div className="build__prereq">
- <Info size={13} /> <span className="selectable">{def.prereq}</span>
- </div>
- )}
-
<Group title={t('build.secBuild')}>
<div className="build__row">
<span className="build__label">{t('build.configuration')}</span>
diff --git a/desktop/src/i18n/messages/project.ts b/desktop/src/i18n/messages/project.ts
index b05cd286c..5f792d862 100644
--- a/desktop/src/i18n/messages/project.ts
+++ b/desktop/src/i18n/messages/project.ts
@@ -13,7 +13,8 @@ export const projectMessages = defineMessages({
'build.plat.desktop': { en: 'Desktop', zh: '桌面' },
'build.plat.wechat': { en: 'WeChat', zh: '微信小游戏' },
'build.plat.playable': { en: 'Playable', zh: 'Playable' },
- 'build.plat.native': { en: 'Mobile', zh: '移动原生' },
+ 'build.plat.android': { en: 'Android', zh: 'Android' },
+ 'build.plat.ios': { en: 'iOS', zh: 'iOS' },
// — Platform categories (the nav's group headings) —
'build.cat.general': { en: 'General', zh: '通用' },
'build.cat.minigame': { en: 'Mini-Games', zh: '小游戏' },
@@ -29,6 +30,29 @@ export const projectMessages = defineMessages({
en: 'This target needs an engine runtime that is not built yet. Packaging will fail until it is.',
zh: '该目标需要的引擎运行时尚未构建,在此之前打包会失败。',
},
+ // — Native toolchain readiness. A native target's export is app CONTENT, which
+ // always succeeds; only assembling the installable app needs these, and that
+ // step can run on another machine. —
+ 'build.needAndroidSdk': {
+ en: 'Android SDK not found — set ANDROID_HOME, or install it with Android Studio.',
+ zh: '未找到 Android SDK——请设置 ANDROID_HOME,或通过 Android Studio 安装。',
+ },
+ 'build.needAndroidNdk': {
+ en: 'No NDK in the Android SDK — install one from the SDK Manager (the app is cross-compiled with it).',
+ zh: 'Android SDK 中没有 NDK——请在 SDK Manager 中安装(应用由它交叉编译)。',
+ },
+ 'build.needXcode': {
+ en: 'Xcode not found — the iOS app is built and signed by it.',
+ zh: '未找到 Xcode——iOS 应用由它构建并签名。',
+ },
+ 'build.needMacos': {
+ en: 'Building the iOS app needs a Mac with Xcode — Apple ships no toolchain for this OS.',
+ zh: '构建 iOS 应用需要装有 Xcode 的 Mac——Apple 未在本系统提供工具链。',
+ },
+ 'build.toolchainHint': {
+ en: 'The export still writes the app\'s content here; assembling the installable app needs this toolchain, and that step can run on another machine.',
+ zh: '导出仍会在此写出应用内容;将其装配成可安装的应用才需要该工具链,且这一步可以在另一台机器上完成。',
+ },
'build.copyCommand': { en: 'Copy command', zh: '复制命令' },
'build.copied': { en: 'Copied', zh: '已复制' },
'build.platformBroken': { en: 'This platform profile failed to load', zh: '该平台配置加载失败' },
@@ -75,13 +99,13 @@ export const projectMessages = defineMessages({
en: 'Single-file HTML playable ad — everything inlined, no requests.',
zh: '单文件 HTML 试玩广告——所有内容内联,无网络请求。',
},
- 'build.blurb.native': {
- en: 'Content for the native iOS / Android app — a real app, not a WebView.',
- zh: '原生 iOS / Android 应用的内容——真正的原生应用,而非 WebView。',
+ 'build.blurb.android': {
+ en: 'Content for the native Android app (Vulkan) — a real APK, not a WebView.',
+ zh: '原生 Android 应用(Vulkan)的内容——真正的 APK,而非 WebView。',
},
- 'build.prereq.native': {
- en: 'Needs the native host — see native/README.md (embedded Dawn + QuickJS).',
- zh: '需要原生宿主——见 native/README.md(内嵌 Dawn + QuickJS)。',
+ 'build.blurb.ios': {
+ en: 'Content for the native iOS app (Metal) — packaged and signed by Xcode.',
+ zh: '原生 iOS 应用(Metal)的内容——由 Xcode 打包并签名。',
},
'build.next.web': {
en: "Preview over http below, or upload {out}/ to any static host. (A web build needs an http origin — opening index.html directly won't stream the wasm.)",
@@ -100,9 +124,13 @@ export const projectMessages = defineMessages({
zh: '在下方通过 http 预览(其真实运行环境是广告网络的 iframe)。注意:完整引擎通常会超出广告网络的体积限制。',
},
- 'build.next.native': {
- en: 'Package it into the app: node build-tools/cli.js native --package --content {out} (Android), or point the Xcode project at {out} (iOS).',
- zh: '将其打进应用:node build-tools/cli.js native --package --content {out}(Android),或让 Xcode 工程指向 {out}(iOS)。',
+ 'build.next.android': {
+ en: 'Build the signed APK around it: node build-tools/cli.js native --package --content {out} (see native/README.md for the one-time Dawn + QuickJS setup).',
+ zh: '据此构建签名 APK:node build-tools/cli.js native --package --content {out}(一次性的 Dawn + QuickJS 准备见 native/README.md)。',
+ },
+ 'build.next.ios': {
+ en: 'On a Mac: node build-tools/cli.js native --target ios --content {out}, then cd native/ios && xcodegen — pick your Team in Xcode and Run.',
+ zh: '在 Mac 上运行:node build-tools/cli.js native --target ios --content {out},然后 cd native/ios && xcodegen —— 在 Xcode 中选择你的 Team 并运行。',
},
// — Options —
diff --git a/desktop/src/panels/Details.tsx b/desktop/src/panels/Details.tsx
index 57de8f475..42f1875e4 100644
--- a/desktop/src/panels/Details.tsx
+++ b/desktop/src/panels/Details.tsx
@@ -28,6 +28,8 @@ import {
Monitor,
MessageSquare,
Play,
+ Smartphone,
+ Apple,
Image as ImageIcon,
MoreHorizontal,
Move3d,
@@ -53,6 +55,7 @@ import { COMP_COLLIDER_SHAPE, type ColliderShapeKind } from '@/engine/colliderCo
import { AudioWavePreview } from '@/components/AudioWavePreview';
import { Toasts } from '@/store/Toasts';
import { baseName, assetTypeOf, IMAGE_RE } from '@/project/assetMeta';
+import { BUILTIN_PLATFORMS, type BuiltinPlatform } from '@/project/platforms';
import { revealAsset } from '@/project/assetReveal';
import { useSelection } from '@/store/selectionStore';
import { usePrefabConflicts } from '@/store/prefabConflicts';
@@ -3148,16 +3151,32 @@ function MetaRow({ k, v, mono }: { k: string; v: string; mono?: boolean }) {
// GPU" pipeline: size cap + whether/how to compress (e.g. WeChat ships smaller /
// ETC1S). Edits write to `overrides.<platform>.*` through the same importer `write`
// seam, so save + dirty tracking are unchanged.
+//
+// The tabs are the BUILT-IN platform list itself, not a copy of it: this used to be
+// a hand-written four and had already drifted — it never offered the mobile targets,
+// which is where a texture budget bites hardest.
+const PLATFORM_TAB_ICON: Record<BuiltinPlatform, ReactNode> = {
+ web: <Globe size={13} />,
+ desktop: <Monitor size={13} />,
+ wechat: <MessageSquare size={13} />,
+ playable: <Play size={13} />,
+ android: <Smartphone size={13} />,
+ ios: <Apple size={13} />,
+};
+
+/** Labels come from the build dialog's catalog — one name per platform, editor-wide. */
+const PLATFORM_TAB_LABEL: Record<BuiltinPlatform, string> = {
+ web: t('build.plat.web'), desktop: t('build.plat.desktop'),
+ wechat: t('build.plat.wechat'), playable: t('build.plat.playable'),
+ android: t('build.plat.android'), ios: t('build.plat.ios'),
+};
+
function TexturePlatformOverrides({ importer, write }: { importer: Record<string, unknown>; write: FieldWrite }) {
- const [tab, setTab] = useState('wechat');
+ const [tab, setTab] = useState<BuiltinPlatform>('wechat');
const overrides = (importer.overrides as Record<string, Record<string, unknown>> | undefined) ?? {};
const ov = overrides[tab] ?? {};
const enabled = !!ov.enabled;
const def = readTextureCookSettings(importer); // true default (what an unset field inherits)
- const platLabel: Record<string, string> = {
- web: t('build.plat.web'), desktop: t('build.plat.desktop'),
- wechat: t('build.plat.wechat'), playable: t('build.plat.playable'),
- };
const fields: InspectorField[] = [
{
key: `overrides.${tab}.maxSize`, label: 'Max Size', type: 'enum', category: '',
@@ -3182,16 +3201,13 @@ function TexturePlatformOverrides({ importer, write }: { importer: Record<string
ariaLabel={t('det.platformOverrides')}
value={tab}
onChange={setTab}
- options={[
- { value: 'web', icon: <Globe size={13} />, title: platLabel.web },
- { value: 'desktop', icon: <Monitor size={13} />, title: platLabel.desktop },
- { value: 'wechat', icon: <MessageSquare size={13} />, title: platLabel.wechat },
- { value: 'playable', icon: <Play size={13} />, title: platLabel.playable },
- ]}
+ options={BUILTIN_PLATFORMS.map((id) => ({
+ value: id, icon: PLATFORM_TAB_ICON[id], title: PLATFORM_TAB_LABEL[id],
+ }))}
/>
<label className="tex-plat__en">
<input type="checkbox" checked={enabled} onChange={(e) => write(`overrides.${tab}.enabled`, 'bool', e.target.checked)} />
- {t('det.overrideFor', { platform: platLabel[tab] })}
+ {t('det.overrideFor', { platform: PLATFORM_TAB_LABEL[tab] })}
</label>
{enabled ? (
<div className="tex-plat__fields">
diff --git a/desktop/src/project/format.ts b/desktop/src/project/format.ts
index 37acdd3e1..512ff9ecc 100644
--- a/desktop/src/project/format.ts
+++ b/desktop/src/project/format.ts
@@ -19,6 +19,7 @@
*/
import { parseAudioProjectConfig, THEME_COLOR_ROLES, type AudioProjectConfig } from 'esengine';
+import { normalizePlatform, type ExportPlatform } from './platforms';
export const PROJECT_FORMAT_VERSION = '1';
export const PROJECT_MANIFEST_FILE = 'project.esproject';
@@ -123,16 +124,9 @@ export type CameraScaleMode = 'none' | 'fixed-width' | 'fixed-height' | 'expand'
export interface WeChatPackaging { appid?: string; }
export interface DesktopPackaging { appId?: string; productName?: string; }
-/** Every export target. The single source: the electron export pipeline, the IPC
- * surface and the build dialog all name their platforms from here. */
-/**
- * A packaging target. The editor's built-ins are named for completion, but the
- * type is OPEN: a project can add its own platform by dropping a profile in
- * `.esengine/platforms/<id>.mjs`, and that id flows through packaging settings,
- * the export result and the cook's per-platform Import Settings key exactly like
- * a built-in one.
- */
-export type ExportPlatform = 'web' | 'desktop' | 'wechat' | 'playable' | 'native' | (string & {});
+/** A packaging target — defined in `./platforms`, where the built-in vocabulary
+ * lives, and re-exported here because the manifest is what persists it. */
+export type { ExportPlatform } from './platforms';
/** Persisted Package Project settings (UE's ProjectPackagingSettings analog) —
* committed with the project so the build dialog restores the last target/config
@@ -371,9 +365,11 @@ export function parseManifest(raw: unknown): ProjectManifest {
const p = o.packaging as Record<string, unknown>;
const pkg: ProjectPackaging = {};
// Any non-empty id: built-ins plus whatever platforms the project defines.
- // (The old enumeration silently dropped 'native', so packaging for it never
- // persisted and the dialog reopened on web.)
- if (typeof p.platform === 'string' && p.platform !== '') pkg.platform = p.platform;
+ // (The old enumeration silently dropped unknown ids, so packaging for them
+ // never persisted and the dialog reopened on web.) `normalizePlatform` is the
+ // one migration point: an id an older editor wrote — 'native', when the two
+ // mobile targets were one row — becomes the id this editor spells.
+ if (typeof p.platform === 'string' && p.platform !== '') pkg.platform = normalizePlatform(p.platform);
if (p.config === 'development' || p.config === 'shipping') pkg.config = p.config;
if (typeof p.sourceMaps === 'boolean') pkg.sourceMaps = p.sourceMaps;
if (typeof p.openFolder === 'boolean') pkg.openFolder = p.openFolder;
@@ -391,9 +387,10 @@ export function parseManifest(raw: unknown): ProjectManifest {
const od = p.outDir as Record<string, unknown>;
const out: NonNullable<ProjectPackaging['outDir']> = {};
// Per-platform output dirs, keyed by whatever platform ids this project has
- // used — built-in or its own.
+ // used — built-in or its own. A renamed built-in keeps its directory: the
+ // key migrates, the value the developer chose does not.
for (const [k, v] of Object.entries(od)) {
- if (typeof v === 'string' && v !== '') out[k] = v;
+ if (typeof v === 'string' && v !== '') out[normalizePlatform(k)] = v;
}
if (Object.keys(out).length > 0) pkg.outDir = out;
}
diff --git a/desktop/src/project/platforms.ts b/desktop/src/project/platforms.ts
new file mode 100644
index 000000000..b35cc5a1d
--- /dev/null
+++ b/desktop/src/project/platforms.ts
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file The built-in packaging targets, named once.
+ *
+ * Three surfaces used to carry their own copy of this list — the build
+ * dialog's descriptors, the main process's readiness catalog, and the
+ * Inspector's per-platform Import Settings tabs — and the third had drifted
+ * (it never offered the mobile targets at all, so a texture could not be
+ * tuned for the platform where memory is tightest). The ids live here; each
+ * surface adds only what is genuinely its own (icons and copy in the
+ * renderer, filesystem probes in the main process).
+ *
+ * Deliberately free of node and React imports: the electron export, the
+ * renderer and the tests all read it.
+ */
+
+/**
+ * The targets the editor ships. `android` and `ios` are two platforms, not one
+ * "native": they package through different toolchains (aapt2 + apksigner vs
+ * Xcode), so a single row could not tell you what to run, whether this machine
+ * can run it, or where the package comes out.
+ */
+export type BuiltinPlatform = 'web' | 'desktop' | 'wechat' | 'playable' | 'android' | 'ios';
+
+/** Built-ins, in the order they are offered. */
+export const BUILTIN_PLATFORMS: readonly BuiltinPlatform[] = [
+ 'web', 'desktop', 'wechat', 'playable', 'android', 'ios',
+];
+
+/**
+ * A packaging target. The editor's built-ins are named for completion, but the
+ * type is OPEN: a project can add its own platform by dropping a profile in
+ * `.esengine/platforms/<id>.mjs`, and that id flows through packaging settings,
+ * the export result and the cook's per-platform Import Settings key exactly like
+ * a built-in one.
+ */
+export type ExportPlatform = BuiltinPlatform | (string & {});
+
+/**
+ * The targets that ship as a real native app (embedded Dawn + QuickJS, see
+ * `native/README.md`). They share ONE runtime and ONE export payload — content
+ * only, since the engine, the SDK and the game runtime live in the app binary —
+ * and differ in how that content is assembled into an installable app.
+ */
+export const NATIVE_PLATFORMS = ['android', 'ios'] as const;
+export type NativePlatform = (typeof NATIVE_PLATFORMS)[number];
+
+/** Whether this target's export is app CONTENT rather than a runnable payload. */
+export function isNativePlatform(platform: ExportPlatform): platform is NativePlatform {
+ return platform === 'android' || platform === 'ios';
+}
+
+/**
+ * Platform ids written by an older editor, and what they are today. `native` was
+ * one row covering both mobile targets; a project that selected it re-opens on
+ * Android — the target whose toolchain runs on every desktop OS.
+ */
+export const LEGACY_PLATFORM_IDS: Readonly<Record<string, BuiltinPlatform>> = {
+ native: 'android',
+};
+
+/** A persisted platform id, as this editor spells it. Unknown ids pass through —
+ * they belong to the project's own platforms. */
+export function normalizePlatform(id: string): string {
+ return LEGACY_PLATFORM_IDS[id] ?? id;
+}
+
+/** The default output directory for a built-in target. */
+export function defaultOutDir(platform: ExportPlatform): string {
+ return `dist-${platform}`;
+}
+
+/**
+ * Why a target is not ready to produce a package. STRUCTURED, not prose: the main
+ * process probes the filesystem but has no locale, so it reports the facts and
+ * the build dialog writes the sentence.
+ *
+ * The two kinds are not the same severity, and the dialog says so. A missing
+ * ENGINE RUNTIME means the package cannot be produced at all. A missing native
+ * TOOLCHAIN does not: the export writes the app's content either way — only the
+ * final assembly into an installable app needs the toolchain, and that step can
+ * run on another machine (an iOS build always does, when the editor is on
+ * Windows).
+ */
+export type PlatformPrereq =
+ | {
+ kind: 'runtime-missing';
+ /** Display path that was searched (project-relative where possible). */
+ dir: string;
+ /** Glue filenames looked for in it. */
+ looked: string[];
+ /** The build command that produces it — only when the editor ships that target. */
+ command?: string;
+ }
+ | {
+ kind: 'toolchain-missing';
+ /** Which piece is absent — the dialog maps it to a localized sentence. */
+ tool: NativeToolchain;
+ };
+
+/** The native toolchain pieces the editor probes for. */
+export type NativeToolchain = 'android-sdk' | 'android-ndk' | 'xcode' | 'macos';
diff --git a/desktop/src/project/targetSupport.ts b/desktop/src/project/targetSupport.ts
index 1b6f9cc23..509e4c171 100644
--- a/desktop/src/project/targetSupport.ts
+++ b/desktop/src/project/targetSupport.ts
@@ -4,11 +4,11 @@
* @file What a build target can render — and what it cannot.
*
* The editor authors every subsystem the engine has; a target does not
- * necessarily compile all of them. The native app builds a subset:
- * `native/CMakeLists.txt` sets ES_ENABLE_WEBGPU and nothing else, so
- * `cmake/ESEngineSources.cmake` leaves out the tilemap, particle, post-process
- * and text sources — and the optional emscripten side modules (Box2D, Spine,
- * video) have no native counterpart yet.
+ * necessarily compile all of them. The native app builds a subset: the flags
+ * `native/CMakeLists.txt` sets decide what `cmake/ESEngineSources.cmake` compiles
+ * in, and the optional emscripten side modules (Box2D, Spine, video) have no
+ * native counterpart yet. iOS and Android build from that same CMakeLists, so
+ * their gaps are one list.
*
* Without this, an export writes a package that is quietly missing half a
* scene. This is the one declaration of that gap, so the export can name it
@@ -19,7 +19,7 @@
* Deliberately free of node imports — the electron export and the renderer's
* build dialog both read it.
*/
-import type { ExportPlatform } from './format';
+import { NATIVE_PLATFORMS, type ExportPlatform } from './platforms';
/** An engine subsystem a build target may lack. */
export type Subsystem = 'text' | 'tilemap' | 'particles' | 'postprocess' | 'physics' | 'spine' | 'video';
@@ -73,21 +73,25 @@ export interface SubsystemGap {
why: string;
}
+/** What the native app cannot render. ONE list: iOS and Android compile the same
+ * `native/CMakeLists.txt`, so a flag flipped there closes the gap on both. */
+const NATIVE_GAPS: readonly SubsystemGap[] = [
+ { subsystem: 'tilemap', why: 'the native build leaves out the tilemap sources (ES_ENABLE_TILEMAP)' },
+ { subsystem: 'particles', why: 'the native build leaves out the particle sources (ES_ENABLE_PARTICLES)' },
+ { subsystem: 'postprocess', why: 'the native build leaves out the post-process pipeline (ES_ENABLE_POSTPROCESS)' },
+ { subsystem: 'physics', why: 'Box2D ships as an emscripten side module; the native host has no counterpart yet' },
+ { subsystem: 'spine', why: 'the Spine runtime ships as an emscripten side module; the native host has no counterpart yet' },
+ { subsystem: 'video', why: 'the video decoder ships as an emscripten side module; the native host has no counterpart yet' },
+];
+
/**
* Per-target gaps. A platform absent from this table has none *known*: only the
- * native target's feature set has been audited against the engine's, since it is
- * the one that compiles a subset.
+ * native targets' feature set has been audited against the engine's, since they
+ * are the ones that compile a subset.
*/
-const GAPS: Partial<Record<ExportPlatform, readonly SubsystemGap[]>> = {
- native: [
- { subsystem: 'tilemap', why: 'the native build leaves out the tilemap sources (ES_ENABLE_TILEMAP)' },
- { subsystem: 'particles', why: 'the native build leaves out the particle sources (ES_ENABLE_PARTICLES)' },
- { subsystem: 'postprocess', why: 'the native build leaves out the post-process pipeline (ES_ENABLE_POSTPROCESS)' },
- { subsystem: 'physics', why: 'Box2D ships as an emscripten side module; the native host has no counterpart yet' },
- { subsystem: 'spine', why: 'the Spine runtime ships as an emscripten side module; the native host has no counterpart yet' },
- { subsystem: 'video', why: 'the video decoder ships as an emscripten side module; the native host has no counterpart yet' },
- ],
-};
+const GAPS: Partial<Record<ExportPlatform, readonly SubsystemGap[]>> = Object.fromEntries(
+ NATIVE_PLATFORMS.map((platform) => [platform, NATIVE_GAPS]),
+);
/** What `platform` cannot render, whether or not this project uses it. */
export function targetGaps(platform: ExportPlatform): readonly SubsystemGap[] {
diff --git a/desktop/tests/export-native.test.ts b/desktop/tests/export-native.test.ts
index b2f770059..3eb7f9d0b 100644
--- a/desktop/tests/export-native.test.ts
+++ b/desktop/tests/export-native.test.ts
@@ -42,17 +42,17 @@ beforeAll(async () => {
mkdirSync(path.join(root, '_wasm'), { recursive: true });
writeFileSync(path.join(root, '_wasm', 'esengine.js'), 'export default () => {};');
- out = path.join(root, 'dist-native');
+ out = path.join(root, 'dist-android');
}, 60_000);
afterAll(() => rmSync(root, { recursive: true, force: true }));
-describe('exportGame (native)', () => {
+describe('exportGame (native app content)', () => {
it('ships content only — cooked assets, manifests, scene, config', async () => {
const res = await exportGame({
root, entryScene: 'scenes/main.esscene', gameHostEntry: GAME_HOST, scriptsEntry: 'src/main.ts',
sdkDistDir: path.join(root, '_sdk'), wasmDir: path.join(root, '_wasm'), outDir: out,
- platform: 'native', title: 'NativeGame',
+ platform: 'android', title: 'NativeGame',
});
expect(res.errors).toEqual([]);
expect(res.ok).toBe(true);
diff --git a/desktop/tests/platform-catalog.test.ts b/desktop/tests/platform-catalog.test.ts
index 381f03bb4..721f03ba0 100644
--- a/desktop/tests/platform-catalog.test.ts
+++ b/desktop/tests/platform-catalog.test.ts
@@ -14,6 +14,7 @@ import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync } from 'nod
import { tmpdir } from 'node:os';
import path from 'node:path';
import { listPlatforms, loadProjectPlatform, createProjectPlatform, PROJECT_PLATFORM_DIR } from '../electron/platformCatalog';
+import { BUILTIN_PLATFORMS } from '../src/project/platforms';
let root: string;
let webDir: string;
@@ -119,7 +120,7 @@ describe('listPlatforms — platforms the project defines', () => {
expect(bad!.ready).toBe(false);
expect(bad!.error).toBeTruthy();
// Every built-in still came through.
- expect(rows.filter((r) => r.source === 'builtin')).toHaveLength(5);
+ expect(rows.filter((r) => r.source === 'builtin').map((r) => r.id)).toEqual([...BUILTIN_PLATFORMS]);
});
it('rejects a profile that shadows a built-in, or has no id/label/emitter', async () => {
diff --git a/desktop/tests/project-packaging.test.ts b/desktop/tests/project-packaging.test.ts
index a8fc6d943..82d9f713e 100644
--- a/desktop/tests/project-packaging.test.ts
+++ b/desktop/tests/project-packaging.test.ts
@@ -31,15 +31,16 @@ describe('parseManifest — packaging', () => {
// a bad one. It keeps any non-empty string and drops everything else.
it('keeps an unknown platform id (a project may define one) but drops non-strings', () => {
expect(parseManifest({ name: 'X', packaging: { platform: 'acme-play' } }).packaging?.platform).toBe('acme-play');
- // 'native' used to be dropped by an enumeration that forgot it.
- expect(parseManifest({ name: 'X', packaging: { platform: 'native' } }).packaging?.platform).toBe('native');
+ // An id an older editor wrote migrates to what this one spells: 'native' was
+ // one row for both mobile targets, and reopens on the one that builds anywhere.
+ expect(parseManifest({ name: 'X', packaging: { platform: 'native' } }).packaging?.platform).toBe('android');
expect(parseManifest({ name: 'X', packaging: { platform: '' } }).packaging).toBeUndefined();
expect(parseManifest({ name: 'X', packaging: { platform: 7 } }).packaging).toBeUndefined();
});
it('keeps per-platform output dirs for project-defined platforms', () => {
- const m = parseManifest({ name: 'X', packaging: { outDir: { 'acme-play': 'dist-acme', native: 'dist-native' } } });
- expect(m.packaging?.outDir).toEqual({ 'acme-play': 'dist-acme', native: 'dist-native' });
+ const m = parseManifest({ name: 'X', packaging: { outDir: { 'acme-play': 'dist-acme', android: 'dist-android' } } });
+ expect(m.packaging?.outDir).toEqual({ 'acme-play': 'dist-acme', android: 'dist-android' });
});
it('parses excludeScenes, dropping non-string / empty entries', () => {
diff --git a/desktop/tests/target-support.test.ts b/desktop/tests/target-support.test.ts
index 57eee5759..be275fe6e 100644
--- a/desktop/tests/target-support.test.ts
+++ b/desktop/tests/target-support.test.ts
@@ -56,7 +56,7 @@ describe('subsystemGapWarnings', () => {
const usage = new Map<Subsystem, string[]>([['tilemap', ['scenes/b.esscene', 'scenes/a.esscene']]]);
it('names the subsystem, the reason and the files', () => {
- const [warning, ...rest] = subsystemGapWarnings('native', usage);
+ const [warning, ...rest] = subsystemGapWarnings('android', usage);
expect(rest).toEqual([]);
expect(warning).toContain('Tilemaps will not render');
expect(warning).toContain('scenes/a.esscene, scenes/b.esscene');
@@ -67,14 +67,19 @@ describe('subsystemGapWarnings', () => {
});
it('is silent about a gap the content does not use', () => {
- expect(subsystemGapWarnings('native', new Map())).toEqual([]);
+ expect(subsystemGapWarnings('ios', new Map())).toEqual([]);
+ });
+
+ it('reports the same gaps for both native targets — they compile one CMakeLists', () => {
+ expect(targetGaps('ios')).toEqual(targetGaps('android'));
+ expect(targetGaps('ios').length).toBeGreaterThan(0);
});
});
describe('the native gaps match the native build', () => {
const cmake = readFileSync(path.join(REPO, 'native', 'CMakeLists.txt'), 'utf8');
const enabled = new Set([...cmake.matchAll(/set\(\s*(ES_ENABLE_\w+)\s+ON\s*\)/g)].map((m) => m[1]));
- const gaps = new Set(targetGaps('native').map((g) => g.subsystem));
+ const gaps = new Set(targetGaps('android').map((g) => g.subsystem));
it.each(Object.entries(SUBSYSTEM_CMAKE_FLAG) as [Subsystem, string][])(
'%s: a source set the native build omits is declared unsupported', (subsystem, flag) => {
@@ -119,17 +124,17 @@ describe('exportGame warns about content the target cannot render', () => {
afterAll(() => rmSync(root, { recursive: true, force: true }));
- const run = (platform: 'native' | 'web', outDir: string) => exportGame({
+ const run = (platform: 'android' | 'web', outDir: string) => exportGame({
root, entryScene: 'scenes/main.esscene', gameHostEntry: GAME_HOST,
sdkDistDir: path.join(root, '_sdk'), wasmDir: path.join(root, '_wasm'),
outDir, platform, title: 'Game',
});
it('names every unsupported subsystem the scene uses — and ships anyway', async () => {
- const res = await run('native', path.join(root, 'dist-native'));
+ const res = await run('android', path.join(root, 'dist-android'));
expect(res.errors).toEqual([]);
expect(res.ok).toBe(true);
- const gaps = res.warnings.filter((w) => w.startsWith('native:'));
+ const gaps = res.warnings.filter((w) => w.startsWith('android:'));
expect(gaps).toHaveLength(2);
expect(gaps.join('\n')).toContain('Particles will not render');
expect(gaps.join('\n')).toContain('Tilemaps will not render');