@threenative/runtime-native 0.3.1 → 0.3.3

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');
@@ -16,12 +16,17 @@ import {
16
16
  import { tmpdir } from 'node:os';
17
17
  import { basename, dirname, join, posix, 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';
21
22
  import { downloadReleaseArtifact } from './install-prebuilt.mjs';
22
- import { PNG } from 'pngjs';
23
23
 
24
24
  export const NATIVE_ORIENTATIONS = ['landscape', 'portrait', 'sensor'];
25
+ /**
26
+ * The iOS-only SDL3 version. Upstream 3.4.16 owns the UIWindowScene lifecycle via its
27
+ * built-in SDLUIKitSceneDelegate (TN3187 opt-in); desktop and Android stay on 3.2.30.
28
+ */
29
+ export const SDL3_IOS_VERSION = '3.4.16';
25
30
  export const DEFAULT_IOS_CONFIG = {
26
31
  app: { id: 'com.threenative.game', name: 'ThreeNative', version: '0.1.13', build: 1 },
27
32
  display: { orientation: 'landscape', fullscreen: true, keepScreenOn: false, maxFps: 60 },
@@ -45,6 +50,10 @@ function configValue(value, orientation) {
45
50
  const display = source.display && typeof source.display === 'object' ? source.display : {};
46
51
  const window = source.window && typeof source.window === 'object' ? source.window : {};
47
52
  const bootSplash = source.bootSplash && typeof source.bootSplash === 'object' ? source.bootSplash : {};
53
+ const renderer = source.ui === undefined ? 'native' : source.ui?.renderer;
54
+ if (renderer !== 'web' && renderer !== 'native') {
55
+ throw new Error('TN_UI_RENDERER_INVALID: ui.renderer must be web or native.');
56
+ }
48
57
  return {
49
58
  app: { ...DEFAULT_IOS_CONFIG.app, ...app },
50
59
  display: {
@@ -53,6 +62,7 @@ function configValue(value, orientation) {
53
62
  orientation: orientation ?? display.orientation ?? DEFAULT_IOS_CONFIG.display.orientation,
54
63
  },
55
64
  window: { ...DEFAULT_IOS_CONFIG.window, ...window },
65
+ ui: { renderer },
56
66
  ...(source.bootSplash === undefined ? {} : { bootSplash: { ...bootSplash } }),
57
67
  };
58
68
  }
@@ -118,9 +128,10 @@ function plistInteger(source, key, value) {
118
128
 
119
129
  function plistLaunchScreen(source, config) {
120
130
  const image = config.bootSplash?.image === undefined ? undefined : 'LaunchImage';
131
+ const icon = config.app.icon ?? config.app.icons?.ios?.dark ?? config.app.icons?.ios?.tinted;
132
+ const hasCatalog = icon !== undefined || config.bootSplash !== undefined;
121
133
  const inner = [
122
- ' <key>UIColorName</key>',
123
- ' <string>TNLaunchBackground</string>',
134
+ ...(hasCatalog ? [' <key>UIColorName</key>', ' <string>LaunchBackground</string>'] : []),
124
135
  ...(image === undefined ? [] : [' <key>UIImageName</key>', ` <string>${image}</string>`]),
125
136
  ].join('\n');
126
137
  const rendered = ` <key>UILaunchScreen</key>\n <dict>\n${inner}\n </dict>`;
@@ -130,6 +141,21 @@ function plistLaunchScreen(source, config) {
130
141
  : source.replace(/\s*<\/dict>\s*<\/plist>/u, `\n${rendered}\n</dict>\n</plist>`);
131
142
  }
132
143
 
144
+ /**
145
+ * Legacy generated-host detection for the TN3187 scene opt-in: the Info.plist
146
+ * template must carry the manifest key opening a dict AND the delegate
147
+ * assignment naming SDLUIKitSceneDelegate. XML comments are stripped first so a
148
+ * commented-out pair cannot pass. Field markers only, not an XML structure
149
+ * validator: no nesting proof (manifest → configuration → delegate), and a pass
150
+ * never qualifies an arbitrary plist for Apple launch — real UIKit execution on
151
+ * device/simulator remains required.
152
+ */
153
+ export function hasIosSceneManifestFields(source) {
154
+ const text = String(source ?? '').replace(/<!--[\s\S]*?-->/gu, '');
155
+ return /<key>UIApplicationSceneManifest<\/key>\s*<dict>/u.test(text) &&
156
+ /<key>UISceneDelegateClassName<\/key>\s*<string>SDLUIKitSceneDelegate<\/string>/u.test(text);
157
+ }
158
+
133
159
  function orientationValue(value = 'landscape') {
134
160
  if (typeof value === 'string' && NATIVE_ORIENTATIONS.includes(value)) return value;
135
161
  throw new Error(
@@ -156,11 +182,13 @@ export function renderIosInfoPlist(source, orientation = 'landscape') {
156
182
  rendered = plistBoolean(rendered, 'TNFullscreen', config.display.fullscreen);
157
183
  rendered = plistBoolean(rendered, 'TNKeepScreenOn', config.display.keepScreenOn);
158
184
  rendered = plistInteger(rendered, 'TNMaxFps', config.display.maxFps);
185
+ rendered = plistKey(rendered, 'TNUIRenderer', config.ui.renderer);
159
186
  rendered = plistKey(rendered, 'TNWindowTitle', config.window.title);
160
187
  rendered = plistInteger(rendered, 'TNWindowWidth', config.window.width);
161
188
  rendered = plistInteger(rendered, 'TNWindowHeight', config.window.height);
162
189
  rendered = plistBoolean(rendered, 'TNWindowResizable', config.window.resizable);
163
- if (config.app.icon !== undefined || config.app.icons?.ios !== undefined) {
190
+ const launchIcon = config.app.icon ?? config.app.icons?.ios?.dark ?? config.app.icons?.ios?.tinted;
191
+ if (launchIcon !== undefined) {
164
192
  rendered = plistKey(rendered, 'CFBundleIconName', 'AppIcon');
165
193
  }
166
194
  return plistLaunchScreen(rendered, config);
@@ -246,6 +274,9 @@ function compileIosIcon(catalog, output) {
246
274
  }
247
275
 
248
276
  function assertIosIconSource(icon, label) {
277
+ // Loaded lazily so importing this module (e.g. download-deps.mjs reading SDL3_IOS_VERSION)
278
+ // does not require node_modules; the check still runs synchronously when it is reached.
279
+ const { PNG } = createRequire(import.meta.url)('pngjs');
249
280
  let image;
250
281
  try {
251
282
  image = PNG.sync.read(readFileSync(icon));
@@ -264,9 +295,9 @@ function assertIosIconSource(icon, label) {
264
295
  function colorComponents(value) {
265
296
  const hex = /^#([0-9a-f]{6})$/iu.exec(value ?? '')?.[1] ?? '000000';
266
297
  return {
267
- blue: hex.slice(4, 6),
268
- green: hex.slice(2, 4),
269
- red: hex.slice(0, 2),
298
+ blue: Number.parseInt(hex.slice(4, 6), 16) / 255,
299
+ green: Number.parseInt(hex.slice(2, 4), 16) / 255,
300
+ red: Number.parseInt(hex.slice(0, 2), 16) / 255,
270
301
  };
271
302
  }
272
303
 
@@ -282,7 +313,7 @@ function writeLaunchColor(catalog, value) {
282
313
  {
283
314
  color: {
284
315
  'color-space': 'srgb',
285
- components: { alpha: '1.000', ...components },
316
+ components: { alpha: 1, ...components },
286
317
  },
287
318
  idiom: 'universal',
288
319
  },
@@ -394,7 +425,7 @@ function stageIosLaunchAssets(output, backgroundColor, compileAssets = compileIo
394
425
  * game with no built UI would launch and show nothing over a working game, and a `native` game must
395
426
  * carry no bundle at all.
396
427
  *
397
- * **The iOS host that would read this has never run.** See `ios/ui_overlay_ios.mm`.
428
+ * Native-only simulator smoke does not qualify WebUI. See the packaged React pixel proof.
398
429
  */
399
430
  export function stageIosUi(ui, renderer, destination) {
400
431
  rmSync(destination, { force: true, recursive: true });
@@ -449,6 +480,15 @@ export function stageIosSimulatorApp({
449
480
  throw new Error(`Verified iOS simulator host is missing ${required}.`);
450
481
  }
451
482
  }
483
+ // An old prebuilt archive predates the TN3187 scene opt-in and would ship a non-launching
484
+ // app. Fail closed with the matching-runtime fix instead of silently packaging it: the
485
+ // release lane must rebuild the ios-simulator-arm64 archive from SDL 3.4.16.
486
+ const templatePlist = readIosInfoPlist(join(templateApp, 'Info.plist'), convertInfoPlist);
487
+ if (!hasIosSceneManifestFields(templatePlist.source)) {
488
+ throw new Error(
489
+ '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.',
490
+ );
491
+ }
452
492
  rmSync(output, { force: true, recursive: true });
453
493
  mkdirSync(dirname(output), { recursive: true });
454
494
  cpSync(templateApp, output, { recursive: true });
@@ -512,7 +552,9 @@ export function stageIosSimulatorApp({
512
552
  ...(icon === undefined ? {} : { icon }),
513
553
  ...(icon === undefined ? {} : { iconArtifact: 'Assets.car' }),
514
554
  ...(declared.bootSplash?.image === undefined ? {} : { launchImage: 'LaunchImage.png' }),
515
- launchBackground: declared.bootSplash?.backgroundColor ?? '#000000',
555
+ ...(icon === undefined && declared.bootSplash === undefined
556
+ ? {}
557
+ : { launchBackground: declared.bootSplash?.backgroundColor ?? '#000000' }),
516
558
  output,
517
559
  outputBundleSha256: checksum(join(output, 'native-smoke.js')),
518
560
  };
@@ -565,6 +607,7 @@ export async function packageIosSimulator(options) {
565
607
  return stageIosSimulatorApp({
566
608
  assets: options.assets ? resolve(options.assets) : undefined,
567
609
  bundle: resolve(options.bundle),
610
+ ui: options.ui === undefined ? undefined : resolve(options.ui),
568
611
  output: resolve(options.output),
569
612
  templateApp,
570
613
  orientation,
@@ -332,9 +332,13 @@ function strictlyIncreasing(values) {
332
332
 
333
333
  function maximumMetric(metrics, key) {
334
334
  if (Array.isArray(metrics.intervals) && metrics.intervals.length > 0) {
335
- const values = metrics.intervals.map((sample) => sample?.[key]);
336
- if (values.some((value) => !finiteMetric(value))) return undefined;
337
- return Math.max(...values);
335
+ // The first frame of each collection window settles before the asynchronous renderer read
336
+ // resolves, so it carries no draw-call or triangle reading. Match the producer, which takes the
337
+ // maximum over the readings that exist; a series with no reading at all stays unmeasured.
338
+ const values = metrics.intervals
339
+ .map((sample) => sample?.[key])
340
+ .filter((value) => finiteMetric(value));
341
+ return values.length > 0 ? Math.max(...values) : undefined;
338
342
  }
339
343
  return finiteMetric(metrics[key]) ? metrics[key] : undefined;
340
344
  }