@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 CHANGED
@@ -8,3 +8,5 @@ Imported maintained-fork state: c705b16eef02bc49e68fe6c9b4114698aa6b3d7f
8
8
 
9
9
  The upstream license is preserved in LICENSE. Third-party dependencies are not vendored;
10
10
  scripts/download-deps.mjs downloads them into the untracked third_party directory.
11
+ Every payload is pinned in native-deps.lock.json; release auditors read the generated
12
+ SBOM and license inventory attached to native prereleases (scripts/generate-native-sbom.mjs).
@@ -266,6 +266,16 @@ val buildNativePhysics by tasks.registering(Exec::class) {
266
266
  outputs.dir(layout.projectDirectory.dir("../../.runtime/physics-target"))
267
267
  }
268
268
 
269
+ // Verify the complete source payload on every build, even when snapshot copying is up-to-date.
270
+ // Published, no-NDK builds must not resolve or execute this development-only source helper.
271
+ if (!usePrebuiltRuntime && nativeJsEngineName == "v8") {
272
+ val verifyV8Dependency = tasks.register<Exec>("verifyV8Dependency") {
273
+ workingDir(runtimeRoot.asFile)
274
+ commandLine("node", runtimeRoot.file("scripts/build-android-v8.mjs").asFile.absolutePath, "--verify")
275
+ }
276
+ tasks.named("copyV8Snapshot") { dependsOn(verifyV8Dependency) }
277
+ }
278
+
269
279
  tasks.named("preBuild") {
270
280
  dependsOn("copyV8Snapshot")
271
281
  if (conformanceBundle.isPresent) dependsOn("buildAndroidConformanceBundle")
@@ -286,7 +296,7 @@ dependencies {
286
296
  android {
287
297
  namespace = "com.threenative.game"
288
298
  compileSdk = 35
289
- ndkVersion = "27.1.12297006"
299
+ ndkVersion = "28.2.13676358"
290
300
 
291
301
  defaultConfig {
292
302
  applicationId = "com.threenative.game"
@@ -92,6 +92,17 @@ public class MystralActivity extends SDLActivity {
92
92
  if (mSurface != null) requestPreferredFrameRate(mSurface.getHolder(), applicationMetadata());
93
93
  }
94
94
 
95
+ @Override
96
+ public void onTrimMemory(int level) {
97
+ // SDL's implementation below forwards a level-less SDL_EVENT_LOW_MEMORY. Capture the
98
+ // ComponentCallbacks2 level first so the existing lifecycle watch can answer moderate and
99
+ // critical pressure differently, then preserve SDL's event delivery with super.
100
+ nativeOnTrimMemory(level);
101
+ super.onTrimMemory(level);
102
+ }
103
+
104
+ private static native void nativeOnTrimMemory(int level);
105
+
95
106
  private void installPreferredFrameRate(Bundle metadata) {
96
107
  if (mSurface == null) {
97
108
  Log.w(LOG_TAG, "TN_DISPLAY_FRAME_RATE_REQUEST:{\"applied\":false,\"reason\":\"surface-missing\"}");
@@ -10,4 +10,4 @@ android.useAndroidX=true
10
10
  org.gradle.caching=true
11
11
 
12
12
  # NDK version - matches the SDK-installed NDK
13
- android.ndkVersion=27.1.12297006
13
+ android.ndkVersion=28.2.13676358
package/package.json CHANGED
@@ -1,7 +1,26 @@
1
1
  {
2
2
  "name": "@threenative/runtime-native",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "ThreeNative-owned native host for desktop, Android, and iOS",
5
+ "keywords": [
6
+ "threenative",
7
+ "native",
8
+ "desktop",
9
+ "android",
10
+ "ios",
11
+ "webgpu",
12
+ "three",
13
+ "threejs"
14
+ ],
15
+ "homepage": "https://github.com/ThreeNativeHQ/threenative#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/ThreeNativeHQ/threenative/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/ThreeNativeHQ/threenative.git",
22
+ "directory": "packages/runtime-native"
23
+ },
5
24
  "license": "MIT",
6
25
  "publishConfig": {
7
26
  "access": "public"
@@ -25,6 +44,7 @@
25
44
  "android/settings.gradle.kts",
26
45
  "scripts/asset-preflight.mjs",
27
46
  "scripts/bundle.mjs",
47
+ "scripts/check-source-list.mjs",
28
48
  "scripts/device-preflight.mjs",
29
49
  "scripts/install-prebuilt.mjs",
30
50
  "scripts/package-android.mjs",
@@ -42,15 +62,18 @@
42
62
  "publint": "0.3.22",
43
63
  "three": "0.185.1",
44
64
  "vitest": "4.1.10",
45
- "@threenative/playtest": "0.3.0"
65
+ "@threenative/playtest": "0.3.2"
46
66
  },
47
67
  "dependencies": {
48
68
  "pngjs": "7.0.0"
49
69
  },
50
70
  "scripts": {
51
71
  "deps:download": "node scripts/download-deps.mjs",
72
+ "deps:verify": "node scripts/download-deps.mjs --check-lock",
73
+ "deps:sbom": "node scripts/generate-native-sbom.mjs --out .runtime/sbom",
74
+ "deps:sbom:check": "node scripts/generate-native-sbom.mjs --check --sbom .runtime/sbom/native-dependencies.cdx.json --inventory .runtime/sbom/native-license-inventory.json",
52
75
  "native:build": "node scripts/download-deps.mjs && node scripts/native-build.mjs",
53
- "native:coverage": "node scripts/measure-native-coverage.mjs",
76
+ "native:coverage": "sh ../../scripts/xvfb.sh node scripts/measure-native-coverage.mjs",
54
77
  "native:test:cpp": "node scripts/measure-native-coverage.mjs --ctest",
55
78
  "native:test:asan": "node scripts/measure-native-coverage.mjs --sanitizers",
56
79
  "native:physics:cross": "node scripts/build-native-physics.mjs",
@@ -58,7 +81,7 @@
58
81
  "native:physics:parity": "pnpm --dir ../.. exec vitest run packages/physics/__tests__/parity.spec.ts && cargo test --manifest-path native/physics/Cargo.toml --lib --test parity -- --nocapture",
59
82
  "native:physics:parity:device": "node scripts/verify-android-physics-parity.mjs",
60
83
  "native:qualify:physical": "node scripts/qualify-physical-mobile.mjs",
61
- "native:verify:desktop": "node scripts/verify-desktop-audio.mjs && node scripts/verify-desktop-stability.mjs && node scripts/verify-desktop-core.mjs && node scripts/verify-desktop-physics.mjs && node scripts/verify-native-contracts.mjs && pnpm --dir ../playtest build && sh ../../scripts/xvfb.sh node scripts/verify-desktop-loading.mjs",
84
+ "native:verify:desktop": "node scripts/verify-desktop-audio.mjs && node scripts/verify-desktop-stability.mjs && node scripts/verify-desktop-core.mjs && node scripts/verify-desktop-physics.mjs && sh ../../scripts/xvfb.sh node scripts/verify-native-contracts.mjs && pnpm --dir ../playtest build && sh ../../scripts/xvfb.sh node scripts/verify-desktop-loading.mjs",
62
85
  "native:verify:loading": "pnpm --dir ../playtest build && sh ../../scripts/xvfb.sh node scripts/verify-desktop-loading.mjs",
63
86
  "native:verify:android:multitouch": "pnpm --dir ../playtest build && node scripts/verify-android-multitouch.mjs",
64
87
  "profile:production": "node scripts/profile-production.mjs",
@@ -167,9 +167,9 @@ const MOBILE_KTX2_MESSAGE =
167
167
  // Deliberately never spells the WASM host object: `TN_NATIVE_WASM_ON_MOBILE` greps the
168
168
  // finished bundle for that identifier, and a refusal message must not read as the thing it
169
169
  // refuses.
170
- "TN_NATIVE_KTX2_UNSUPPORTED: this Android/iOS bundle carries no Basis transcoder, because the mobile native runtime has no WASM engine. Compiled .ktx2 textures cannot be decoded here; build native targets with assets.textures set to \\\"none\\\", or keep those textures on the web target.";
170
+ "TN_NATIVE_KTX2_UNSUPPORTED: this Android/iOS bundle carries no Basis transcoder, because the mobile native runtime has no WASM engine. Compiled .ktx2 textures cannot be decoded here; native compilation automatically keeps decoder-free authored textures, or keep compressed textures on the web target.";
171
171
  const MOBILE_MESH_MESSAGE =
172
- "TN_NATIVE_MESH_COMPRESSION_UNSUPPORTED: this Android/iOS bundle carries no Meshopt or Draco decoder, because the mobile native runtime has no WASM engine. Compressed model geometry cannot be decoded here; build native targets with assets.models set to \\\"none\\\", or keep those models on the web target.";
172
+ "TN_NATIVE_MESH_COMPRESSION_UNSUPPORTED: this Android/iOS bundle carries no Meshopt or Draco decoder, because the mobile native runtime has no WASM engine. Compressed model geometry cannot be decoded here; native compilation keeps shared images and decoder-free model geometry, or keep compressed models on the web target.";
173
173
 
174
174
  const MOBILE_DECODER_STUBS = [
175
175
  {
@@ -264,12 +264,9 @@ async function bundleProject(project, entryPoint, outputPath, target) {
264
264
  const nativeElements = new Map();
265
265
  const nativeGetElementById = document.getElementById.bind(document);
266
266
  const nativeQuerySelector = document.querySelector.bind(document);
267
- const nativeCreateElement = document.createElement.bind(document);
268
267
  document.getElementById = (id) => nativeElements.get(id) ?? nativeGetElementById(id);
269
268
  document.querySelector = (selector) =>
270
269
  selector.startsWith("#") ? nativeElements.get(selector.slice(1)) ?? null : nativeQuerySelector(selector);
271
- document.createElement = (tag) =>
272
- String(tag).toLowerCase() === "canvas" ? globalThis.canvas : nativeCreateElement(tag);
273
270
  for (const id of ["app", "root"]) {
274
271
  if (nativeGetElementById(id) == null) {
275
272
  const element = document.createElement("div");
@@ -346,7 +343,17 @@ void game.start().catch((error) => console.error(
346
343
  target === 'desktop'
347
344
  ? [importMetaPlugin, nativeEntryPlugin]
348
345
  : [importMetaPlugin, mobileDecodersPlugin, nativeEntryPlugin],
349
- resolve: target === 'desktop' ? undefined : { conditions: ['threenative-native'] },
346
+ // One three, whatever the import graph looks like. The game resolves `three` beside itself
347
+ // while a linked engine package — `@threenative/core`, or anything else installed outside the
348
+ // project — resolves the same bare specifier beside *itself*, so a second physical copy enters
349
+ // the bundle. Three keeps the TSL node stack in module scope, so the copy that builds a
350
+ // material is not the copy the renderer pushed onto, and the first material build on the phone
351
+ // dies with "No stack defined for assign operation". `mergeConfig` concatenates arrays, so a
352
+ // project that dedupes its own packages keeps every one of them.
353
+ resolve:
354
+ target === 'desktop'
355
+ ? { dedupe: ['three'] }
356
+ : { conditions: ['threenative-native'], dedupe: ['three'] },
350
357
  configFile: existsSync(join(absoluteProject, 'vite.config.ts'))
351
358
  ? join(absoluteProject, 'vite.config.ts')
352
359
  : undefined,
@@ -0,0 +1,90 @@
1
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
2
+ import { dirname, join, relative, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const sourceToken = /src\/[A-Za-z0-9_./-]+\.cpp/gu;
6
+ const explicitlyExcludedSources = new Set([
7
+ "src/gltf/gltf_loader.cpp",
8
+ "src/utils/cgltf_impl.cpp",
9
+ ]);
10
+
11
+ function normalizePath(path) {
12
+ return path.replaceAll("\\", "/");
13
+ }
14
+
15
+ function stripCmakeComments(cmakeSource) {
16
+ const withoutBracketComments = cmakeSource.replace(
17
+ /#\[(=*)\[[\s\S]*?\]\1\]/gu,
18
+ (comment) => comment.replace(/[^\r\n]/gu, " "),
19
+ );
20
+ return withoutBracketComments.replace(/#[^\r\n]*/gu, "");
21
+ }
22
+
23
+ function sourcePathsOnDisk(directory, root = directory) {
24
+ const paths = [];
25
+ for (const entry of readdirSync(directory, { withFileTypes: true }).sort((a, b) =>
26
+ a.name.localeCompare(b.name),
27
+ )) {
28
+ const path = join(directory, entry.name);
29
+ if (entry.isDirectory()) {
30
+ paths.push(...sourcePathsOnDisk(path, root));
31
+ } else if (entry.isFile() && entry.name.endsWith(".cpp")) {
32
+ paths.push(`src/${normalizePath(relative(root, path))}`);
33
+ }
34
+ }
35
+ return paths;
36
+ }
37
+
38
+ function excludedSourcePaths(cmakeSource) {
39
+ const block = /set\s*\(\s*MYSTRAL_EXCLUDED_CPP_SOURCES([\s\S]*?)\)/u.exec(cmakeSource);
40
+ return new Set([
41
+ ...explicitlyExcludedSources,
42
+ ...(block?.[1]?.match(sourceToken) ?? []),
43
+ ]);
44
+ }
45
+
46
+ export function checkSourceList({ cmakeSource, sourceRoot, sourcePaths } = {}) {
47
+ if (typeof cmakeSource !== "string")
48
+ throw new TypeError("checkSourceList requires the CMake source text");
49
+
50
+ const activeCmakeSource = stripCmakeComments(cmakeSource);
51
+ const excluded = excludedSourcePaths(activeCmakeSource);
52
+ const listed = new Set(activeCmakeSource.match(sourceToken) ?? []);
53
+ for (const path of excluded) listed.delete(path);
54
+
55
+ const hasExplicitSourcePaths = Array.isArray(sourcePaths);
56
+ const actualSources = (hasExplicitSourcePaths
57
+ ? sourcePaths
58
+ : sourcePathsOnDisk(resolve(sourceRoot ?? "src")))
59
+ .map(normalizePath)
60
+ .sort();
61
+ const unlisted = actualSources.filter((path) => !listed.has(path) && !excluded.has(path));
62
+ const missing = hasExplicitSourcePaths
63
+ ? []
64
+ : [...listed].filter((path) => !existsSync(join(resolve(sourceRoot ?? "src"), path.slice(4))));
65
+ return { unlisted, missing, excluded: [...excluded].sort() };
66
+ }
67
+
68
+ function main() {
69
+ const scriptDirectory = dirname(fileURLToPath(import.meta.url));
70
+ const packageRoot = resolve(scriptDirectory, "..");
71
+ const cmakePath = join(packageRoot, "CMakeLists.txt");
72
+ const sourceRoot = join(packageRoot, "src");
73
+ const report = checkSourceList({
74
+ cmakeSource: readFileSync(cmakePath, "utf8"),
75
+ sourceRoot,
76
+ });
77
+ if (report.unlisted.length > 0 || report.missing.length > 0) {
78
+ if (report.unlisted.length > 0)
79
+ console.error(`Unlisted native C++ sources: ${report.unlisted.join(", ")}`);
80
+ if (report.missing.length > 0)
81
+ console.error(`Missing CMake native C++ sources: ${report.missing.join(", ")}`);
82
+ process.exitCode = 1;
83
+ return;
84
+ }
85
+ console.log(
86
+ `native source list passed (${report.excluded.length} explicit exclusions)`,
87
+ );
88
+ }
89
+
90
+ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main();