@threenative/runtime-native 0.3.0 → 0.3.2
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.
- package/NOTICE +2 -0
- package/android/app/build.gradle.kts +11 -1
- package/android/app/src/main/java/com/mystral/engine/MystralActivity.java +11 -0
- package/android/gradle.properties +1 -1
- package/package.json +27 -4
- package/scripts/bundle.mjs +13 -6
- package/scripts/check-source-list.mjs +90 -0
- package/scripts/install-prebuilt.mjs +323 -50
- package/scripts/package-android.mjs +26 -15
- package/scripts/package-desktop.mjs +50 -7
- package/scripts/package-ios.mjs +45 -4
- package/scripts/physical-device-evidence.mjs +1 -1
- package/scripts/production-evidence.mjs +101 -2
- package/scripts/profile-production.mjs +490 -92
- package/scripts/verify-starter-desktop.mjs +134 -13
- package/scripts/xvfb.sh +7 -2
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { createHash } from 'node:crypto';
|
|
4
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
4
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
7
|
|
|
@@ -9,29 +9,69 @@ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
|
9
9
|
const packageVersion = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8')).version;
|
|
10
10
|
export const RELEASE_REPOSITORY = 'ThreeNativeHQ/threenative';
|
|
11
11
|
|
|
12
|
+
/** Every asset a packaged consumer or native release workflow may request. */
|
|
13
|
+
export const PREBUILT_ASSET_NAMES = Object.freeze({
|
|
14
|
+
'android-arm64-v8a-runtime': 'threenative-runtime-android-arm64-v8a.so',
|
|
15
|
+
'android-arm64-v8a-runtime-v8': 'threenative-runtime-android-arm64-v8a-v8.so',
|
|
16
|
+
'android-arm64-v8a-sdl3': 'threenative-sdl3-android-arm64-v8a.so',
|
|
17
|
+
'android-arm64-v8a-v8': 'threenative-v8-android-arm64-v8a.so',
|
|
18
|
+
'android-arm64-v8a-libcxx': 'threenative-libcxx-android-arm64-v8a.so',
|
|
19
|
+
'android-arm64-v8a-v8-snapshot': 'threenative-v8-snapshot-android-arm64-v8a.bin',
|
|
20
|
+
'android-sdl3-aar': 'threenative-sdl3-android.aar',
|
|
21
|
+
'android-x86_64-runtime': 'threenative-runtime-android-x86_64.so',
|
|
22
|
+
'android-x86_64-runtime-v8': 'threenative-runtime-android-x86_64-v8.so',
|
|
23
|
+
'android-x86_64-sdl3': 'threenative-sdl3-android-x86_64.so',
|
|
24
|
+
'android-x86_64-v8': 'threenative-v8-android-x86_64.so',
|
|
25
|
+
'android-x86_64-libcxx': 'threenative-libcxx-android-x86_64.so',
|
|
26
|
+
'android-x86_64-v8-snapshot': 'threenative-v8-snapshot-android-x86_64.bin',
|
|
27
|
+
'darwin-arm64': 'threenative-runtime-darwin-arm64',
|
|
28
|
+
'darwin-arm64-tools': 'threenative-tools-darwin-arm64',
|
|
29
|
+
'ios-simulator-arm64': 'threenative-ios-simulator-arm64.zip',
|
|
30
|
+
'linux-x64': 'threenative-runtime-linux-x64',
|
|
31
|
+
'linux-x64-tools': 'threenative-tools-linux-x64',
|
|
32
|
+
'win32-x64': 'threenative-runtime-win32-x64.exe',
|
|
33
|
+
'win32-x64-tools': 'threenative-tools-win32-x64.exe',
|
|
34
|
+
});
|
|
35
|
+
|
|
12
36
|
/** Every key a packaged consumer or native release workflow may request. */
|
|
13
|
-
export const PREBUILT_KEYS = Object.freeze(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
export const PREBUILT_KEYS = Object.freeze(Object.keys(PREBUILT_ASSET_NAMES));
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Rows this repository builds and verifies on every release run but does not publish.
|
|
41
|
+
*
|
|
42
|
+
* Only macOS. Gatekeeper hard-refuses an unsigned, un-notarized bundle downloaded from the web, so
|
|
43
|
+
* a macOS asset without an Apple Developer Program identity is not a shippable artifact — it is a
|
|
44
|
+
* support ticket. Windows is different: an unsigned executable runs, SmartScreen only warns, so
|
|
45
|
+
* `win32-x64` ships unsigned rather than waiting on a certificate.
|
|
46
|
+
*
|
|
47
|
+
* The row keeps building and verifying on every release run — a row that stops compiling rots
|
|
48
|
+
* silently — it is simply not advertised as downloadable, which is the narrowing PRD-262 allows in
|
|
49
|
+
* place of building every claimed row. Publishing it again is one entry, once the Apple identity
|
|
50
|
+
* exists. Status and cost of every platform's signing inputs: `docs/RELEASE-SIGNING.md`.
|
|
51
|
+
*/
|
|
52
|
+
export const UNPUBLISHED_PREBUILT_KEYS = Object.freeze(['darwin-arm64', 'darwin-arm64-tools']);
|
|
53
|
+
|
|
54
|
+
/** The exact cohort a release publishes and a consumer may download. */
|
|
55
|
+
export const PUBLISHED_PREBUILT_KEYS = Object.freeze(
|
|
56
|
+
PREBUILT_KEYS.filter((key) => !UNPUBLISHED_PREBUILT_KEYS.includes(key)),
|
|
57
|
+
);
|
|
32
58
|
|
|
33
59
|
const supported = new Set(['darwin-arm64', 'linux-x64', 'win32-x64']);
|
|
34
60
|
|
|
61
|
+
/**
|
|
62
|
+
* The desktop runtime dispatches `threenative build --target desktop` to a `mystral-tools` helper
|
|
63
|
+
* sitting beside its own executable (`src/cli/tool_dispatch.cpp:52`). A consumer that installs only
|
|
64
|
+
* the runtime gets `build tool helper is missing` and exit 127, so the helper is a published
|
|
65
|
+
* release asset of its own and is installed beside the runtime by the same atomic install.
|
|
66
|
+
*/
|
|
67
|
+
export function toolsKey(key) {
|
|
68
|
+
return supported.has(key) ? `${key}-tools` : undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function toolsFilename(platform = process.platform) {
|
|
72
|
+
return platform === 'win32' ? 'mystral-tools.exe' : 'mystral-tools';
|
|
73
|
+
}
|
|
74
|
+
|
|
35
75
|
export function platformKey(platform = process.platform, arch = process.arch) {
|
|
36
76
|
const key = `${platform}-${arch}`;
|
|
37
77
|
if (!supported.has(key)) throw new Error(`Unsupported native runtime platform '${key}'.`);
|
|
@@ -50,10 +90,20 @@ export function verifyChecksum(contents, expected, key) {
|
|
|
50
90
|
}
|
|
51
91
|
|
|
52
92
|
function releaseFromManifest(manifest, key) {
|
|
53
|
-
|
|
93
|
+
if (UNPUBLISHED_PREBUILT_KEYS.includes(key)) {
|
|
94
|
+
const error = new Error(
|
|
95
|
+
`No prebuilt release is published for '${key}'. This platform builds from an engine checkout until its release credentials exist; see PRD-262.`,
|
|
96
|
+
);
|
|
97
|
+
error.code = 'PREBUILT_RELEASE_UNPUBLISHED';
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
const release = manifest?.artifacts?.[key];
|
|
54
101
|
if (!release?.url || !release?.sha256) {
|
|
55
102
|
throw new Error(`No prebuilt release asset is recorded for '${key}'.`);
|
|
56
103
|
}
|
|
104
|
+
if (typeof release.sha256 !== 'string' || !/^[a-f0-9]{64}$/u.test(release.sha256)) {
|
|
105
|
+
throw new Error(`Invalid prebuilt SHA-256 for '${key}'.`);
|
|
106
|
+
}
|
|
57
107
|
const url = new URL(release.url);
|
|
58
108
|
if (url.protocol !== 'https:' && process.env.THREENATIVE_ALLOW_INSECURE_PREBUILT !== '1') {
|
|
59
109
|
throw new Error(`Prebuilt release URL for '${key}' must use HTTPS.`);
|
|
@@ -61,23 +111,211 @@ function releaseFromManifest(manifest, key) {
|
|
|
61
111
|
return release;
|
|
62
112
|
}
|
|
63
113
|
|
|
114
|
+
function isLoopbackFixture(url) {
|
|
115
|
+
return process.env.THREENATIVE_ALLOW_INSECURE_PREBUILT === '1' &&
|
|
116
|
+
url.protocol === 'http:' && ['127.0.0.1', '[::1]', 'localhost'].includes(url.hostname) &&
|
|
117
|
+
!url.username && !url.password;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The keys a manifest declares it advertises.
|
|
122
|
+
*
|
|
123
|
+
* A manifest may carry `requiredKeys`; absent, the strict full-cohort default below is unchanged, so
|
|
124
|
+
* the official CI release keeps its guarantee. A scoped manifest is how a local release states which
|
|
125
|
+
* of the platform matrices this host actually built, without claiming the rest.
|
|
126
|
+
*/
|
|
127
|
+
function declaredRequiredKeys(manifest) {
|
|
128
|
+
if (manifest.requiredKeys === undefined) return undefined;
|
|
129
|
+
if (!Array.isArray(manifest.requiredKeys) || manifest.requiredKeys.length === 0 ||
|
|
130
|
+
manifest.requiredKeys.some((key) => typeof key !== 'string')) {
|
|
131
|
+
throw new Error('Prebuilt manifest requiredKeys must be a non-empty array of prebuilt release keys.');
|
|
132
|
+
}
|
|
133
|
+
for (const key of manifest.requiredKeys) {
|
|
134
|
+
if (!Object.hasOwn(PREBUILT_ASSET_NAMES, key)) {
|
|
135
|
+
throw new Error(`Unknown prebuilt release key '${key}' in manifest requiredKeys.`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return manifest.requiredKeys;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function validateManifestEnvelope(manifest, options) {
|
|
142
|
+
if (manifest?.schemaVersion !== 1) throw new Error('Unsupported or missing prebuilt manifest schemaVersion.');
|
|
143
|
+
const version = options.version ?? packageVersion;
|
|
144
|
+
if (manifest.version !== version) {
|
|
145
|
+
throw new Error(`Prebuilt manifest version mismatch: expected ${version}, received ${manifest.version}.`);
|
|
146
|
+
}
|
|
147
|
+
if (typeof manifest.sourceSha !== 'string' || !/^[a-f0-9]{40}$/u.test(manifest.sourceSha)) {
|
|
148
|
+
throw new Error('Prebuilt manifest must record a full source SHA.');
|
|
149
|
+
}
|
|
150
|
+
if (options.sourceSha !== undefined && manifest.sourceSha !== options.sourceSha) {
|
|
151
|
+
throw new Error(`Prebuilt source SHA mismatch: expected ${options.sourceSha}, received ${manifest.sourceSha}.`);
|
|
152
|
+
}
|
|
153
|
+
declaredRequiredKeys(manifest);
|
|
154
|
+
if (!manifest.artifacts || typeof manifest.artifacts !== 'object' || Array.isArray(manifest.artifacts)) {
|
|
155
|
+
throw new Error('Prebuilt manifest artifacts must be an object.');
|
|
156
|
+
}
|
|
157
|
+
return version;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function validateManifestArtifact(manifest, key, version) {
|
|
161
|
+
if (!Object.hasOwn(PREBUILT_ASSET_NAMES, key)) throw new Error(`Unknown prebuilt release key '${key}'.`);
|
|
162
|
+
const release = releaseFromManifest(manifest, key);
|
|
163
|
+
if (!Number.isSafeInteger(release.size) || release.size <= 0) {
|
|
164
|
+
throw new Error(`Prebuilt release size for '${key}' must be a positive integer.`);
|
|
165
|
+
}
|
|
166
|
+
const expectedUrl = `${releaseManifestUrl(version).replace('/prebuilt-lock.json', '')}/${PREBUILT_ASSET_NAMES[key]}`;
|
|
167
|
+
const url = new URL(release.url);
|
|
168
|
+
if (release.url !== expectedUrl && !isLoopbackFixture(url)) {
|
|
169
|
+
throw new Error(`Prebuilt release URL for '${key}' must match version ${version}: ${expectedUrl}.`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Validate the entire advertised cohort before selecting even one consumer artifact. */
|
|
174
|
+
export function validateReleaseManifest(manifest, options = {}) {
|
|
175
|
+
const version = validateManifestEnvelope(manifest, options);
|
|
176
|
+
// A caller's explicit scope wins; then the manifest's own advertised keys; then the strict
|
|
177
|
+
// non-iOS cohort. iOS retains its separate release gate, so it is not a prerequisite for a
|
|
178
|
+
// non-iOS consumer, and a scoped local manifest is accepted for exactly the keys it names.
|
|
179
|
+
const requiredKeys = options.requiredKeys ?? declaredRequiredKeys(manifest) ??
|
|
180
|
+
PUBLISHED_PREBUILT_KEYS.filter((key) => !key.startsWith('ios-'));
|
|
181
|
+
for (const key of requiredKeys) releaseFromManifest(manifest, key);
|
|
182
|
+
for (const key of Object.keys(manifest.artifacts)) validateManifestArtifact(manifest, key, version);
|
|
183
|
+
return manifest;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The release workflow uses this same validator, including its existing iOS requirement.
|
|
188
|
+
*
|
|
189
|
+
* `keys` narrows the matrix to the artifacts this caller staged: the lock then advertises exactly
|
|
190
|
+
* those keys (`requiredKeys`) and refuses if one is missing from the directory. Omitted, the full
|
|
191
|
+
* published matrix is required and the lock carries no `requiredKeys`, so every consumer keeps the
|
|
192
|
+
* strict default.
|
|
193
|
+
*/
|
|
194
|
+
export function generateReleaseManifest(directory, { repository, tag, sourceSha, keys }) {
|
|
195
|
+
if (repository !== RELEASE_REPOSITORY) {
|
|
196
|
+
throw new Error(`Prebuilt releases must be published by ${RELEASE_REPOSITORY}, received ${repository}.`);
|
|
197
|
+
}
|
|
198
|
+
if (tag !== releaseTag()) {
|
|
199
|
+
throw new Error(`Prebuilt release tag must be ${releaseTag()}, received ${tag}.`);
|
|
200
|
+
}
|
|
201
|
+
const selectedKeys = keys === undefined ? [...PUBLISHED_PREBUILT_KEYS] : keys;
|
|
202
|
+
if (!Array.isArray(selectedKeys) || selectedKeys.length === 0) {
|
|
203
|
+
throw new Error('Prebuilt release keys must be a non-empty array.');
|
|
204
|
+
}
|
|
205
|
+
const published = selectedKeys.map((key) => {
|
|
206
|
+
if (!Object.hasOwn(PREBUILT_ASSET_NAMES, key)) throw new Error(`Unknown prebuilt release key '${key}'.`);
|
|
207
|
+
return [key, PREBUILT_ASSET_NAMES[key]];
|
|
208
|
+
});
|
|
209
|
+
const expected = published.map(([, name]) => name).sort();
|
|
210
|
+
const actual = readdirSync(directory).sort();
|
|
211
|
+
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
212
|
+
throw new Error(`Incomplete prebuilt release matrix: expected ${expected.join(', ')}; received ${actual.join(', ')}.`);
|
|
213
|
+
}
|
|
214
|
+
const artifacts = Object.fromEntries(published.map(([key, name]) => {
|
|
215
|
+
const contents = readFileSync(join(directory, name));
|
|
216
|
+
if (contents.length === 0) throw new Error(`Prebuilt release asset '${key}' is empty.`);
|
|
217
|
+
return [key, { sha256: sha256(contents), size: contents.length,
|
|
218
|
+
url: `${releaseManifestUrl().replace('/prebuilt-lock.json', '')}/${name}` }];
|
|
219
|
+
}));
|
|
220
|
+
return validateReleaseManifest(
|
|
221
|
+
{ schemaVersion: 1, version: packageVersion, sourceSha, artifacts,
|
|
222
|
+
...(keys === undefined ? {} : { requiredKeys: [...selectedKeys] }) },
|
|
223
|
+
{ sourceSha, requiredKeys: selectedKeys },
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
64
227
|
export function readRelease(manifestPath, key) {
|
|
65
228
|
if (!existsSync(manifestPath)) {
|
|
66
229
|
const error = new Error(`No prebuilt release manifest exists for '${key}'; this target remains OPEN.`);
|
|
67
230
|
error.code = 'PREBUILT_RELEASE_MISSING';
|
|
68
231
|
throw error;
|
|
69
232
|
}
|
|
70
|
-
|
|
233
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
234
|
+
// Explicit artifact-only local pins predate the envelope. Never downgrade a partially
|
|
235
|
+
// specified candidate, and never allow this compatibility path for a remote default lock.
|
|
236
|
+
if (manifest && ['schemaVersion', 'version', 'sourceSha'].some((field) => Object.hasOwn(manifest, field))) {
|
|
237
|
+
validateReleaseManifest(manifest);
|
|
238
|
+
}
|
|
239
|
+
return releaseFromManifest(manifest, key);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** The GitHub release tag a version's prebuilt payload is published under. */
|
|
243
|
+
export function releaseTag(version = packageVersion) {
|
|
244
|
+
return `runtime-native-v${version}`;
|
|
71
245
|
}
|
|
72
246
|
|
|
73
247
|
export function releaseManifestUrl(version = packageVersion) {
|
|
74
|
-
return `https://github.com/${RELEASE_REPOSITORY}/releases/download
|
|
248
|
+
return `https://github.com/${RELEASE_REPOSITORY}/releases/download/${releaseTag(version)}/prebuilt-lock.json`;
|
|
75
249
|
}
|
|
76
250
|
|
|
77
251
|
export function writeInstallStatus(status, statusPath = join(packageRoot, 'prebuilt', 'install-status.json')) {
|
|
78
252
|
mkdirSync(dirname(statusPath), { recursive: true });
|
|
79
|
-
|
|
80
|
-
|
|
253
|
+
const temporary = `${statusPath}.${randomUUID()}.tmp`;
|
|
254
|
+
try {
|
|
255
|
+
writeFileSync(temporary, `${JSON.stringify(status, null, 2)}\n`, { flag: 'wx' });
|
|
256
|
+
renameSync(temporary, statusPath);
|
|
257
|
+
return statusPath;
|
|
258
|
+
} finally {
|
|
259
|
+
rmSync(temporary, { force: true });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function createInstallPlan(options) {
|
|
264
|
+
const platform = options.platform ?? process.platform;
|
|
265
|
+
const key = `${platform}-${options.arch ?? process.arch}`;
|
|
266
|
+
const filename = platform === 'win32' ? 'threenative-runtime.exe' : 'threenative-runtime';
|
|
267
|
+
const output = resolve(options.output ?? join(packageRoot, 'prebuilt', key, filename));
|
|
268
|
+
const statusPath = resolve(options.statusPath ?? (options.output
|
|
269
|
+
? join(dirname(output), 'install-status.json')
|
|
270
|
+
: join(packageRoot, 'prebuilt', 'install-status.json')));
|
|
271
|
+
if (output === statusPath) throw new Error('Prebuilt output and install status paths must differ.');
|
|
272
|
+
const toolsOutput = join(dirname(output), toolsFilename(platform));
|
|
273
|
+
if (toolsOutput === output) throw new Error('Prebuilt runtime and build tool helper paths must differ.');
|
|
274
|
+
return { platform, key, output, statusPath, toolsOutput, toolsKey: toolsKey(key),
|
|
275
|
+
status: { key, url: options.manifestPath ?? process.env.THREENATIVE_PREBUILT_MANIFEST ??
|
|
276
|
+
options.manifestUrl ?? releaseManifestUrl(), version: packageVersion } };
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function beginInstall(plan, arch) {
|
|
280
|
+
rmSync(plan.output, { force: true });
|
|
281
|
+
rmSync(plan.toolsOutput, { force: true });
|
|
282
|
+
rmSync(plan.statusPath, { force: true });
|
|
283
|
+
writeInstallStatus({ ...plan.status, ok: false, reason: 'installing' }, plan.statusPath);
|
|
284
|
+
platformKey(plan.platform, arch);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function publishBinary(target, contents, platform) {
|
|
288
|
+
const temporary = `${target}.${randomUUID()}.tmp`;
|
|
289
|
+
try {
|
|
290
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
291
|
+
writeFileSync(temporary, contents, { flag: 'wx' });
|
|
292
|
+
if (platform !== 'win32') chmodSync(temporary, 0o755);
|
|
293
|
+
renameSync(temporary, target);
|
|
294
|
+
} finally {
|
|
295
|
+
rmSync(temporary, { force: true });
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// The success marker is written only once both binaries are in place: a desktop build that finds
|
|
300
|
+
// the runtime but not the helper dies inside the packager with exit 127, which is exactly the
|
|
301
|
+
// stale-success shape this install exists to prevent.
|
|
302
|
+
function publishInstall(plan, contents, toolsContents) {
|
|
303
|
+
publishBinary(plan.output, contents, plan.platform);
|
|
304
|
+
publishBinary(plan.toolsOutput, toolsContents, plan.platform);
|
|
305
|
+
writeInstallStatus({ ...plan.status, ok: true, reason: 'installed', sha256: sha256(contents),
|
|
306
|
+
toolsSha256: sha256(toolsContents) }, plan.statusPath);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function recordInstallFailure(plan, error) {
|
|
310
|
+
try {
|
|
311
|
+
rmSync(plan.output, { force: true });
|
|
312
|
+
rmSync(plan.toolsOutput, { force: true });
|
|
313
|
+
writeInstallStatus({ ...plan.status, ok: false,
|
|
314
|
+
reason: error instanceof Error ? error.message : String(error) }, plan.statusPath);
|
|
315
|
+
} catch (statusError) {
|
|
316
|
+
rmSync(plan.statusPath, { force: true });
|
|
317
|
+
throw new Error(`Could not invalidate prebuilt install for '${plan.key}': ${statusError instanceof Error ? statusError.message : String(statusError)}`, { cause: error });
|
|
318
|
+
}
|
|
81
319
|
}
|
|
82
320
|
|
|
83
321
|
async function fetchRelease(manifestUrl, key) {
|
|
@@ -100,7 +338,7 @@ async function fetchRelease(manifestUrl, key) {
|
|
|
100
338
|
if (response.status === 404) error.code = 'PREBUILT_RELEASE_MISSING';
|
|
101
339
|
throw error;
|
|
102
340
|
}
|
|
103
|
-
return releaseFromManifest(await response.json(), key);
|
|
341
|
+
return releaseFromManifest(validateReleaseManifest(await response.json()), key);
|
|
104
342
|
}
|
|
105
343
|
|
|
106
344
|
export async function downloadReleaseArtifact(key, options = {}) {
|
|
@@ -119,21 +357,66 @@ export async function downloadReleaseArtifact(key, options = {}) {
|
|
|
119
357
|
if (!response.ok) {
|
|
120
358
|
throw new Error(`Prebuilt release fetch failed for '${key}' at ${release.url}: HTTP ${response.status}.`);
|
|
121
359
|
}
|
|
122
|
-
|
|
360
|
+
let contents;
|
|
361
|
+
try {
|
|
362
|
+
contents = Buffer.from(await response.arrayBuffer());
|
|
363
|
+
} catch (error) {
|
|
364
|
+
throw new Error(`Prebuilt release body failed for '${key}' at ${release.url}: ${error instanceof Error ? error.message : String(error)}`);
|
|
365
|
+
}
|
|
123
366
|
verifyChecksum(contents, release.sha256, key);
|
|
367
|
+
if (contents.length === 0 || (release.size !== undefined && contents.length !== release.size)) {
|
|
368
|
+
throw new Error(`Prebuilt release size verification failed for '${key}': received ${contents.length} bytes.`);
|
|
369
|
+
}
|
|
124
370
|
return contents;
|
|
125
371
|
}
|
|
126
372
|
|
|
373
|
+
/** Reuse only a complete install for this exact package, platform and manifest selection. */
|
|
374
|
+
function isVerifiedInstall(plan, options) {
|
|
375
|
+
try {
|
|
376
|
+
const status = JSON.parse(readFileSync(plan.statusPath, 'utf8'));
|
|
377
|
+
if (status.ok !== true || status.key !== plan.key ||
|
|
378
|
+
status.version !== plan.status.version || status.url !== plan.status.url) return false;
|
|
379
|
+
// A caller can replace a local lock without changing its path. That explicit pin must
|
|
380
|
+
// still authorize these bytes, and a missing/invalid pin must never be bypassed by cache.
|
|
381
|
+
const manifestPath = options.manifestPath ?? process.env.THREENATIVE_PREBUILT_MANIFEST;
|
|
382
|
+
const pinned = manifestPath ? readRelease(resolve(manifestPath), plan.key) : undefined;
|
|
383
|
+
if (pinned && pinned.sha256 !== status.sha256) return false;
|
|
384
|
+
const contents = readFileSync(plan.output);
|
|
385
|
+
if (contents.length === 0 || (pinned?.size !== undefined && contents.length !== pinned.size)) return false;
|
|
386
|
+
verifyChecksum(contents, status.sha256, plan.key);
|
|
387
|
+
// A cached runtime without its verified helper is not a reusable desktop install.
|
|
388
|
+
if (typeof status.toolsSha256 !== 'string') return false;
|
|
389
|
+
const pinnedTools = manifestPath ? readRelease(resolve(manifestPath), plan.toolsKey) : undefined;
|
|
390
|
+
if (pinnedTools && pinnedTools.sha256 !== status.toolsSha256) return false;
|
|
391
|
+
const tools = readFileSync(plan.toolsOutput);
|
|
392
|
+
if (tools.length === 0 || (pinnedTools?.size !== undefined && tools.length !== pinnedTools.size)) return false;
|
|
393
|
+
verifyChecksum(tools, status.toolsSha256, plan.toolsKey);
|
|
394
|
+
return true;
|
|
395
|
+
} catch {
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
127
400
|
export async function installPrebuilt(options = {}) {
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
401
|
+
const plan = createInstallPlan(options);
|
|
402
|
+
try {
|
|
403
|
+
// Packaging may reuse verified bytes offline. Explicit install/retry keeps its original
|
|
404
|
+
// invalidation semantics, including removing an earlier binary on a failed retry.
|
|
405
|
+
if (options.reuse === true) {
|
|
406
|
+
platformKey(plan.platform, options.arch);
|
|
407
|
+
if (isVerifiedInstall(plan, options)) return plan.output;
|
|
408
|
+
}
|
|
409
|
+
// A failed retry must not leave an earlier binary usable or its old success marker intact.
|
|
410
|
+
beginInstall(plan, options.arch);
|
|
411
|
+
const contents = await downloadReleaseArtifact(plan.key, options);
|
|
412
|
+
const toolsContents = await downloadReleaseArtifact(plan.toolsKey, options);
|
|
413
|
+
publishInstall(plan, contents, toolsContents);
|
|
414
|
+
console.log(`Installed verified ThreeNative runtime and build tool helper for '${plan.key}'.`);
|
|
415
|
+
return plan.output;
|
|
416
|
+
} catch (error) {
|
|
417
|
+
recordInstallFailure(plan, error);
|
|
418
|
+
throw error;
|
|
419
|
+
}
|
|
137
420
|
}
|
|
138
421
|
|
|
139
422
|
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
@@ -141,26 +424,16 @@ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1]
|
|
|
141
424
|
if (sourceCheckout) {
|
|
142
425
|
console.log('ThreeNative runtime source checkout detected; prebuilt install is deferred to package testing.');
|
|
143
426
|
} else {
|
|
144
|
-
const key = `${process.platform}-${process.arch}`;
|
|
145
|
-
const url = process.env.THREENATIVE_PREBUILT_MANIFEST ?? releaseManifestUrl();
|
|
146
427
|
installPrebuilt()
|
|
147
|
-
.then(() => writeInstallStatus({ key, ok: true, reason: 'installed', url, version: packageVersion }))
|
|
148
428
|
.catch((error) => {
|
|
149
429
|
const reason = error instanceof Error ? error.message : String(error);
|
|
150
|
-
try {
|
|
151
|
-
writeInstallStatus({ key, ok: false, reason, url, version: packageVersion });
|
|
152
|
-
} catch (statusError) {
|
|
153
|
-
console.error(
|
|
154
|
-
`Could not record prebuilt install status: ${statusError instanceof Error ? statusError.message : String(statusError)}`,
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
430
|
// An unpublished release is a packaging-state fact, not a broken download. The web game
|
|
158
431
|
// this install carries must not lose node_modules/.bin over an optional native binary;
|
|
159
432
|
// the native lanes fail closed later, on the missing binary itself.
|
|
160
|
-
if (error instanceof Error &&
|
|
433
|
+
if (error instanceof Error &&
|
|
434
|
+
['PREBUILT_RELEASE_MISSING', 'PREBUILT_RELEASE_UNPUBLISHED'].includes(error.code)) {
|
|
161
435
|
console.warn(
|
|
162
|
-
`No prebuilt release is published for v${packageVersion} (${reason}).
|
|
163
|
-
'Continuing without the native runtime; desktop and device lanes fail closed on the missing binary.',
|
|
436
|
+
`No prebuilt release is published for v${packageVersion} (${reason}). Continuing without the native runtime; desktop and device lanes fail closed on the missing binary.`,
|
|
164
437
|
);
|
|
165
438
|
return;
|
|
166
439
|
}
|
|
@@ -156,7 +156,7 @@ function androidPaths(root = runtimeRoot) {
|
|
|
156
156
|
export const DEFAULT_ANDROID_CONFIG = {
|
|
157
157
|
app: { id: 'com.threenative.game', name: 'ThreeNative', version: '0.1.0', build: 1 },
|
|
158
158
|
display: { orientation: 'landscape', fullscreen: true, keepScreenOn: false, maxFps: 60, backgroundMode: 'pause' },
|
|
159
|
-
window: { title: 'ThreeNative', width: 1280, height: 720, resizable: true },
|
|
159
|
+
window: { title: 'ThreeNative', width: 1280, height: 720, maximized: false, resizable: true },
|
|
160
160
|
// `native` is PRD-216's CanvasLayer renderer: no WebView, no CSS, no second process. A game
|
|
161
161
|
// that never states a renderer therefore ships no overlay, which is what acceptance criterion 5
|
|
162
162
|
// asks for. Templates state `web` explicitly.
|
|
@@ -629,18 +629,26 @@ export async function packageAndroid(
|
|
|
629
629
|
config = undefined,
|
|
630
630
|
options = {},
|
|
631
631
|
) {
|
|
632
|
-
//
|
|
633
|
-
//
|
|
634
|
-
//
|
|
635
|
-
// A game in a sandbox resolves `runtime-native` to the published tarball, which ships no
|
|
636
|
-
// `CMakeLists.txt`, so the check below always takes the download path — and the download path
|
|
637
|
-
// fetches a GitHub release that does not exist, in a repository that is private. Every consumer
|
|
638
|
-
// on 0.2.0 gets `HTTP 404` naming a URL and no next step. `packageAndroid` has always accepted
|
|
639
|
-
// `options.runtimeRoot`; it simply was not reachable from the CLI or the environment.
|
|
632
|
+
// Source identity must not depend on whether downloaded dependencies are already present.
|
|
633
|
+
// Otherwise a partially provisioned checkout silently takes the consumer download path.
|
|
640
634
|
const packageRoot = resolve(
|
|
641
635
|
options.runtimeRoot ?? process.env.THREENATIVE_RUNTIME_SOURCE ?? runtimeRoot,
|
|
642
636
|
);
|
|
643
637
|
const { androidRoot } = androidPaths(packageRoot);
|
|
638
|
+
const sourceCheckout = existsSync(join(packageRoot, 'CMakeLists.txt'));
|
|
639
|
+
if (sourceCheckout && options.allowSourceBuild !== true) {
|
|
640
|
+
throw new Error(
|
|
641
|
+
`Android build resolved a source checkout at ${packageRoot} with no explicit opt-in. ` +
|
|
642
|
+
'Pass --allow-source-build (or { allowSourceBuild: true }) for a maintainer build; ' +
|
|
643
|
+
'consumer builds use the prebuilt path from a published install.',
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
if (sourceCheckout && !existsSync(join(packageRoot, 'third_party', 'sdl3-android', `SDL3-${SDL3_ANDROID_VERSION}.aar`))) {
|
|
647
|
+
throw new Error(
|
|
648
|
+
`Android source checkout at ${packageRoot} is missing SDL3-${SDL3_ANDROID_VERSION}.aar. ` +
|
|
649
|
+
'Provision the maintainer dependencies with node scripts/download-deps.mjs --android from the runtime checkout, then retry --allow-source-build.',
|
|
650
|
+
);
|
|
651
|
+
}
|
|
644
652
|
const declared = configValue(config, orientation);
|
|
645
653
|
orientationValue(declared.display.orientation);
|
|
646
654
|
const gradlew = join(androidRoot, process.platform === 'win32' ? 'gradlew.bat' : 'gradlew');
|
|
@@ -650,9 +658,6 @@ export async function packageAndroid(
|
|
|
650
658
|
options.ensureGradleWrapper ??
|
|
651
659
|
(() => ensureGradleWrapper({ output: join(androidRoot, 'gradle', 'wrapper', 'gradle-wrapper.jar') }));
|
|
652
660
|
await ensureWrapper();
|
|
653
|
-
const sourceCheckout =
|
|
654
|
-
existsSync(join(packageRoot, 'CMakeLists.txt')) &&
|
|
655
|
-
existsSync(join(packageRoot, 'third_party', 'sdl3-android', `SDL3-${SDL3_ANDROID_VERSION}.aar`));
|
|
656
661
|
if (!sourceCheckout) {
|
|
657
662
|
const preparePrebuilts =
|
|
658
663
|
options.prepareAndroidPrebuilts ??
|
|
@@ -663,7 +668,7 @@ export async function packageAndroid(
|
|
|
663
668
|
// Name the cause and the way out. The bare HTTP status told a person which URL failed and
|
|
664
669
|
// nothing about why a published install can never satisfy it.
|
|
665
670
|
throw new Error(
|
|
666
|
-
`${error instanceof Error ? error.message : String(error)}\n\nThis install has no runtime source checkout at ${packageRoot}, so it tried to download\nprebuilt Android artifacts from a GitHub release. Point the packager at a source\ncheckout of @threenative/runtime-native instead:\n\n THREENATIVE_RUNTIME_SOURCE=/path/to/packages/runtime-native pnpm build
|
|
671
|
+
`${error instanceof Error ? error.message : String(error)}\n\nThis install has no runtime source checkout at ${packageRoot}, so it tried to download\nprebuilt Android artifacts from a GitHub release. Point the packager at a source\ncheckout of @threenative/runtime-native instead:\n\n THREENATIVE_RUNTIME_SOURCE=/path/to/packages/runtime-native pnpm exec threenative build --target android --allow-source-build\n`,
|
|
667
672
|
{ cause: error },
|
|
668
673
|
);
|
|
669
674
|
}
|
|
@@ -737,13 +742,14 @@ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1]
|
|
|
737
742
|
const orientationIndex = process.argv.indexOf('--orientation');
|
|
738
743
|
const configIndex = process.argv.indexOf('--config');
|
|
739
744
|
const uiIndex = process.argv.indexOf('--ui');
|
|
745
|
+
const allowSourceBuild = process.argv.includes('--allow-source-build');
|
|
740
746
|
if (
|
|
741
747
|
bundleIndex === -1 ||
|
|
742
748
|
!process.argv[bundleIndex + 1] ||
|
|
743
749
|
process.argv[bundleIndex + 1].startsWith('--')
|
|
744
750
|
) {
|
|
745
751
|
console.error(
|
|
746
|
-
'Usage: package-android.mjs --bundle FILE [--output FILE] [--assets DIR] [--ui DIR] [--orientation landscape|portrait|sensor] [--config FILE]',
|
|
752
|
+
'Usage: package-android.mjs --bundle FILE [--output FILE] [--assets DIR] [--ui DIR] [--orientation landscape|portrait|sensor] [--config FILE] [--allow-source-build]',
|
|
747
753
|
);
|
|
748
754
|
process.exitCode = 1;
|
|
749
755
|
} else if (
|
|
@@ -782,7 +788,12 @@ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1]
|
|
|
782
788
|
assetsIndex === -1 ? undefined : resolve(process.argv[assetsIndex + 1]),
|
|
783
789
|
orientationIndex === -1 ? undefined : process.argv[orientationIndex + 1],
|
|
784
790
|
readAndroidConfig(configPath),
|
|
785
|
-
|
|
791
|
+
{
|
|
792
|
+
...(uiIndex === -1 ? {} : { ui: resolve(process.argv[uiIndex + 1]) }),
|
|
793
|
+
// Maintainer route for source-checkout builds: the guard requires an
|
|
794
|
+
// explicit opt-in, and this flag is its CLI spelling.
|
|
795
|
+
...(allowSourceBuild ? { allowSourceBuild: true } : {}),
|
|
796
|
+
},
|
|
786
797
|
);
|
|
787
798
|
} catch (error) {
|
|
788
799
|
console.error(error instanceof Error ? error.message : String(error));
|
|
@@ -19,13 +19,38 @@ import { 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 { installPrebuilt } from './install-prebuilt.mjs';
|
|
22
23
|
|
|
23
24
|
const runtimeRoot = resolve(fileURLToPath(new URL('..', import.meta.url)));
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Resolve the desktop runtime binary a consumer build compiles against.
|
|
28
|
+
*
|
|
29
|
+
* A published install ships no compiled runtime until the postinstall hook fetches one, so a
|
|
30
|
+
* missing `--runtime` installs from the release manifest rather than failing with a bare
|
|
31
|
+
* "missing file". `THREENATIVE_RUNTIME_SOURCE` remains the decoder-preflight source only: it
|
|
32
|
+
* never selects or substitutes the runtime binary, and no code path here reads a checkout as
|
|
33
|
+
* the runtime. `options.runtimeSource` is an explicit test seam for the preflight directory.
|
|
34
|
+
*/
|
|
35
|
+
export async function resolveDesktopRuntime(explicit, options = {}) {
|
|
36
|
+
if (explicit) {
|
|
37
|
+
if (!existsSync(explicit)) throw new Error(`Missing prebuilt runtime for '${process.platform}-${process.arch}': ${explicit}`);
|
|
38
|
+
return explicit;
|
|
39
|
+
}
|
|
40
|
+
const sourceOverride = options.runtimeSource ?? process.env.THREENATIVE_RUNTIME_SOURCE;
|
|
41
|
+
if (sourceOverride) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Desktop source-checkout preflight is set (THREENATIVE_RUNTIME_SOURCE=${sourceOverride}) but no --runtime was provided. ` +
|
|
44
|
+
'Pass the checkout-built --runtime explicitly for a maintainer build; consumer builds unset the override and install from the release manifest.',
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return installPrebuilt({ ...options.install, reuse: true });
|
|
48
|
+
}
|
|
49
|
+
|
|
25
50
|
export const DEFAULT_DESKTOP_CONFIG = {
|
|
26
51
|
app: { id: 'com.threenative.game', name: 'ThreeNative', version: '0.1.0', build: 1 },
|
|
27
52
|
display: { orientation: 'landscape', fullscreen: true, keepScreenOn: false, maxFps: 60 },
|
|
28
|
-
window: { title: 'ThreeNative', width: 1280, height: 720, resizable: true },
|
|
53
|
+
window: { title: 'ThreeNative', width: 1280, height: 720, maximized: false, resizable: true },
|
|
29
54
|
};
|
|
30
55
|
|
|
31
56
|
function readConfig(configPath) {
|
|
@@ -43,11 +68,14 @@ export function parseArgs(args) {
|
|
|
43
68
|
const flag = args[index];
|
|
44
69
|
const value = args[index + 1];
|
|
45
70
|
if (!['--assets', '--bundle', '--config', '--output', '--runtime', '--ui'].includes(flag) || !value) {
|
|
46
|
-
throw new Error('Usage: package-desktop.mjs --bundle FILE --
|
|
71
|
+
throw new Error('Usage: package-desktop.mjs --bundle FILE --output FILE [--runtime FILE] [--assets DIR] [--ui DIR] [--config FILE]');
|
|
47
72
|
}
|
|
48
73
|
options[flag.slice(2)] = resolve(value);
|
|
49
74
|
}
|
|
50
|
-
|
|
75
|
+
// `--runtime` is optional: a consumer build with no `--runtime` installs the verified
|
|
76
|
+
// prebuilt from the release manifest via resolveDesktopRuntime. A maintainer build passes
|
|
77
|
+
// the checkout-built binary explicitly.
|
|
78
|
+
for (const required of ['bundle', 'output']) {
|
|
51
79
|
if (!options[required]) throw new Error(`Missing --${required}.`);
|
|
52
80
|
}
|
|
53
81
|
return options;
|
|
@@ -58,9 +86,23 @@ export function packageDesktop(options) {
|
|
|
58
86
|
if (!['linux-x64', 'linux-arm64', 'darwin-x64', 'darwin-arm64', 'win32-x64'].includes(key)) {
|
|
59
87
|
throw new Error(`Unsupported desktop platform '${key}'.`);
|
|
60
88
|
}
|
|
61
|
-
|
|
62
|
-
|
|
89
|
+
if (!options.bundle || !existsSync(options.bundle)) {
|
|
90
|
+
throw new Error(`Missing native bundle for '${key}': ${options.bundle ?? '(not provided)'}`);
|
|
91
|
+
}
|
|
92
|
+
// An explicit `--runtime` keeps the original sync body: the preflight failure the
|
|
93
|
+
// decoder tests assert stays a sync throw. Only the missing-runtime install is async.
|
|
94
|
+
if (options.runtime) {
|
|
95
|
+
if (!existsSync(options.runtime)) {
|
|
96
|
+
throw new Error(`Missing prebuilt runtime for '${key}': ${options.runtime}`);
|
|
97
|
+
}
|
|
98
|
+
return compileDesktopArtifact(options, options.runtime);
|
|
63
99
|
}
|
|
100
|
+
return resolveDesktopRuntime(undefined, { runtimeSource: options.runtimeSource, install: options.install }).then((runtime) =>
|
|
101
|
+
compileDesktopArtifact(options, runtime),
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function compileDesktopArtifact(options, runtime) {
|
|
64
106
|
const output = process.platform === 'win32' && !options.output.endsWith('.exe')
|
|
65
107
|
? `${options.output}.exe`
|
|
66
108
|
: options.output;
|
|
@@ -72,6 +114,7 @@ export function packageDesktop(options) {
|
|
|
72
114
|
options.assets,
|
|
73
115
|
staging,
|
|
74
116
|
options.config === undefined ? undefined : readConfig(options.config),
|
|
117
|
+
process.env.THREENATIVE_RUNTIME_SOURCE ?? runtimeRoot,
|
|
75
118
|
);
|
|
76
119
|
// The UI bundle sits beside the executable rather than inside it. Desktop compiles to one
|
|
77
120
|
// file, but the overlay's web view reads its page from a real path — that is what gives it a
|
|
@@ -93,7 +136,7 @@ export function packageDesktop(options) {
|
|
|
93
136
|
'--out',
|
|
94
137
|
output,
|
|
95
138
|
];
|
|
96
|
-
const result = spawnSync(
|
|
139
|
+
const result = spawnSync(runtime, args, { encoding: 'utf8', stdio: 'inherit' });
|
|
97
140
|
if (result.error) throw result.error;
|
|
98
141
|
if (result.status !== 0)
|
|
99
142
|
throw new Error(`Runtime packager exited with code ${result.status ?? 'unknown'}.`);
|
|
@@ -192,7 +235,7 @@ export function stageDesktopFiles(
|
|
|
192
235
|
|
|
193
236
|
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
194
237
|
try {
|
|
195
|
-
packageDesktop(parseArgs(process.argv.slice(2)));
|
|
238
|
+
await packageDesktop(parseArgs(process.argv.slice(2)));
|
|
196
239
|
} catch (error) {
|
|
197
240
|
console.error(error instanceof Error ? error.message : String(error));
|
|
198
241
|
process.exitCode = 1;
|