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): a template says which Spine runtime it links, and an export names the skeletons it cannot play

yhh203ba161cabc
diff --git a/build-tools/cli.js b/build-tools/cli.js
index e94fd65ac..e75136412 100644
--- a/build-tools/cli.js
+++ b/build-tools/cli.js
@@ -168,6 +168,7 @@ program
.option('--quickjs <dir>', 'QuickJS-ng source dir (default: the pinned checkout; or ESTELLA_QUICKJS_DIR)')
.option('--js-engine <engine>', 'JS engine the host embeds: v8 (default where pinned: Windows, Android) or quickjs (iOS always; or ESTELLA_JS_ENGINE)')
.option('--v8 <dir>', 'A prebuilt V8 (include/ + libraries) instead of the pinned one (or ESTELLA_V8_DIR)')
+ .option('--spine <version>', 'Spine runtime the host links (4.3, 4.2, 4.1, 3.8 or 2.1; default 4.2). A host links ONE: a project whose skeletons are another version needs a template built with this')
.option('--sdl <dir>', 'Desktop: SDL3 source dir or install prefix (default: the pinned checkout; or ESTELLA_SDL_DIR)')
.option('--steam-sdk <dir>', 'Desktop: a Steamworks SDK on this machine; its redistributable ships in the package (and in a template built with --template-out)')
.option('--macos-archs <archs>', 'Desktop: CMAKE_OSX_ARCHITECTURES (arm64, or "arm64;x86_64" for a universal build)')
@@ -209,6 +210,7 @@ program
quickjs: options.quickjs,
jsEngine: options.jsEngine,
v8: options.v8,
+ spine: options.spine,
sdl: options.sdl,
steamSdk: options.steamSdk,
macosArchs: options.macosArchs,
diff --git a/build-tools/tasks/native.js b/build-tools/tasks/native.js
index 9bb1b26fd..f80c5f86b 100644
--- a/build-tools/tasks/native.js
+++ b/build-tools/tasks/native.js
@@ -9,7 +9,7 @@
// --dawn / --dawn-build or ESTELLA_DAWN_DIR / ESTELLA_DAWN_BUILD.
import path from 'path';
-import { existsSync, readFileSync, writeFileSync, statSync } from 'fs';
+import { existsSync, readFileSync, readdirSync, writeFileSync, statSync } from 'fs';
import { mkdir, rm, cp, readdir } from 'fs/promises';
import config from '../build.config.js';
import * as logger from '../utils/logger.js';
@@ -434,6 +434,7 @@ async function buildDesktopHost(options) {
`-DESTELLA_NATIVE_GEN_DIR=${fwd(genDir)}`,
`-DESTELLA_JS_ENGINE=${js.engine}`,
`-DESTELLA_V8_DIR=${js.v8 ? fwd(js.v8) : ''}`,
+ ...spineFlags(rootDir, options),
], { cwd: rootDir });
logger.step('Building desktop host...');
@@ -453,6 +454,29 @@ async function buildDesktopHost(options) {
return exe;
}
+/**
+ * `--spine <version>` as a CMake flag. A host links ONE Spine runtime — every
+ * vendored one exports the same symbols — so a project whose skeletons are 3.8
+ * needs a template built for 3.8; the default is native/CMakeLists.txt's (4.2).
+ * Absent, the build keeps whatever its cache already says, and the template
+ * manifest records that (see builtSpineVersion), so it never claims a default.
+ */
+function spineFlags(rootDir, options) {
+ const version = options.spine;
+ if (!version) return [];
+ checkSpineVendored(rootDir, version);
+ logger.info(`Linking Spine ${version}`);
+ return [`-DESTELLA_SPINE_VERSION=${version}`];
+}
+
+/** Refuses a --spine no runtime is vendored for — before any dependency builds. */
+function checkSpineVendored(rootDir, version) {
+ if (existsSync(path.join(rootDir, 'third_party', `spine-runtimes-${version}`))) return;
+ const vendored = readdirSync(path.join(rootDir, 'third_party'))
+ .filter((d) => d.startsWith('spine-runtimes-')).map((d) => d.slice('spine-runtimes-'.length));
+ throw new Error(`--spine ${version}: no such Spine runtime is vendored (have ${vendored.join(', ')}).`);
+}
+
// 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, '/');
@@ -505,6 +529,7 @@ async function buildAndroidHost(options) {
'-DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
`-DESTELLA_DAWN_DIR=${dawnDir}`,
`-DESTELLA_DAWN_BUILD=${dawnBuild}`,
+ ...spineFlags(rootDir, options),
];
if (ninja) configureArgs.push(`-DCMAKE_MAKE_PROGRAM=${ninja}`);
if (quickjs) {
@@ -682,6 +707,7 @@ async function buildIosHost(options) {
'-DCMAKE_OSX_ARCHITECTURES=arm64',
`-DCMAKE_OSX_DEPLOYMENT_TARGET=${deploymentTarget}`,
`-DCMAKE_OSX_SYSROOT=${slice.sysroot}`,
+ ...spineFlags(rootDir, options),
'-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
`-DESTELLA_DAWN_DIR=${fwd(dawnDir)}`,
@@ -894,6 +920,7 @@ async function buildNativeDeps(options) {
}
export async function buildNative(options = {}) {
+ if (options.spine) checkSpineVendored(config.paths.root, options.spine);
// Before anything that needs a toolchain: this only reads the manifest, and CI
// asks for it on a runner that has not set one up yet.
if (options.depsCacheKey) {
diff --git a/build-tools/tasks/nativeTemplateEmit.js b/build-tools/tasks/nativeTemplateEmit.js
index 798f97a1f..748539c4f 100644
--- a/build-tools/tasks/nativeTemplateEmit.js
+++ b/build-tools/tasks/nativeTemplateEmit.js
@@ -21,7 +21,7 @@ import { makeZip, zipTree } from '../utils/zip.js';
import {
templateLayout, templateId, ANDROID_ABIS, templateAbis, writeTemplateManifest,
missingTemplateFiles, installedTemplateDir, templateZipName, TEMPLATE_INDEX, TEMPLATE_FORMAT, templateJsEngine,
- BYTECODE_FILE,
+ BYTECODE_FILE, builtSpineVersion, DEFAULT_TEMPLATE_SPINE,
} from '../utils/nativeTemplate.js';
/** The Java shim's sources — the IME's own side of an editable field, which has to
@@ -231,7 +231,10 @@ export async function emitNativeTemplate(options) {
const manifest = writeTemplateManifest(dir, {
platform,
engineVersion,
- spineVersion: options.spineVersion || '4.2',
+ // What the host build linked, from its CMake cache: an export refuses to
+ // pair this template with skeletons of another version (#115).
+ spineVersion: builtSpineVersion(root, platform, platform === 'android' ? templateAbis(dir) : undefined)
+ ?? DEFAULT_TEMPLATE_SPINE,
// What runs the game's JS, so the editor (and a person) can tell a JIT
// template from an interpreter one without opening the binary.
jsEngine: templateJsEngine(dir, platform),
diff --git a/build-tools/utils/nativeTemplate.d.ts b/build-tools/utils/nativeTemplate.d.ts
index b6b051357..f206e3775 100644
--- a/build-tools/utils/nativeTemplate.d.ts
+++ b/build-tools/utils/nativeTemplate.d.ts
@@ -25,7 +25,10 @@ export interface NativeTemplateManifest {
/** Matched EXACTLY against the editor's version: the SDK bundle is compiled
* into the host binary, so a near-miss fails on a device. */
engineVersion: string;
- spineVersion: string;
+ /** The one Spine runtime the host links (read from its build, not assumed).
+ * Absent on templates written before it was recorded: those are 4.2 —
+ * read it through {@link templateSpineVersion}. */
+ spineVersion?: string;
/** iOS only. */
deploymentTarget?: string;
/** Android only. */
@@ -98,6 +101,9 @@ export function writeTemplateManifest(
meta: { platform: TemplatePlatform; engineVersion: string; abi?: string } & Record<string, unknown>,
): NativeTemplateManifest;
export function readTemplateManifest(dir: string): NativeTemplateManifest | null;
+export const DEFAULT_TEMPLATE_SPINE: string;
+export function templateSpineVersion(manifest: Pick<NativeTemplateManifest, 'spineVersion'> | null | undefined): string;
+export function builtSpineVersion(root: string, platform: TemplatePlatform, abis?: readonly string[]): string | null;
export function templateMatches(manifest: NativeTemplateManifest | null, want: TemplateWant): boolean;
export function templateZipName(platform: TemplatePlatform, engineVersion: string): string;
export function estellaDataDir(): string;
diff --git a/build-tools/utils/nativeTemplate.js b/build-tools/utils/nativeTemplate.js
index 6395f8e1d..b8b73ee47 100644
--- a/build-tools/utils/nativeTemplate.js
+++ b/build-tools/utils/nativeTemplate.js
@@ -443,6 +443,45 @@ export function readTemplateManifest(dir) {
}
}
+/** What a host links when nobody chose: native/CMakeLists.txt's own default. */
+export const DEFAULT_TEMPLATE_SPINE = '4.2';
+
+/** The Spine runtime a template without the field was built with — every one
+ * published before the manifest recorded it took the CMake default. */
+export function templateSpineVersion(manifest) {
+ return manifest?.spineVersion || DEFAULT_TEMPLATE_SPINE;
+}
+
+/** The build directories a template for `platform` is packed from. */
+function hostBuildDirs(root, platform, abis) {
+ if (platform === 'ios') return [path.join(root, 'build/cmake/native-ios')];
+ if (platform === 'android') return (abis ?? []).map((abi) => path.join(root, 'build/cmake/native', abi));
+ return [path.join(root, `build/cmake/native-${platform}`)];
+}
+
+/**
+ * The Spine runtime the host builds behind a template actually linked, read from
+ * their CMake caches. A host links exactly one (every vendored runtime exports the
+ * same symbols), and the manifest is what an export checks a project against, so
+ * it records what the build DID — a cache set by hand included — not a default.
+ * Null when no build dir has a cache to read.
+ */
+export function builtSpineVersion(root, platform, abis) {
+ const seen = new Map();
+ for (const dir of hostBuildDirs(root, platform, abis)) {
+ const cache = path.join(dir, 'CMakeCache.txt');
+ if (!existsSync(cache)) continue;
+ const m = /^ESTELLA_SPINE_VERSION:[A-Z]+=(.*)$/m.exec(readFileSync(cache, 'utf8'));
+ seen.set(dir, m ? m[1].trim() : DEFAULT_TEMPLATE_SPINE);
+ }
+ const versions = new Set(seen.values());
+ if (versions.size > 1) {
+ throw new Error(`The ${platform} builds link different Spine runtimes (${[...seen].map(([d, v]) => `${path.basename(d)}: ${v}`).join(', ')}): `
+ + 'one template carries one. Rebuild them with the same --spine.');
+ }
+ return versions.size ? [...versions][0] : null;
+}
+
export function writeTemplateManifest(dir, meta) {
const manifest = {
kind: 'estella-native-template',
diff --git a/desktop b/desktop
index a10a9b0cf..b1b1632b5 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit a10a9b0cf4c4dadcbc157beea5d16dd0bad0820a
+Subproject commit b1b1632b5c4664352aa485a4b95c9db30c28acd2
diff --git a/docs/astro/src/content/docs/publishing/android-ios.mdx b/docs/astro/src/content/docs/publishing/android-ios.mdx
index 79176ce45..51c2c5c60 100644
--- a/docs/astro/src/content/docs/publishing/android-ios.mdx
+++ b/docs/astro/src/content/docs/publishing/android-ios.mdx
@@ -209,7 +209,7 @@ behaves exactly as it does in a browser.
| Sprites, tilemaps, particles, post-processing | Native (Dawn) |
| Text, bitmap text, rich text | Same atlas + layout as the web; glyphs rasterized from the OS font |
| Physics (Box2D) | Compiled in; solved across worker threads |
-| Spine | Compiled in — one runtime version per binary (`-DESTELLA_SPINE_VERSION`) |
+| Spine | Compiled in — one runtime version per binary; see [Spine versions](#spine-versions) |
| DragonBones | Compiled in — one runtime, since the format is frozen |
| Video | Compiled in (cooked at build, decoded on device) |
| Audio | Native mixer ([miniaudio](https://miniaud.io/)) — CoreAudio / AAudio |
@@ -219,6 +219,33 @@ behaves exactly as it does in a browser.
| Compressed textures | KTX2 transcoded to the device's format (ASTC → ETC2 → BC), with mip chains |
| Lifecycle | `onShow` / `onHide` and OS memory warnings reach the app |
+### Spine versions
+
+A browser build carries a Spine runtime for each version its skeletons were
+exported from. A native app cannot: every vendored Spine runtime (2.1, 3.8, 4.1,
+4.2, 4.3) exports the same symbols, so a host binary links **one**. The official
+runtime templates link **4.2**.
+
+The Spine version in Project Settings is a preference; the skeleton files decide.
+When you package for Android, iOS or the desktop, the export reads the version
+of every skeleton it ships and compares it with the version the installed
+template links. The app is still assembled, since the rest of the game runs,
+but the export's warnings name every skeleton that will not play in it and the
+template build that would play it. Project Settings → Spine also shows which
+version each installed template links.
+
+To ship skeletons of another version, build the template yourself with that
+runtime linked:
+
+```bash
+node build-tools/cli.js native --target android --spine 3.8
+```
+
+`--target` is `android`, `ios`, `windows`, `macos` or `linux`. The build
+installs the template for this editor version, and its `template.json` records
+the version the host linked. One project can only use one Spine version
+natively: skeletons from two versions have to be exported again from one.
+
If a future build ever *does* drop a subsystem, the export names it — with the
scenes that use it — instead of quietly shipping a package missing half a scene.
diff --git a/docs/astro/src/content/docs/zh-cn/publishing/android-ios.mdx b/docs/astro/src/content/docs/zh-cn/publishing/android-ios.mdx
index 24ce3cb15..1293d2dcd 100644
--- a/docs/astro/src/content/docs/zh-cn/publishing/android-ios.mdx
+++ b/docs/astro/src/content/docs/zh-cn/publishing/android-ios.mdx
@@ -171,7 +171,7 @@ Android 的下限是 29,因为引擎的字体路径调用 `AFontMatcher_create`,
| 精灵、瓦片地图、粒子、后处理 | 原生(Dawn) |
| 文本、位图字体、富文本 | 与网页端相同的图集与排版;字形从系统字体栅格化 |
| 物理(Box2D) | 编译进包;跨工作线程求解 |
-| Spine | 编译进包——每个二进制一个运行时版本(`-DESTELLA_SPINE_VERSION`) |
+| Spine | 编译进包——每个二进制一个运行时版本;见 [Spine 版本](#spine-版本) |
| DragonBones | 编译进包——只有一个运行时,因为格式是固定的 |
| 视频 | 编译进包(构建时 cook,真机解码) |
| 音频 | 原生混音器([miniaudio](https://miniaud.io/))—— CoreAudio / AAudio |
@@ -181,6 +181,26 @@ Android 的下限是 29,因为引擎的字体路径调用 `AFontMatcher_create`,
| 压缩纹理 | KTX2 转码到设备支持的格式(ASTC → ETC2 → BC),含 mip 链 |
| 生命周期 | `onShow` / `onHide` 与系统内存警告都能到达应用 |
+### Spine 版本
+
+网页构建会为骨架导出时所用的每个 Spine 版本各带一个运行时。原生应用做不到:所有内置的
+Spine 运行时(2.1、3.8、4.1、4.2、4.3)导出的符号相同,所以一个宿主二进制只能链接**一个**。
+官方运行时模板链接的是 **4.2**。
+
+项目设置里的 Spine 版本只是偏好,真正起决定作用的是骨架文件。打 Android、iOS 或桌面包时,
+导出会读取每个要打包的骨架的版本,和已安装模板链接的版本比对。应用照常组装(游戏其余部分能正常运行),
+但导出警告会点名每个在这个包里播放不了的骨架,并说明需要哪种模板才能播放。项目设置 → Spine 也会显示每个已安装模板链接的版本。
+
+要打包其他版本的骨架,用对应运行时自行编译模板:
+
+```bash
+node build-tools/cli.js native --target android --spine 3.8
+```
+
+`--target` 可以是 `android`、`ios`、`windows`、`macos` 或 `linux`。编译会为当前编辑器版本安装模板,
+模板的 `template.json` 记录宿主实际链接的版本。一个项目在原生端只能用一个 Spine 版本:
+来自两个版本的骨架需要用同一个版本重新导出。
+
万一将来某个构建*真的*砍掉了某个子系统,导出会点名它——连同用到它的场景——
而不是悄悄发出一个缺了半个场景的包。
diff --git a/native/README.md b/native/README.md
index 5d22e1d28..1d0c8a0e0 100644
--- a/native/README.md
+++ b/native/README.md
@@ -94,8 +94,11 @@ gating installs physics or spine exactly as it does in a browser (see
Spine is the one build-time choice: the vendored runtimes (2.1 / 3.8 / 4.1 / 4.2 / 4.3)
export the same symbol names, so a binary carries exactly one.
-`-DESTELLA_SPINE_VERSION=4.1` picks another; `spine_runtimeVersion()` reports what
-was linked, and content authored against a different release is told so by name
+`node build-tools/cli.js native --spine 4.1` (or `-DESTELLA_SPINE_VERSION=4.1`) picks
+another, and the template's `template.json` records what the build linked, read from
+its CMake cache; an export names each skeleton of another version in its warnings.
+`spine_runtimeVersion()` reports what was linked at runtime, and content authored
+against a different release is told so by name
instead of being decoded by the wrong parser. Which runtime backend a release uses
follows from its tree: 3.8 through 4.2 vendor the pure-C runtime, 2.1 vendors it flat
and in a dialect old enough to warrant its own backend, and 4.3 replaced it with a
diff --git a/pipeline/src/bundle/sideModuleScan.ts b/pipeline/src/bundle/sideModuleScan.ts
index 84466b7f8..6e3e62aeb 100644
--- a/pipeline/src/bundle/sideModuleScan.ts
+++ b/pipeline/src/bundle/sideModuleScan.ts
@@ -33,7 +33,7 @@ export const WECHAT_MODULE_BUILD_TARGET: Record<string, string> = {
'spine:4.3': 'spine-wechat',
};
-interface CookEntryLike {
+export interface CookEntryLike {
path: string;
sourcePath?: string;
type?: string;
@@ -158,19 +158,38 @@ export async function scanSideModuleIds(input: SideModuleScanInput): Promise<Set
if (/\.esv(\.bin)?$/.test(lower)) ids.add('videodec');
const editorType = getEditorType(e.sourcePath ?? e.path);
if (editorType === 'dragonbones-skeleton' || editorType === 'dragonbones-atlas') ids.add('dragonbones');
+ }
+ for (const v of (await scanSpineSkeletons(input.cookEntries, input.stagedDir)).keys()) ids.add(spineModuleId(v));
+ return ids;
+}
+
+/**
+ * Each staged skeleton by the Spine runtime it was exported for, read from the
+ * file itself (paths are the authored ones). The web carries a side module per
+ * version; a native host links ONE runtime, so this is also what an export holds
+ * a native template against.
+ */
+export async function scanSpineSkeletons(
+ cookEntries: readonly CookEntryLike[], stagedDir: string,
+): Promise<Map<SpineVersion, string[]>> {
+ const byVersion = new Map<SpineVersion, string[]>();
+ for (const e of cookEntries) {
if (e.type !== 'spine') continue;
const ext = path.extname(e.sourcePath ?? e.path).toLowerCase();
try {
let v: SpineVersion | null = null;
if (ext === '.skel') {
- v = detectSpineVersion(new Uint8Array(await readFile(path.join(input.stagedDir, e.path))));
+ v = detectSpineVersion(new Uint8Array(await readFile(path.join(stagedDir, e.path))));
} else if (ext === '.json') {
- v = detectSpineVersionJson(await readFile(path.join(input.stagedDir, e.path), 'utf8'));
+ v = detectSpineVersionJson(await readFile(path.join(stagedDir, e.path), 'utf8'));
}
- if (v) ids.add(spineModuleId(v));
+ if (!v) continue;
+ const list = byVersion.get(v) ?? [];
+ list.push(e.sourcePath ?? e.path);
+ byVersion.set(v, list);
} catch { /* unreadable cook entry — cookAssets already warned */ }
}
- return ids;
+ return byVersion;
}
/**
diff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.ts
index 37ca7a4a6..606d716e0 100644
--- a/pipeline/src/export/exportGame.ts
+++ b/pipeline/src/export/exportGame.ts
@@ -87,7 +87,8 @@ import { sizeSettingsOf } from './sizeHistory';
import { loadProjectModules, sideModuleDeclarations, stageProjectModules } from './projectModules';
import { subsystemGapWarnings, targetGaps } from '../project/targetSupport';
import { contentSubsystems } from './contentSubsystems';
-import { scanSideModuleIds, sideModuleFiles, shipsSideModule, textureDecoderBytes } from '../bundle/sideModuleScan';
+import { scanSideModuleIds, scanSpineSkeletons, sideModuleFiles, shipsSideModule, textureDecoderBytes } from '../bundle/sideModuleScan';
+import { nativeSpineMismatch } from './nativeTemplates';
import { MODULES, NATIVE_MODULE_REGISTRY } from '../../../tools/nativeScriptModules.js';
@@ -1042,6 +1043,12 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>
// asset model in the package — the mini-game export has always done this.
await rm(path.join(payloadDir, 'assets.manifest.json'), { force: true });
+ // A native host links one Spine runtime, so a skeleton of another version
+ // does not play on it (#115). Read from the files: the project setting is a
+ // preference, and editor Play loads every version.
+ const nativeSpine = nativeContent
+ ? await scanSpineSkeletons(cookEntries, payloadDir) : new Map<string, string[]>();
+
// What wasm this project's content pulls in — evidence for the plan below, and
// the filter the runtime tree is copied through further down.
const sideModuleIds = !nativeContent && existsSync(opts.wasmDir)
@@ -1306,6 +1313,8 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>
if (platform === 'ios') {
progress({ phase: 'Writing Xcode project' });
const sources = opts.iosSources ?? null;
+ const spineProblem = sources ? nativeSpineMismatch(nativeSpine, path.dirname(sources.xcframework), 'ios') : null;
+ if (spineProblem) warnings.push(spineProblem);
if (sources) {
const projectDir = await emitIosXcodeProject(absOut, appConfig, sources, undefined, icon);
xcodeProject = projectDir;
@@ -1328,6 +1337,8 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>
+ 'Project, then export again.');
}
for (const { os, dir } of templates) {
+ const spineProblem = nativeSpineMismatch(nativeSpine, dir, os);
+ if (spineProblem) warnings.push(spineProblem);
progress({ phase: `Assembling the ${os} app` });
const built = await assembleDesktopApp({
platform: os, templateDir: dir, contentDir: absOut, outDir: absOut, app: appConfig,
@@ -1389,6 +1400,8 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>
+ 'PhysX library: the app runs on Jolt. Install a template built with PhysX, then export again.');
}
}
+ const spineProblem = template ? nativeSpineMismatch(nativeSpine, template, 'android') : null;
+ if (spineProblem) warnings.push(spineProblem);
if (!template) {
warnings.push(`No Android runtime template is installed for this editor version, so no ${
wantsProject ? 'project was written' : 'APK was assembled'} — the content is here. `
diff --git a/pipeline/src/export/nativeTemplates.ts b/pipeline/src/export/nativeTemplates.ts
index 956da2f4e..0b89bdcc1 100644
--- a/pipeline/src/export/nativeTemplates.ts
+++ b/pipeline/src/export/nativeTemplates.ts
@@ -22,13 +22,42 @@ import { randomUUID, createHash } from 'node:crypto';
import {
findTemplate, readTemplateManifest, missingTemplateFiles, installedTemplateDir,
templateStoreDir, iosTemplateSources, releaseAssetBases, parseTemplateIndex,
- TEMPLATE_INDEX,
+ TEMPLATE_INDEX, templateSpineVersion,
type TemplatePlatform, type NativeTemplateManifest,
} from '../../../build-tools/utils/nativeTemplate.js';
import { extractZip } from '../../../build-tools/utils/zip.js';
export type { NativeTemplateManifest };
+/**
+ * Which Spine skeletons a package ships will not play on a template, said as a
+ * warning, or null when every one will. A native host links ONE Spine runtime
+ * (every vendored one exports the same symbols), so a skeleton plays only if it
+ * was exported from the version the template was built with — the project
+ * setting is a preference, the skeleton files are the fact (#115). The package
+ * is still assembled: the rest of the game runs, and the runtime names each
+ * skeleton it refuses. `target` is the `cli native --target` name.
+ */
+export function nativeSpineMismatch(
+ skeletons: ReadonlyMap<string, readonly string[]>, templateDir: string, target: string,
+): string | null {
+ const linked = templateSpineVersion(readTemplateManifest(templateDir));
+ const other = [...skeletons].filter(([v]) => v !== linked).sort(([a], [b]) => a.localeCompare(b));
+ if (other.length === 0) return null;
+ const files = other.flatMap(([, paths]) => paths);
+ const named = files.slice(0, 3).join(', ') + (files.length > 3 ? `, and ${files.length - 3} more` : '');
+ const versions = other.map(([v]) => v);
+ const them = files.length === 1 ? 'it' : 'them';
+ const fix = versions.length === 1 && !skeletons.has(linked)
+ ? `Build a template for ${versions[0]} with \`node build-tools/cli.js native --target ${target} --spine ${versions[0]}\`, `
+ + `or export ${them} from Spine ${linked}.`
+ : `Export ${them} from Spine ${linked}, or export every skeleton from one version and build a template for `
+ + `that version with \`node build-tools/cli.js native --target ${target} --spine <version>\`.`;
+ return `${files.length} Spine skeleton${files.length === 1 ? ' is' : 's are'} ${versions.join(' / ')} (${named}), `
+ + `and the ${target} runtime template links Spine ${linked}: a native host carries one Spine runtime, `
+ + `so ${files.length === 1 ? 'it does' : 'they do'} not play in this app. ${fix}`;
+}
+
/** A template this editor can actually use, with where it came from. */
export interface UsableTemplate {
dir: string;
@@ -63,6 +92,9 @@ export interface NativeTemplateEntry {
/** Android: the architectures it carries. */
abis: string[];
engineVersion: string;
+ /** The one Spine runtime the host links; skeletons of any other version do
+ * not play on it (see {@link nativeSpineMismatch}). */
+ spineVersion: string;
dir: string;
/** Usable by THIS editor — an older release's template stays listed (removing
* it is the user's call) but cannot be packaged with. */
@@ -85,6 +117,7 @@ export function listNativeTemplates(engineVersion: string): NativeTemplateEntry[
platform: manifest.platform,
abis: manifest.abis ?? [],
engineVersion: manifest.engineVersion,
+ spineVersion: templateSpineVersion(manifest),
dir,
current: manifest.engineVersion === engineVersion
&& missingTemplateFiles(dir, manifest.platform).length === 0,
diff --git a/pipeline/tests/native-template.test.ts b/pipeline/tests/native-template.test.ts
index 465a22f28..372c6fee2 100644
--- a/pipeline/tests/native-template.test.ts
+++ b/pipeline/tests/native-template.test.ts
@@ -16,12 +16,12 @@ import { tmpdir } from 'node:os';
import path from 'node:path';
import {
resolveNativeTemplate, iosSourcesFromTemplate, installNativeTemplate,
- listNativeTemplates, removeNativeTemplate, downloadNativeTemplate,
+ listNativeTemplates, removeNativeTemplate, downloadNativeTemplate, nativeSpineMismatch,
} from '../src/export/nativeTemplates';
import { listPlatforms } from '../src/export/platformCatalog';
import {
requiredTemplateFiles, templateLayout, installedTemplateDir, parseTemplateIndex,
- missingTemplateEntries, isTemplatePlatform,
+ missingTemplateEntries, isTemplatePlatform, builtSpineVersion, templateSpineVersion,
TEMPLATE_FORMAT, TEMPLATE_MANIFEST, TEMPLATE_INDEX, TEMPLATE_PLATFORMS,
type TemplatePlatform,
} from '../../build-tools/utils/nativeTemplate.js';
@@ -75,6 +75,72 @@ function writeTemplateZip(version: string, omit?: string, platform: TemplatePlat
return file;
}
+// #115: a host links ONE Spine runtime, so the template says which, read off the
+// build rather than assumed, and an export holds the skeletons it ships to it.
+describe('the Spine runtime a template links', () => {
+ function manifestDir(spineVersion?: string): string {
+ const dir = mkdtempSync(path.join(scratch, 'tmpl-'));
+ writeFileSync(path.join(dir, TEMPLATE_MANIFEST), JSON.stringify({
+ kind: 'estella-native-template', formatVersion: TEMPLATE_FORMAT, id: 'android', platform: 'android',
+ engineVersion: VERSION, ...(spineVersion ? { spineVersion } : {}),
+ }));
+ return dir;
+ }
+ function hostCache(rel: string, line: string | null): void {
+ mkdirSync(path.join(scratch, rel), { recursive: true });
+ writeFileSync(path.join(scratch, rel, 'CMakeCache.txt'),
+ `CMAKE_BUILD_TYPE:STRING=Release
+${line ?? ''}
+`);
+ }
+
+ it('reads what the host build linked from its CMake cache', () => {
+ hostCache('build/cmake/native-windows', 'ESTELLA_SPINE_VERSION:STRING=3.8');
+ expect(builtSpineVersion(scratch, 'windows')).toBe('3.8');
+ hostCache('build/cmake/native/arm64-v8a', 'ESTELLA_SPINE_VERSION:STRING=3.8');
+ expect(builtSpineVersion(scratch, 'android', ['arm64-v8a'])).toBe('3.8');
+ });
+
+ it('takes the CMake default from a cache that never set it, and says nothing without a build', () => {
+ hostCache('build/cmake/native-linux', null);
+ expect(builtSpineVersion(scratch, 'linux')).toBe('4.2');
+ expect(builtSpineVersion(scratch, 'macos')).toBeNull();
+ });
+
+ it('refuses to pack ABIs that linked different runtimes into one template', () => {
+ hostCache('build/cmake/native/arm64-v8a', 'ESTELLA_SPINE_VERSION:STRING=3.8');
+ hostCache('build/cmake/native/x86_64', 'ESTELLA_SPINE_VERSION:STRING=4.2');
+ expect(() => builtSpineVersion(scratch, 'android', ['arm64-v8a', 'x86_64'])).toThrow(/same --spine/);
+ });
+
+ it('reads a template written before the field as the 4.2 it was built with', () => {
+ expect(templateSpineVersion({})).toBe('4.2');
+ expect(templateSpineVersion({ spineVersion: '3.8' })).toBe('3.8');
+ });
+
+ it('passes skeletons of the linked version, and content with no skeletons at all', () => {
+ expect(nativeSpineMismatch(new Map([['3.8', ['a.skel']]]), manifestDir('3.8'), 'android')).toBeNull();
+ expect(nativeSpineMismatch(new Map(), manifestDir('3.8'), 'android')).toBeNull();
+ });
+
+ it('names the skeletons that will not play, and the build that would play them', () => {
+ const why = nativeSpineMismatch(new Map([['3.8', ['hero.skel']]]), manifestDir(), 'android');
+ expect(why).toContain('hero.skel');
+ expect(why).toContain('Spine 4.2');
+ expect(why).toContain('node build-tools/cli.js native --target android --spine 3.8');
+ });
+
+ // spine-demo ships 4.1 and 4.2: on the 4.2 template the 4.2 ones play, so only
+ // the 4.1 ones are named — and no single --spine build would play them all.
+ it('names only the skeletons of another version when some match', () => {
+ const why = nativeSpineMismatch(
+ new Map([['4.2', ['ok.skel']], ['4.1', ['a.json', 'b.json', 'c.json', 'd.json']]]), manifestDir('4.2'), 'windows');
+ expect(why).toContain('4 Spine skeletons are 4.1 (a.json, b.json, c.json, and 1 more)');
+ expect(why).not.toContain('ok.skel');
+ expect(why).toContain('from one version');
+ });
+});
+
describe('installing a runtime template', () => {
it('installs an archive and makes the platform resolvable', () => {
expect(resolveNativeTemplate('ios', VERSION)).toBeNull();