@threenative/runtime-native 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,14 +15,60 @@ import {
15
15
  writeFileSync,
16
16
  } from 'node:fs';
17
17
  import { tmpdir } from 'node:os';
18
- import { dirname, join, resolve } from 'node:path';
18
+ import { basename, dirname, join, resolve } from 'node:path';
19
19
  import { fileURLToPath, pathToFileURL } from 'node:url';
20
20
 
21
21
  import { assertNativeAssetsDecodable, deriveDesktopWebpSupport } from './asset-preflight.mjs';
22
+ import { selectManifestAssets } from './asset-manifest.mjs';
22
23
  import { installPrebuilt } from './install-prebuilt.mjs';
23
24
 
25
+ // The container helper is imported lazily by the release path only, so a debug build never loads
26
+ // it, and it ships in package.json `files` so a published `--mode release` run resolves it.
27
+ const loadDistribution = () => import('./desktop-distribution.mjs');
28
+
24
29
  const runtimeRoot = resolve(fileURLToPath(new URL('..', import.meta.url)));
25
30
 
31
+ /** Normalize `spawnSync` into the shape every injected tool executor returns. */
32
+ function exec(command, args, options = {}) {
33
+ const result = spawnSync(command, args, { encoding: 'utf8', ...options });
34
+ return {
35
+ error: result.error,
36
+ status: result.status,
37
+ stdout: result.stdout ?? '',
38
+ stderr: result.stderr ?? '',
39
+ };
40
+ }
41
+
42
+ /**
43
+ * Strip debug and symbol sections from a packaged runtime copy, in place.
44
+ *
45
+ * Runs on the package COPY, never the build-tree original: the original keeps its symbols for
46
+ * debugging, the artifact the player installs does not carry them. Linux only: `--strip-all` keeps
47
+ * `.dynsym`, so the loader still resolves. macOS is left alone because `strip` invalidates the
48
+ * linker signature Apple Silicon requires to launch an unsigned build, and no macOS lane proves a
49
+ * re-sign here; Windows has no strip step.
50
+ *
51
+ * A machine with no strip tool is not a failed build — the unstripped runtime ships with one
52
+ * warning naming its size in bytes. A tool that runs and fails is: its stderr is the failure.
53
+ */
54
+ export function stripDesktopRuntime(file, { platform = process.platform, run = exec, warn = console.warn } = {}) {
55
+ if (platform !== 'linux') return { stripped: false, reason: platform };
56
+ for (const command of ['strip', 'llvm-strip']) {
57
+ const result = run(command, ['--strip-all', file], { stdio: ['ignore', 'pipe', 'pipe'] });
58
+ if (result.error) continue;
59
+ if (result.status !== 0) {
60
+ throw new Error(
61
+ `TN_DESKTOP_STRIP_FAILED: '${command}' exited ${result.status ?? 'unknown'} on ${basename(file)}.\n${result.stderr ?? ''}`,
62
+ );
63
+ }
64
+ return { stripped: true, command };
65
+ }
66
+ warn(
67
+ `ThreeNative desktop packaging: no strip tool on PATH, shipping unstripped ${basename(file)} (${statSync(file).size} bytes).`,
68
+ );
69
+ return { stripped: false, reason: 'tool-missing' };
70
+ }
71
+
26
72
  /**
27
73
  * Resolve the desktop runtime binary a consumer build compiles against.
28
74
  *
@@ -47,6 +93,44 @@ export async function resolveDesktopRuntime(explicit, options = {}) {
47
93
  return installPrebuilt({ ...options.install, reuse: true });
48
94
  }
49
95
 
96
+ /**
97
+ * Non-secret signing inputs, from the build environment the way Android signing already works.
98
+ *
99
+ * `THREENATIVE_DESKTOP_SIGN=1` requests signing; the identity/certificate/profile/timestamp values
100
+ * name the developer's credentials but never carry the secret itself — the private key and the
101
+ * notarytool password stay in the OS keychain. No inputs and no request means unsigned preparation,
102
+ * which is recorded as `signed: false`.
103
+ */
104
+ export function desktopSigningFromEnvironment(env = process.env) {
105
+ const requested = env.THREENATIVE_DESKTOP_SIGN === '1' || env.THREENATIVE_DESKTOP_SIGN === 'true';
106
+ // A CI job writing `SUBJECT: ${{ secrets.WIN_SIGN_SUBJECT }}` with the secret unset hands us the
107
+ // empty string, not undefined. Treating that as "signing requested" turns a release that used to
108
+ // produce an unsigned container into a hard failure, so blank reads the same as absent.
109
+ const set = (value) => (typeof value === 'string' && value.trim() !== '' ? value : undefined);
110
+ const identity = set(env.THREENATIVE_DESKTOP_CODESIGN_IDENTITY);
111
+ const certificate = set(env.THREENATIVE_DESKTOP_SIGN_CERTIFICATE);
112
+ const subject = set(env.THREENATIVE_DESKTOP_SIGN_SUBJECT);
113
+ const keychainProfile = set(env.THREENATIVE_DESKTOP_NOTARY_PROFILE);
114
+ const timestampUrl = set(env.THREENATIVE_DESKTOP_TIMESTAMP_URL);
115
+ if (!requested && identity === undefined && certificate === undefined && subject === undefined &&
116
+ keychainProfile === undefined) {
117
+ return undefined;
118
+ }
119
+ // Knowable here, so refuse here: the same clash inside signDesktopArtifact costs a whole release
120
+ // build first. That check stays as well, because `signing` can be passed in directly.
121
+ if (certificate !== undefined && subject !== undefined) {
122
+ throw new Error('TN_DESKTOP_SIGNING_CREDENTIALS_AMBIGUOUS: THREENATIVE_DESKTOP_SIGN_CERTIFICATE and THREENATIVE_DESKTOP_SIGN_SUBJECT are both set; one of them would be silently ignored.');
123
+ }
124
+ return {
125
+ ...(requested ? { requested: true } : {}),
126
+ ...(identity === undefined ? {} : { identity }),
127
+ ...(certificate === undefined ? {} : { certificate }),
128
+ ...(subject === undefined ? {} : { subject }),
129
+ ...(timestampUrl === undefined ? {} : { timestampUrl }),
130
+ ...(keychainProfile === undefined ? {} : { keychainProfile, notarize: true }),
131
+ };
132
+ }
133
+
50
134
  export const DEFAULT_DESKTOP_CONFIG = {
51
135
  app: { id: 'com.threenative.game', name: 'ThreeNative', version: '0.1.0', build: 1 },
52
136
  display: { orientation: 'landscape', fullscreen: true, keepScreenOn: false, maxFps: 60 },
@@ -67,10 +151,14 @@ export function parseArgs(args) {
67
151
  for (let index = 0; index < args.length; index += 2) {
68
152
  const flag = args[index];
69
153
  const value = args[index + 1];
70
- if (!['--assets', '--bundle', '--config', '--output', '--runtime', '--ui'].includes(flag) || !value) {
71
- throw new Error('Usage: package-desktop.mjs --bundle FILE --output FILE [--runtime FILE] [--assets DIR] [--ui DIR] [--config FILE]');
154
+ if (!['--assets', '--bundle', '--config', '--mode', '--output', '--runtime', '--ui'].includes(flag) || !value) {
155
+ throw new Error('Usage: package-desktop.mjs --bundle FILE --output FILE [--runtime FILE] [--assets DIR] [--ui DIR] [--config FILE] [--mode debug|release]');
72
156
  }
73
- options[flag.slice(2)] = resolve(value);
157
+ // `--mode` is a word, not a path; every other flag names a filesystem location.
158
+ options[flag.slice(2)] = flag === '--mode' ? value : resolve(value);
159
+ }
160
+ if (options.mode !== undefined && options.mode !== 'debug' && options.mode !== 'release') {
161
+ throw new Error(`Unknown build mode '${options.mode}'. Choose debug or release.`);
74
162
  }
75
163
  // `--runtime` is optional: a consumer build with no `--runtime` installs the verified
76
164
  // prebuilt from the release manifest via resolveDesktopRuntime. A maintainer build passes
@@ -95,18 +183,87 @@ export function packageDesktop(options) {
95
183
  if (!existsSync(options.runtime)) {
96
184
  throw new Error(`Missing prebuilt runtime for '${key}': ${options.runtime}`);
97
185
  }
98
- return compileDesktopArtifact(options, options.runtime);
186
+ return compileOrPackage(options, options.runtime);
99
187
  }
100
188
  return resolveDesktopRuntime(undefined, { runtimeSource: options.runtimeSource, install: options.install }).then((runtime) =>
101
- compileDesktopArtifact(options, runtime),
189
+ compileOrPackage(options, runtime),
102
190
  );
103
191
  }
104
192
 
105
- function compileDesktopArtifact(options, runtime) {
193
+ function compileOrPackage(options, runtime) {
194
+ if (options.mode === 'release') return packageDesktopRelease(options, runtime);
195
+ return compileDesktopArtifact(options, runtime);
196
+ }
197
+
198
+ /**
199
+ * Wrap the compiled executable in the complete desktop container for the host OS (PRD-365).
200
+ *
201
+ * The runtime compiler only knows how to produce a raw executable and stage `ui/` beside it; the
202
+ * container layout, OS metadata and dependency census are OS operations and live in
203
+ * `desktop-distribution.mjs`. The raw debug path above is untouched.
204
+ */
205
+ async function packageDesktopRelease(options, runtime) {
206
+ const { classifyDependencies, containerSlug, discoverRuntimeDependencies, packageDesktopContainer } =
207
+ await loadDistribution();
208
+ const staging = mkdtempSync(join(tmpdir(), 'threenative-desktop-release-'));
209
+ try {
210
+ const config = options.config === undefined ? DEFAULT_DESKTOP_CONFIG : readConfig(options.config);
211
+ // Signing inputs are non-secret identity/options from the build environment; secrets stay in
212
+ // the OS keychain. Without them, release stays an unsigned-but-complete container.
213
+ const signing = desktopSigningFromEnvironment();
214
+ const rawOutput = join(staging, containerSlug(basename(options.output)));
215
+ const { bundle, executable } = compileDesktopArtifact({ ...options, output: rawOutput }, runtime, {
216
+ sidecar: true,
217
+ });
218
+ const uiRenderer = config.ui?.renderer === 'web' ? 'web' : 'native';
219
+ const uiDirectory = uiRenderer === 'web' ? join(dirname(executable), 'ui') : undefined;
220
+ const discovered = options.dependencies === undefined
221
+ ? classifyDependencies(discoverRuntimeDependencies(executable, { platform: process.platform, run: options.run }), {
222
+ platform: process.platform,
223
+ })
224
+ : { bundled: options.dependencies, prerequisites: options.prerequisites ?? [] };
225
+ const icon = config.app?.icon === undefined ? undefined : resolve(config.app.icon);
226
+ const result = packageDesktopContainer({
227
+ arch: process.arch,
228
+ bundle,
229
+ config,
230
+ dependencies: discovered.bundled,
231
+ executable,
232
+ icon,
233
+ output: options.output,
234
+ platform: process.platform,
235
+ prerequisites: discovered.prerequisites,
236
+ run: options.run,
237
+ signing,
238
+ uiDirectory,
239
+ uiRenderer,
240
+ });
241
+ console.log(`ThreeNative desktop container${result.signed ? ' (signed)' : ' (unsigned)'}: ${result.archive}`);
242
+ if (result.installer) console.log('ThreeNative Windows installer: ' + result.installer);
243
+ return result.archive;
244
+ } finally {
245
+ rmSync(staging, { force: true, recursive: true });
246
+ }
247
+ }
248
+
249
+ /**
250
+ * Build the desktop artifact.
251
+ *
252
+ * Debug appends the game to a copy of the runtime, which is one self-contained file. Release takes
253
+ * `sidecar`, which writes the game to `game.bundle` and leaves the executable a bare runtime copy:
254
+ * anything that rewrites the executable afterwards - rcedit embedding the icon, `signtool` adding
255
+ * the certificate table, `codesign` sealing a bundle - moves or discards data appended past the
256
+ * end of the image, and the loader finds its footer only at physical EOF. Keeping the game beside
257
+ * the executable instead of inside it is what makes release resource-editing and signing safe.
258
+ */
259
+ function compileDesktopArtifact(options, runtime, { sidecar = false } = {}) {
106
260
  const output = process.platform === 'win32' && !options.output.endsWith('.exe')
107
261
  ? `${options.output}.exe`
108
262
  : options.output;
109
263
  mkdirSync(dirname(output), { recursive: true });
264
+ // Named `game.bundle` because that is what the runtime's own `findExternalBundle` looks for
265
+ // beside the executable; the container places it where each platform's loader searches.
266
+ const bundle = join(dirname(output), 'game.bundle');
110
267
  const staging = mkdtempSync(join(tmpdir(), 'threenative-desktop-'));
111
268
  try {
112
269
  const stagedEntry = stageDesktopFiles(
@@ -115,6 +272,9 @@ function compileDesktopArtifact(options, runtime) {
115
272
  staging,
116
273
  options.config === undefined ? undefined : readConfig(options.config),
117
274
  process.env.THREENATIVE_RUNTIME_SOURCE ?? runtimeRoot,
275
+ // Installed from a tarball there is no CMakeLists to read, so the decoder preflight asks
276
+ // this binary — the one the container is about to ship — instead of guessing.
277
+ runtime,
118
278
  );
119
279
  // The UI bundle sits beside the executable rather than inside it. Desktop compiles to one
120
280
  // file, but the overlay's web view reads its page from a real path — that is what gives it a
@@ -134,18 +294,30 @@ function compileDesktopArtifact(options, runtime) {
134
294
  '--include',
135
295
  staging,
136
296
  '--out',
137
- output,
297
+ sidecar ? bundle : output,
138
298
  ];
299
+ // `--bundle-only` writes the bundle alone and copies no executable, so the runtime copy below
300
+ // carries no appended payload for a later PE or Mach-O rewrite to lose.
301
+ if (sidecar) args.push('--bundle-only');
139
302
  const result = spawnSync(runtime, args, { encoding: 'utf8', stdio: 'inherit' });
140
303
  if (result.error) throw result.error;
141
304
  if (result.status !== 0)
142
305
  throw new Error(`Runtime packager exited with code ${result.status ?? 'unknown'}.`);
306
+ if (sidecar) {
307
+ if (!existsSync(bundle)) {
308
+ throw new Error(`TN_DESKTOP_BUNDLE_MISSING: the runtime packager wrote no bundle at ${bundle}.`);
309
+ }
310
+ copyFileSync(runtime, output);
311
+ // The sidecar copy is the bare runtime the container ships, so it is stripped here; the
312
+ // executable the runtime packager wrote in debug mode has the game appended and must not be.
313
+ stripDesktopRuntime(output, { run: options.stripRun });
314
+ }
143
315
  } finally {
144
316
  rmSync(staging, { force: true, recursive: true });
145
317
  }
146
318
  if (process.platform !== 'win32') chmodSync(output, 0o755);
147
319
  console.log(`ThreeNative desktop artifact: ${output}`);
148
- return output;
320
+ return sidecar ? { bundle, executable: output } : output;
149
321
  }
150
322
 
151
323
  /**
@@ -189,6 +361,7 @@ export function stageDesktopFiles(
189
361
  staging,
190
362
  config = undefined,
191
363
  runtimeSource = runtimeRoot,
364
+ runtimeExecutable = undefined,
192
365
  ) {
193
366
  mkdirSync(staging, { recursive: true });
194
367
  if (assets && existsSync(assets)) {
@@ -200,13 +373,16 @@ export function stageDesktopFiles(
200
373
  // read the bytes on its way past. Same gate, desktop's own derived capabilities.
201
374
  assertNativeAssetsDecodable(assets, {
202
375
  target: 'desktop',
203
- capabilities: { webp: deriveDesktopWebpSupport(runtimeSource) },
376
+ capabilities: { webp: deriveDesktopWebpSupport(runtimeSource, runtimeExecutable) },
204
377
  });
205
- for (const entry of readdirSync(assets)) {
206
- if (entry === '.threenative') {
207
- throw new Error('TN_NATIVE_ASSET_RESERVED_PATH: public/.threenative is reserved.');
208
- }
209
- cpSync(join(assets, entry), join(staging, entry), { recursive: true });
378
+ if (existsSync(join(assets, '.threenative'))) {
379
+ throw new Error('TN_NATIVE_ASSET_RESERVED_PATH: public/.threenative is reserved.');
380
+ }
381
+ const { selected } = selectManifestAssets(assets);
382
+ for (const file of selected) {
383
+ const output = join(staging, file);
384
+ mkdirSync(dirname(output), { recursive: true });
385
+ copyFileSync(join(assets, file), output);
210
386
  }
211
387
  }
212
388
  const entry = join(staging, '.threenative', 'game.js');
@@ -14,14 +14,20 @@ import {
14
14
  writeFileSync,
15
15
  } from 'node:fs';
16
16
  import { tmpdir } from 'node:os';
17
- import { basename, dirname, join, posix, resolve } from 'node:path';
17
+ import { basename, dirname, join, resolve } from 'node:path';
18
18
  import { fileURLToPath } from 'node:url';
19
+ import { createRequire } from 'node:module';
19
20
  import { spawnSync } from 'node:child_process';
20
21
  import { assertNativeAssetsDecodable, deriveIosWebpSupport } from './asset-preflight.mjs';
22
+ import { listFiles, selectManifestAssets } from './asset-manifest.mjs';
21
23
  import { downloadReleaseArtifact } from './install-prebuilt.mjs';
22
- import { PNG } from 'pngjs';
23
24
 
24
25
  export const NATIVE_ORIENTATIONS = ['landscape', 'portrait', 'sensor'];
26
+ /**
27
+ * The iOS-only SDL3 version. Upstream 3.4.16 owns the UIWindowScene lifecycle via its
28
+ * built-in SDLUIKitSceneDelegate (TN3187 opt-in); desktop and Android stay on 3.2.30.
29
+ */
30
+ export const SDL3_IOS_VERSION = '3.4.16';
25
31
  export const DEFAULT_IOS_CONFIG = {
26
32
  app: { id: 'com.threenative.game', name: 'ThreeNative', version: '0.1.13', build: 1 },
27
33
  display: { orientation: 'landscape', fullscreen: true, keepScreenOn: false, maxFps: 60 },
@@ -45,6 +51,10 @@ function configValue(value, orientation) {
45
51
  const display = source.display && typeof source.display === 'object' ? source.display : {};
46
52
  const window = source.window && typeof source.window === 'object' ? source.window : {};
47
53
  const bootSplash = source.bootSplash && typeof source.bootSplash === 'object' ? source.bootSplash : {};
54
+ const renderer = source.ui === undefined ? 'native' : source.ui?.renderer;
55
+ if (renderer !== 'web' && renderer !== 'native') {
56
+ throw new Error('TN_UI_RENDERER_INVALID: ui.renderer must be web or native.');
57
+ }
48
58
  return {
49
59
  app: { ...DEFAULT_IOS_CONFIG.app, ...app },
50
60
  display: {
@@ -53,6 +63,7 @@ function configValue(value, orientation) {
53
63
  orientation: orientation ?? display.orientation ?? DEFAULT_IOS_CONFIG.display.orientation,
54
64
  },
55
65
  window: { ...DEFAULT_IOS_CONFIG.window, ...window },
66
+ ui: { renderer },
56
67
  ...(source.bootSplash === undefined ? {} : { bootSplash: { ...bootSplash } }),
57
68
  };
58
69
  }
@@ -118,9 +129,10 @@ function plistInteger(source, key, value) {
118
129
 
119
130
  function plistLaunchScreen(source, config) {
120
131
  const image = config.bootSplash?.image === undefined ? undefined : 'LaunchImage';
132
+ const icon = config.app.icon ?? config.app.icons?.ios?.dark ?? config.app.icons?.ios?.tinted;
133
+ const hasCatalog = icon !== undefined || config.bootSplash !== undefined;
121
134
  const inner = [
122
- ' <key>UIColorName</key>',
123
- ' <string>TNLaunchBackground</string>',
135
+ ...(hasCatalog ? [' <key>UIColorName</key>', ' <string>LaunchBackground</string>'] : []),
124
136
  ...(image === undefined ? [] : [' <key>UIImageName</key>', ` <string>${image}</string>`]),
125
137
  ].join('\n');
126
138
  const rendered = ` <key>UILaunchScreen</key>\n <dict>\n${inner}\n </dict>`;
@@ -130,6 +142,21 @@ function plistLaunchScreen(source, config) {
130
142
  : source.replace(/\s*<\/dict>\s*<\/plist>/u, `\n${rendered}\n</dict>\n</plist>`);
131
143
  }
132
144
 
145
+ /**
146
+ * Legacy generated-host detection for the TN3187 scene opt-in: the Info.plist
147
+ * template must carry the manifest key opening a dict AND the delegate
148
+ * assignment naming SDLUIKitSceneDelegate. XML comments are stripped first so a
149
+ * commented-out pair cannot pass. Field markers only, not an XML structure
150
+ * validator: no nesting proof (manifest → configuration → delegate), and a pass
151
+ * never qualifies an arbitrary plist for Apple launch — real UIKit execution on
152
+ * device/simulator remains required.
153
+ */
154
+ export function hasIosSceneManifestFields(source) {
155
+ const text = String(source ?? '').replace(/<!--[\s\S]*?-->/gu, '');
156
+ return /<key>UIApplicationSceneManifest<\/key>\s*<dict>/u.test(text) &&
157
+ /<key>UISceneDelegateClassName<\/key>\s*<string>SDLUIKitSceneDelegate<\/string>/u.test(text);
158
+ }
159
+
133
160
  function orientationValue(value = 'landscape') {
134
161
  if (typeof value === 'string' && NATIVE_ORIENTATIONS.includes(value)) return value;
135
162
  throw new Error(
@@ -156,11 +183,13 @@ export function renderIosInfoPlist(source, orientation = 'landscape') {
156
183
  rendered = plistBoolean(rendered, 'TNFullscreen', config.display.fullscreen);
157
184
  rendered = plistBoolean(rendered, 'TNKeepScreenOn', config.display.keepScreenOn);
158
185
  rendered = plistInteger(rendered, 'TNMaxFps', config.display.maxFps);
186
+ rendered = plistKey(rendered, 'TNUIRenderer', config.ui.renderer);
159
187
  rendered = plistKey(rendered, 'TNWindowTitle', config.window.title);
160
188
  rendered = plistInteger(rendered, 'TNWindowWidth', config.window.width);
161
189
  rendered = plistInteger(rendered, 'TNWindowHeight', config.window.height);
162
190
  rendered = plistBoolean(rendered, 'TNWindowResizable', config.window.resizable);
163
- if (config.app.icon !== undefined || config.app.icons?.ios !== undefined) {
191
+ const launchIcon = config.app.icon ?? config.app.icons?.ios?.dark ?? config.app.icons?.ios?.tinted;
192
+ if (launchIcon !== undefined) {
164
193
  rendered = plistKey(rendered, 'CFBundleIconName', 'AppIcon');
165
194
  }
166
195
  return plistLaunchScreen(rendered, config);
@@ -182,17 +211,6 @@ function checksum(path) {
182
211
  return createHash('sha256').update(readFileSync(path)).digest('hex');
183
212
  }
184
213
 
185
- function listFiles(directory, relative = '') {
186
- const files = [];
187
- for (const entry of readdirSync(join(directory, relative), { withFileTypes: true })) {
188
- const path = relative ? posix.join(relative, entry.name) : entry.name;
189
- if (entry.isDirectory()) files.push(...listFiles(directory, path));
190
- else if (entry.isFile()) files.push(path);
191
- else throw new Error(`Unsupported iOS asset entry: ${join(directory, path)}`);
192
- }
193
- return files.sort();
194
- }
195
-
196
214
  function findApp(directory) {
197
215
  const entries = readdirSync(directory, { withFileTypes: true });
198
216
  for (const entry of entries) {
@@ -246,6 +264,9 @@ function compileIosIcon(catalog, output) {
246
264
  }
247
265
 
248
266
  function assertIosIconSource(icon, label) {
267
+ // Loaded lazily so importing this module (e.g. download-deps.mjs reading SDL3_IOS_VERSION)
268
+ // does not require node_modules; the check still runs synchronously when it is reached.
269
+ const { PNG } = createRequire(import.meta.url)('pngjs');
249
270
  let image;
250
271
  try {
251
272
  image = PNG.sync.read(readFileSync(icon));
@@ -264,9 +285,9 @@ function assertIosIconSource(icon, label) {
264
285
  function colorComponents(value) {
265
286
  const hex = /^#([0-9a-f]{6})$/iu.exec(value ?? '')?.[1] ?? '000000';
266
287
  return {
267
- blue: hex.slice(4, 6),
268
- green: hex.slice(2, 4),
269
- red: hex.slice(0, 2),
288
+ blue: Number.parseInt(hex.slice(4, 6), 16) / 255,
289
+ green: Number.parseInt(hex.slice(2, 4), 16) / 255,
290
+ red: Number.parseInt(hex.slice(0, 2), 16) / 255,
270
291
  };
271
292
  }
272
293
 
@@ -282,7 +303,7 @@ function writeLaunchColor(catalog, value) {
282
303
  {
283
304
  color: {
284
305
  'color-space': 'srgb',
285
- components: { alpha: '1.000', ...components },
306
+ components: { alpha: 1, ...components },
286
307
  },
287
308
  idiom: 'universal',
288
309
  },
@@ -394,7 +415,7 @@ function stageIosLaunchAssets(output, backgroundColor, compileAssets = compileIo
394
415
  * game with no built UI would launch and show nothing over a working game, and a `native` game must
395
416
  * carry no bundle at all.
396
417
  *
397
- * **The iOS host that would read this has never run.** See `ios/ui_overlay_ios.mm`.
418
+ * Native-only simulator smoke does not qualify WebUI. See the packaged React pixel proof.
398
419
  */
399
420
  export function stageIosUi(ui, renderer, destination) {
400
421
  rmSync(destination, { force: true, recursive: true });
@@ -424,6 +445,33 @@ export function stageIosUi(ui, renderer, destination) {
424
445
  return listFiles(destination);
425
446
  }
426
447
 
448
+ /**
449
+ * Stage the game's compiled assets into the `.app`'s `game` directory.
450
+ *
451
+ * The same selector the other two packagers use, so one cook output left over from a previous
452
+ * bake is dropped here too instead of shipping inside the bundle. iOS ran no preflight at all.
453
+ * Its capability set is not Android's: `CMakeLists.txt` excludes IOS from every libwebp branch,
454
+ * so a WebP texture that packages for Android must still be refused here, while the audio answer
455
+ * is the same on every native target.
456
+ */
457
+ export function stageIosAssets(assets, destination) {
458
+ if (!assets || !existsSync(assets)) return [];
459
+ if (!statSync(assets).isDirectory()) {
460
+ throw new Error(`iOS assets path is not a directory: ${assets}`);
461
+ }
462
+ assertNativeAssetsDecodable(assets, {
463
+ target: 'ios',
464
+ capabilities: { webp: deriveIosWebpSupport() },
465
+ });
466
+ const { selected } = selectManifestAssets(assets);
467
+ for (const file of selected) {
468
+ const staged = join(destination, file);
469
+ mkdirSync(dirname(staged), { recursive: true });
470
+ cpSync(join(assets, file), staged);
471
+ }
472
+ return selected;
473
+ }
474
+
427
475
  export function stageIosSimulatorApp({
428
476
  assets,
429
477
  bundle,
@@ -449,6 +497,15 @@ export function stageIosSimulatorApp({
449
497
  throw new Error(`Verified iOS simulator host is missing ${required}.`);
450
498
  }
451
499
  }
500
+ // An old prebuilt archive predates the TN3187 scene opt-in and would ship a non-launching
501
+ // app. Fail closed with the matching-runtime fix instead of silently packaging it: the
502
+ // release lane must rebuild the ios-simulator-arm64 archive from SDL 3.4.16.
503
+ const templatePlist = readIosInfoPlist(join(templateApp, 'Info.plist'), convertInfoPlist);
504
+ if (!hasIosSceneManifestFields(templatePlist.source)) {
505
+ throw new Error(
506
+ 'TN_IOS_SCENE_MANIFEST_MISSING: simulator host predates the UIScene adoption; rebuild the ios-simulator-arm64 archive from the matching runtime (SDL 3.4.16) before packaging.',
507
+ );
508
+ }
452
509
  rmSync(output, { force: true, recursive: true });
453
510
  mkdirSync(dirname(output), { recursive: true });
454
511
  cpSync(templateApp, output, { recursive: true });
@@ -480,25 +537,7 @@ export function stageIosSimulatorApp({
480
537
  }
481
538
  copyFileSync(declared.bootSplash.image, join(output, 'LaunchImage.png'));
482
539
  }
483
- let assetFiles = [];
484
- if (assets && existsSync(assets)) {
485
- if (!statSync(assets).isDirectory()) {
486
- throw new Error(`iOS assets path is not a directory: ${assets}`);
487
- }
488
- // iOS ran no preflight at all. Its capability set is not Android's: `CMakeLists.txt` excludes
489
- // IOS from every libwebp branch, so a WebP texture that packages for Android must still be
490
- // refused here, while the audio answer is the same on every native target.
491
- assertNativeAssetsDecodable(assets, {
492
- target: 'ios',
493
- capabilities: { webp: deriveIosWebpSupport() },
494
- });
495
- assetFiles = listFiles(assets);
496
- for (const file of assetFiles) {
497
- const staged = join(game, file);
498
- mkdirSync(dirname(staged), { recursive: true });
499
- cpSync(join(assets, file), staged);
500
- }
501
- }
540
+ const assetFiles = stageIosAssets(assets, game);
502
541
  const report = {
503
542
  assets: assetFiles.map((path) => ({ path, sha256: checksum(join(game, path)) })),
504
543
  bundleSha256: checksum(bundle),
@@ -512,7 +551,9 @@ export function stageIosSimulatorApp({
512
551
  ...(icon === undefined ? {} : { icon }),
513
552
  ...(icon === undefined ? {} : { iconArtifact: 'Assets.car' }),
514
553
  ...(declared.bootSplash?.image === undefined ? {} : { launchImage: 'LaunchImage.png' }),
515
- launchBackground: declared.bootSplash?.backgroundColor ?? '#000000',
554
+ ...(icon === undefined && declared.bootSplash === undefined
555
+ ? {}
556
+ : { launchBackground: declared.bootSplash?.backgroundColor ?? '#000000' }),
516
557
  output,
517
558
  outputBundleSha256: checksum(join(output, 'native-smoke.js')),
518
559
  };
@@ -565,6 +606,7 @@ export async function packageIosSimulator(options) {
565
606
  return stageIosSimulatorApp({
566
607
  assets: options.assets ? resolve(options.assets) : undefined,
567
608
  bundle: resolve(options.bundle),
609
+ ui: options.ui === undefined ? undefined : resolve(options.ui),
568
610
  output: resolve(options.output),
569
611
  templateApp,
570
612
  orientation,