@mentra/crust 3.3.0-dev.656 → 3.3.0-dev.658

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.
Files changed (56) hide show
  1. package/README.md +7 -0
  2. package/android/build.gradle +15 -40
  3. package/android/src/main/java/com/mentra/crust/jsc/JSCRuntime.kt +13 -4
  4. package/android/src/test/java/com/mentra/crust/jsc/QuickJsLifecycleTest.kt +87 -0
  5. package/package.json +2 -2
  6. package/plugin/build/index.d.ts +2 -0
  7. package/plugin/build/index.js +2 -0
  8. package/plugin/build/withAndroid.js +39 -0
  9. package/android/quickjs-consumer-rules.pro +0 -6
  10. package/android/scripts/test-quickjs-lifecycle.py +0 -45
  11. package/android/src/main/cpp/quickjs/CMakeLists.txt +0 -20
  12. package/android/src/main/cpp/quickjs/LICENSE.quickjs-kt.txt +0 -201
  13. package/android/src/main/cpp/quickjs/README.md +0 -30
  14. package/android/src/main/cpp/quickjs/c-vector/LICENSE +0 -21
  15. package/android/src/main/cpp/quickjs/c-vector/cvector.h +0 -479
  16. package/android/src/main/cpp/quickjs/common/quickjs_version.c +0 -9
  17. package/android/src/main/cpp/quickjs/common/quickjs_version.h +0 -9
  18. package/android/src/main/cpp/quickjs/engine/LICENSE +0 -22
  19. package/android/src/main/cpp/quickjs/engine/VERSION +0 -1
  20. package/android/src/main/cpp/quickjs/engine/cutils.c +0 -631
  21. package/android/src/main/cpp/quickjs/engine/cutils.h +0 -347
  22. package/android/src/main/cpp/quickjs/engine/libbf.c +0 -8475
  23. package/android/src/main/cpp/quickjs/engine/libbf.h +0 -535
  24. package/android/src/main/cpp/quickjs/engine/libregexp-opcode.h +0 -57
  25. package/android/src/main/cpp/quickjs/engine/libregexp.c +0 -2501
  26. package/android/src/main/cpp/quickjs/engine/libregexp.h +0 -55
  27. package/android/src/main/cpp/quickjs/engine/libunicode-table.h +0 -4557
  28. package/android/src/main/cpp/quickjs/engine/libunicode.c +0 -1910
  29. package/android/src/main/cpp/quickjs/engine/libunicode.h +0 -182
  30. package/android/src/main/cpp/quickjs/engine/list.h +0 -99
  31. package/android/src/main/cpp/quickjs/engine/quickjs-atom.h +0 -273
  32. package/android/src/main/cpp/quickjs/engine/quickjs-opcode.h +0 -372
  33. package/android/src/main/cpp/quickjs/engine/quickjs.c +0 -55978
  34. package/android/src/main/cpp/quickjs/engine/quickjs.h +0 -1087
  35. package/android/src/main/cpp/quickjs/jni/binding_bridge.c +0 -488
  36. package/android/src/main/cpp/quickjs/jni/binding_bridge.h +0 -32
  37. package/android/src/main/cpp/quickjs/jni/exception_util.c +0 -64
  38. package/android/src/main/cpp/quickjs/jni/exception_util.h +0 -21
  39. package/android/src/main/cpp/quickjs/jni/jni_globals.c +0 -59
  40. package/android/src/main/cpp/quickjs/jni/jni_globals.h +0 -12
  41. package/android/src/main/cpp/quickjs/jni/jni_globals_generated.c +0 -855
  42. package/android/src/main/cpp/quickjs/jni/jni_globals_generated.h +0 -171
  43. package/android/src/main/cpp/quickjs/jni/js_value_util.c +0 -213
  44. package/android/src/main/cpp/quickjs/jni/js_value_util.h +0 -71
  45. package/android/src/main/cpp/quickjs/jni/log_util.h +0 -15
  46. package/android/src/main/cpp/quickjs/jni/mapping/jni_types_util.c +0 -27
  47. package/android/src/main/cpp/quickjs/jni/mapping/jni_types_util.h +0 -15
  48. package/android/src/main/cpp/quickjs/jni/mapping/jobject_to_js_value.c +0 -620
  49. package/android/src/main/cpp/quickjs/jni/mapping/jobject_to_js_value.h +0 -13
  50. package/android/src/main/cpp/quickjs/jni/mapping/js_value_to_jobject.c +0 -421
  51. package/android/src/main/cpp/quickjs/jni/mapping/js_value_to_jobject.h +0 -12
  52. package/android/src/main/cpp/quickjs/jni/promise_rejection_handler.c +0 -20
  53. package/android/src/main/cpp/quickjs/jni/promise_rejection_handler.h +0 -10
  54. package/android/src/main/cpp/quickjs/jni/quickjs_jni.c +0 -735
  55. package/android/src/main/cpp/quickjs/jni/quickjs_jni.h +0 -40
  56. package/android/src/testNative/QuickJsLifecycleTest.kt +0 -56
package/README.md CHANGED
@@ -31,6 +31,13 @@ core-library desugaring. Add it to the host app's Expo config:
31
31
  Building with the navigation feature requires a `MAPBOX_DOWNLOADS_TOKEN` in
32
32
  the Android build environment (Mapbox's SDK repository is authenticated).
33
33
 
34
+ The plugin also raises the host's Android build to Kotlin 2.3.0 (crust's
35
+ QuickJS library, `quickjs-kt` 1.0.15, is compiled with Kotlin 2.4) and pins
36
+ the root Kotlin Gradle plugin to that version. Every native module in the
37
+ host then compiles with Kotlin 2.3. Known incompatibility:
38
+ `react-native-gesture-handler` before 2.31.0 fails to compile; use 2.31.0 or
39
+ later.
40
+
34
41
  At build time the Android side also reads the MentraJS polyfill bundle from
35
42
  its [`@mentra/jspolyfill`](https://www.npmjs.com/package/@mentra/jspolyfill)
36
43
  sibling, which is declared as a dependency.
@@ -1,24 +1,5 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
- // Resolve alpha13 only as a build input. Embed its Kotlin classes as a local
4
- // JAR so its obsolete JNI libraries never reach a consuming app transitively.
5
- configurations {
6
- quickJsKotlinAar {
7
- canBeConsumed = false
8
- canBeResolved = true
9
- transitive = false
10
- attributes.attribute(org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE,
11
- objects.named(org.gradle.api.attributes.Usage, org.gradle.api.attributes.Usage.JAVA_RUNTIME))
12
- }
13
- }
14
- def extractQuickJsClasses = tasks.register('extractQuickJsClasses', Sync) {
15
- from({ zipTree(configurations.quickJsKotlinAar.singleFile) }) {
16
- include 'classes.jar'
17
- rename 'classes.jar', 'quickjs-alpha13.jar'
18
- }
19
- into layout.buildDirectory.dir('quickjs-kotlin')
20
- }
21
-
22
3
  group = 'com.mentra.crust'
23
4
  version = '0.1.0'
24
5
 
@@ -69,17 +50,6 @@ android {
69
50
  versionCode 1
70
51
  versionName "0.1.0"
71
52
  multiDexEnabled true
72
- // Preserve alpha13's JNI class names when consuming apps enable R8.
73
- consumerProguardFiles 'quickjs-consumer-rules.pro'
74
- externalNativeBuild {
75
- cmake { arguments '-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON' }
76
- }
77
- }
78
- externalNativeBuild {
79
- cmake {
80
- path 'src/main/cpp/quickjs/CMakeLists.txt'
81
- version '3.22.1'
82
- }
83
53
  }
84
54
  // Pull the MentraJS polyfill bundle from the sibling @mentra/jspolyfill
85
55
  // module's `assets/` directory — single committed source of truth. The
@@ -155,14 +125,10 @@ dependencies {
155
125
  // for installing Kotlin lambdas as JS globals via `JS_SetPropertyStr`.
156
126
  // Mirrors iOS Apple JSC's `setObject(_, forKeyedSubscript:)` pattern.
157
127
  //
158
- // Version pin: this Expo SDK 55 build uses Kotlin 2.1.20, which can read
159
- // metadata up to 2.2.0. dokar3 1.0.1+ ships classes with metadata 2.3.0
160
- // (compiled with Kotlin 2.3.x) and is unreadable here. 1.0.0-alpha13 is
161
- // the last release compiled with Kotlin 2.0 (metadata 2.0.0) — its API
162
- // (`QuickJs.create`, `evaluate`, `function` extension) matches 1.0.5 1:1.
163
- // Bump only when the host Kotlin compiler clears 2.3.0 metadata.
164
- quickJsKotlinAar 'io.github.dokar3:quickjs-kt-android:1.0.0-alpha13'
165
- implementation files(layout.buildDirectory.file('quickjs-kotlin/quickjs-alpha13.jar')).builtBy(extractQuickJsClasses)
128
+ // 1.0.15 is compiled with Kotlin 2.4.10. The crust config plugin raises the
129
+ // host to Kotlin 2.3.0, which reads one metadata version ahead. The AAR ships
130
+ // its own 16 KB-aligned JNI libraries and R8 keep rules.
131
+ implementation 'io.github.dokar3:quickjs-kt-android:1.0.15'
166
132
 
167
133
  // OkHttp for fetch / WebSocket — already used elsewhere in MentraOS;
168
134
  // pinned here so the gradle plugin doesn't downgrade us.
@@ -175,8 +141,8 @@ dependencies {
175
141
 
176
142
  // Kotlin coroutines: dokar3's `evaluate()` is suspend; we bridge it via
177
143
  // `runBlocking(dispatcher)` from the per-miniapp single-thread executor.
178
- implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1'
179
- implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1'
144
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.11.0'
145
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.11.0'
180
146
  }
181
147
 
182
148
  // Notification lifecycle tests run against Android APIs without a device.
@@ -184,3 +150,12 @@ dependencies {
184
150
  testImplementation 'junit:junit:4.13.2'
185
151
  testImplementation 'org.robolectric:robolectric:4.11.1'
186
152
  }
153
+
154
+ // A desktop JVM cannot load the Android QuickJS library, so local unit tests
155
+ // run the same QuickJS build through its desktop JVM artifact.
156
+ configurations.matching { it.name.endsWith('UnitTestRuntimeClasspath') }.configureEach {
157
+ resolutionStrategy.dependencySubstitution {
158
+ substitute(module('io.github.dokar3:quickjs-kt-android'))
159
+ .using(module('io.github.dokar3:quickjs-kt-jvm:1.0.15'))
160
+ }
161
+ }
@@ -293,10 +293,10 @@ class JSCRuntime private constructor(private val appContext: Context) {
293
293
  runBlocking {
294
294
  installGlobals(qjs, packageName)
295
295
  if (bundle.isNotEmpty()) {
296
- qjs.evaluate<Any?>(bundle, filename = "mentrajs:startup.js")
296
+ qjs.evaluateForEffect(bundle, filename = "mentrajs:startup.js")
297
297
  }
298
298
  if (miniappJs.isNotEmpty()) {
299
- qjs.evaluate<Any?>(miniappJs, filename = "mentrajs:miniapp.js")
299
+ qjs.evaluateForEffect(miniappJs, filename = "mentrajs:miniapp.js")
300
300
  }
301
301
  }
302
302
  Log.i(TAG, "spawned $packageName")
@@ -420,7 +420,7 @@ class JSCRuntime private constructor(private val appContext: Context) {
420
420
  record.executor.submit {
421
421
  runBlocking {
422
422
  try {
423
- record.qjs.evaluate<Any?>(
423
+ record.qjs.evaluateForEffect(
424
424
  "globalThis.__deliverTimer && globalThis.__deliverTimer($token);",
425
425
  filename = "mentrajs:timer-$token.js",
426
426
  )
@@ -511,7 +511,7 @@ class JSCRuntime private constructor(private val appContext: Context) {
511
511
  try {
512
512
  val source = "globalThis.__deliver(${jsStringLiteral(envelopeJson)});"
513
513
  runBlocking {
514
- record.qjs.evaluate<Any?>(source, filename = "mentrajs:deliver.js")
514
+ record.qjs.evaluateForEffect(source, filename = "mentrajs:deliver.js")
515
515
  }
516
516
  } catch (e: Throwable) {
517
517
  failure = e
@@ -590,6 +590,15 @@ class JSCRuntime private constructor(private val appContext: Context) {
590
590
 
591
591
  // ------------------------------------------------------------------
592
592
 
593
+ /**
594
+ * Evaluate for side effects. A completion value is never converted to
595
+ * Kotlin: quickjs-kt 1.0.15 hangs converting a Set, Map or array that
596
+ * contains itself, and miniapp code chooses its bundle's last value.
597
+ */
598
+ private suspend fun QuickJs.evaluateForEffect(source: String, filename: String) {
599
+ evaluate<Any?>("$source\n;undefined", filename = filename)
600
+ }
601
+
593
602
  private fun parseArgsEnvelope(argsJson: String): Pair<List<Any?>, String?> {
594
603
  return try {
595
604
  if (argsJson.startsWith("{")) {
@@ -0,0 +1,87 @@
1
+ package com.mentra.crust.jsc
2
+
3
+ import com.dokar.quickjs.QuickJs
4
+ import com.dokar.quickjs.QuickJsException
5
+ import com.dokar.quickjs.binding.function
6
+ import java.util.concurrent.Executors
7
+ import kotlinx.coroutines.Dispatchers
8
+ import kotlinx.coroutines.runBlocking
9
+ import kotlinx.coroutines.withTimeout
10
+ import org.junit.Assert.*
11
+ import org.junit.Test
12
+
13
+ /**
14
+ * Runs the real QuickJS JNI library (through the desktop JVM artifact, see
15
+ * build.gradle) the way [JSCRuntime] uses it: one instance per miniapp, Kotlin
16
+ * bindings called from JS, and independent close orders.
17
+ */
18
+ class QuickJsLifecycleTest {
19
+ private fun create() = QuickJs.create(Dispatchers.Unconfined)
20
+
21
+ @Test fun `closing one instance keeps another instance's callbacks working`() = runBlocking {
22
+ var calls = 0
23
+ val survivor = create()
24
+ survivor.function("hostCallback") { calls++; 42 }
25
+ val other = create()
26
+ assertEquals(42, survivor.evaluate<Int>("hostCallback()"))
27
+ other.close()
28
+ withTimeout(1000) { assertEquals(42, survivor.evaluate<Int>("hostCallback()")) }
29
+ assertEquals(2, calls)
30
+ repeat(20) {
31
+ create().close()
32
+ assertEquals(42, survivor.evaluate<Int>("hostCallback()"))
33
+ }
34
+ val workers = Executors.newFixedThreadPool(4)
35
+ try {
36
+ (1..40).map { workers.submit { create().close() } }.forEach { it.get() }
37
+ assertEquals(42, survivor.evaluate<Int>("hostCallback()"))
38
+ } finally {
39
+ workers.shutdownNow()
40
+ }
41
+ survivor.close()
42
+ val fresh = create()
43
+ fresh.function("hostCallback") { 7 }
44
+ assertEquals(7, fresh.evaluate<Int>("hostCallback()"))
45
+ fresh.close()
46
+ val older = create()
47
+ val newer = create()
48
+ newer.function("hostCallback") { 9 }
49
+ older.close()
50
+ assertEquals(9, newer.evaluate<Int>("hostCallback()"))
51
+ newer.close()
52
+ }
53
+
54
+ @Test fun `a binding exception is a catchable JS Error carrying the message`() = runBlocking {
55
+ val qjs = create()
56
+ qjs.function("__dispatch") { throw MentraJSDispatchError("INVALID_ARGS", "iface") }
57
+ val caught = qjs.evaluate<String>(
58
+ "try { __dispatch(); 'no throw' } catch (e) { (e instanceof Error) + '|' + e.message }",
59
+ )
60
+ assertEquals("true|INVALID_ARGS: iface", caught)
61
+ qjs.close()
62
+ }
63
+
64
+ @Test fun `non-ASCII strings cross the bridge unchanged`() = runBlocking {
65
+ val text = "héllo 😀 中文 \u0000 end"
66
+ var received: String? = null
67
+ val qjs = create()
68
+ qjs.function("hostText") { text }
69
+ qjs.function("hostEcho") { args -> received = args[0] as String; args[0] }
70
+ assertEquals(text, qjs.evaluate<String>("hostEcho(hostText())"))
71
+ assertEquals(text, received)
72
+ qjs.close()
73
+ }
74
+
75
+ @Test fun `unusual thrown values fail as exceptions, not crashes`() = runBlocking {
76
+ val qjs = create()
77
+ for (source in listOf("throw undefined", "throw null", "throw new Error('%s%n%s%n')")) {
78
+ try {
79
+ qjs.evaluate<Any?>(source)
80
+ fail("$source did not throw")
81
+ } catch (_: QuickJsException) {
82
+ }
83
+ assertEquals(2, qjs.evaluate<Int>("1 + 1"))
84
+ }
85
+ qjs.close()
86
+ }
87
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentra/crust",
3
- "version": "3.3.0-dev.656",
3
+ "version": "3.3.0-dev.658",
4
4
  "description": "Mentra Native Module",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  "license": "Apache-2.0",
36
36
  "homepage": "https://github.com/Mentra-Community/MentraOS/tree/dev/mobile/modules/crust#readme",
37
37
  "dependencies": {
38
- "@mentra/jspolyfill": "3.3.0-dev.656"
38
+ "@mentra/jspolyfill": "3.3.0-dev.658"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@expo/config-plugins": ">=8.0.0",
@@ -14,6 +14,8 @@ import { type ConfigPlugin } from "expo/config-plugins";
14
14
  * both fails the release build with duplicate classes)
15
15
  * - core-library desugaring (crust's AAR metadata requires it of embedding
16
16
  * apps — the Nav SDK uses newer core libs)
17
+ * - Kotlin 2.3.0 or newer, with the root Kotlin Gradle plugin pinned to it
18
+ * (crust's QuickJS library, quickjs-kt 1.0.15, is compiled with Kotlin 2.4)
17
19
  * - a generated MainApplication process guard so the notification-listener
18
20
  * process never initializes React Native
19
21
  * - iOS Mapbox Swift Package products and the Crust build-order dependency
@@ -21,6 +21,8 @@ const withMapboxNavIos_1 = __importDefault(require("./withMapboxNavIos"));
21
21
  * both fails the release build with duplicate classes)
22
22
  * - core-library desugaring (crust's AAR metadata requires it of embedding
23
23
  * apps — the Nav SDK uses newer core libs)
24
+ * - Kotlin 2.3.0 or newer, with the root Kotlin Gradle plugin pinned to it
25
+ * (crust's QuickJS library, quickjs-kt 1.0.15, is compiled with Kotlin 2.4)
24
26
  * - a generated MainApplication process guard so the notification-listener
25
27
  * process never initializes React Native
26
28
  * - iOS Mapbox Swift Package products and the Crust build-order dependency
@@ -20,12 +20,50 @@ const MAPBOX_REPO = [
20
20
  " }",
21
21
  " }",
22
22
  ].join("\n");
23
+ // quickjs-kt 1.0.15 is compiled with Kotlin 2.4, and a Kotlin compiler reads
24
+ // metadata one version ahead. 2.3.0 is the newest 2.3 release Expo SDK 55's
25
+ // root plugin maps to a KSP version.
26
+ const MIN_KOTLIN_VERSION = "2.3.0";
27
+ // The template's unversioned classpath entry resolves to the Kotlin Gradle
28
+ // plugin React Native's Gradle plugin depends on (2.1.20 on RN 0.83), whatever
29
+ // `android.kotlinVersion` says; Expo fixes that only in SDK 58
30
+ // (expo/expo#49668). SDK 56 also never copies the property into Expo's catalog,
31
+ // so pin both the compiler and the root `kotlinVersion` to the property itself.
32
+ const UNVERSIONED_KOTLIN_PLUGIN = "classpath('org.jetbrains.kotlin:kotlin-gradle-plugin')";
33
+ const PINNED_KOTLIN_PLUGIN = `classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:\${findProperty('android.kotlinVersion')}")`;
34
+ const KOTLIN_VERSION_MARKER = "kotlinVersion from android.kotlinVersion (injected by @mentra/crust)";
35
+ const EXPO_ROOT_PROJECT = 'apply plugin: "expo-root-project"';
36
+ function isOlderVersion(version, minimum) {
37
+ const actual = version.split(".").map(Number);
38
+ const required = minimum.split(".").map(Number);
39
+ for (let i = 0; i < required.length; i++) {
40
+ if ((actual[i] ?? 0) !== required[i])
41
+ return (actual[i] ?? 0) < required[i];
42
+ }
43
+ return false;
44
+ }
45
+ function withCrustKotlinVersion(config) {
46
+ return (0, config_plugins_1.withGradleProperties)(config, (cfg) => {
47
+ const property = cfg.modResults.find((item) => item.type === "property" && item.key === "android.kotlinVersion");
48
+ if (property?.type !== "property") {
49
+ cfg.modResults.push({ type: "property", key: "android.kotlinVersion", value: MIN_KOTLIN_VERSION });
50
+ }
51
+ else if (isOlderVersion(property.value, MIN_KOTLIN_VERSION)) {
52
+ property.value = MIN_KOTLIN_VERSION;
53
+ }
54
+ return cfg;
55
+ });
56
+ }
23
57
  const PROTOBUF_EXCLUDE = "exclude group: 'com.google.protobuf', module: 'protobuf-javalite'";
24
58
  const NOTIFICATION_PROCESS_GUARD = "crust: skip React Native in notification process";
25
59
  const NOTIFICATION_CONFIG_GUARD = "crust: skip Expo lifecycle in notification process";
26
60
  function withCrustProjectGradle(config) {
27
61
  return (0, config_plugins_1.withProjectBuildGradle)(config, (cfg) => {
28
62
  let gradle = cfg.modResults.contents;
63
+ gradle = gradle.replace(UNVERSIONED_KOTLIN_PLUGIN, PINNED_KOTLIN_PLUGIN);
64
+ if (!gradle.includes(KOTLIN_VERSION_MARKER)) {
65
+ gradle = gradle.replace(EXPO_ROOT_PROJECT, `// ${KOTLIN_VERSION_MARKER}\next.kotlinVersion = findProperty('android.kotlinVersion')\n${EXPO_ROOT_PROJECT}`);
66
+ }
29
67
  // Mapbox Downloads repo, inserted at the top of allprojects.repositories.
30
68
  if (!gradle.includes(MAPBOX_REPO_MARKER)) {
31
69
  const reposMatch = gradle.match(/allprojects\s*\{[\s\S]*?repositories\s*\{/);
@@ -129,6 +167,7 @@ function withNotificationProcessGuard(config) {
129
167
  });
130
168
  }
131
169
  const withCrustAndroidBuildContract = (config) => {
170
+ config = withCrustKotlinVersion(config);
132
171
  config = withCrustProjectGradle(config);
133
172
  config = withCrustAppGradle(config);
134
173
  return withNotificationProcessGuard(config);
@@ -1,6 +0,0 @@
1
- -keep,allowoptimization class com.dokar.quickjs.QuickJs { *; }
2
- -keep,allowoptimization class com.dokar.quickjs.QuickJsException { *; }
3
- -keep,allowoptimization class com.dokar.quickjs.binding.JsProperty { *; }
4
- -keep,allowoptimization class com.dokar.quickjs.binding.JsFunction { *; }
5
- -keep,allowoptimization class com.dokar.quickjs.binding.JsObject { *; }
6
- -keep,allowoptimization class kotlin.UByteArray
@@ -1,45 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Compile and test real JNI on Linux; run only when native builds are authorized."""
3
- import os
4
- from pathlib import Path
5
- import subprocess
6
- import tempfile
7
- import zipfile
8
-
9
- android = Path(__file__).resolve().parents[1]
10
- cache = Path(os.environ.get("GRADLE_USER_HOME", str(Path.home() / ".gradle"))) / "caches/modules-2/files-2.1"
11
-
12
-
13
- def artifact(group, name, version, extension="jar"):
14
- # Classifier artifacts such as -sources.jar share the version directory.
15
- matches = [path for path in (cache / group / name / version).glob(f"*/*.{extension}")
16
- if not path.stem.endswith(("-sources", "-javadoc"))]
17
- if not matches:
18
- raise SystemExit(f"Missing cached {group}:{name}:{version}; resolve Android dependencies first.")
19
- return matches[0]
20
-
21
-
22
- with tempfile.TemporaryDirectory(prefix="mentra-quickjs-test-") as directory:
23
- output = Path(directory)
24
- native = output / "native"
25
- subprocess.run(["cmake", "-S", str(android / "src/main/cpp/quickjs"), "-B", str(native),
26
- "-G", "Ninja", "-DCMAKE_BUILD_TYPE=Release"], check=True)
27
- subprocess.run(["cmake", "--build", str(native), "-j", "2"], check=True)
28
- aar = artifact("io.github.dokar3", "quickjs-kt-android", "1.0.0-alpha13", "aar")
29
- with zipfile.ZipFile(aar) as archive:
30
- (output / "quickjs.jar").write_bytes(archive.read("classes.jar"))
31
- runtime = [output / "quickjs.jar",
32
- artifact("org.jetbrains.kotlin", "kotlin-stdlib", "2.1.20"),
33
- artifact("org.jetbrains.kotlinx", "kotlinx-coroutines-core-jvm", "1.8.1"),
34
- artifact("androidx.annotation", "annotation-jvm", "1.9.1"),
35
- artifact("org.jetbrains", "annotations", "23.0.0")]
36
- compiler = runtime + [artifact("org.jetbrains.kotlin", "kotlin-compiler-embeddable", "2.1.20"),
37
- artifact("org.jetbrains.intellij.deps", "trove4j", "1.0.20200330")]
38
- classpath = os.pathsep.join(map(str, runtime))
39
- subprocess.run(["java", "-cp", os.pathsep.join(map(str, compiler)),
40
- "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler", "-no-stdlib", "-no-reflect",
41
- "-jvm-target", "17", "-classpath", classpath, "-d", str(output / "classes"),
42
- str(android / "src/testNative/QuickJsLifecycleTest.kt")], check=True)
43
- subprocess.run(["java", f"-Djava.library.path={native}", "-cp",
44
- str(output / "classes") + os.pathsep + classpath,
45
- "com.mentra.crust.jsc.QuickJsLifecycleTestKt"], check=True, timeout=30)
@@ -1,20 +0,0 @@
1
- cmake_minimum_required(VERSION 3.22.1)
2
- project(mentra_quickjs C)
3
- set(CMAKE_C_STANDARD 99)
4
- file(READ "engine/VERSION" QUICKJS_VERSION)
5
- string(STRIP "${QUICKJS_VERSION}" QUICKJS_VERSION)
6
- file(GLOB JNI_SOURCES CONFIGURE_DEPENDS "jni/*.c" "jni/mapping/*.c")
7
- add_library(quickjs SHARED
8
- engine/cutils.c engine/libbf.c engine/libregexp.c engine/libunicode.c
9
- engine/quickjs.c common/quickjs_version.c ${JNI_SOURCES})
10
- target_include_directories(quickjs PRIVATE engine common c-vector jni jni/mapping)
11
- target_compile_definitions(quickjs PRIVATE CONFIG_BIGNUM CONFIG_VERSION="${QUICKJS_VERSION}")
12
- if(ANDROID)
13
- target_compile_definitions(quickjs PRIVATE CONFIG_ANDROID)
14
- target_link_libraries(quickjs PRIVATE log m)
15
- target_link_options(quickjs PRIVATE "-Wl,-z,max-page-size=16384")
16
- else()
17
- find_package(JNI REQUIRED)
18
- target_include_directories(quickjs PRIVATE ${JNI_INCLUDE_DIRS})
19
- target_link_libraries(quickjs PRIVATE pthread m)
20
- endif()
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright 2015 Anton Lopyrev
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
@@ -1,30 +0,0 @@
1
- # QuickJS JNI lifetime backport
2
-
3
- The Kotlin API remains on `io.github.dokar3:quickjs-kt-android:1.0.0-alpha13` to
4
- preserve compatibility with Kotlin 2.1.20. Crust builds this native source for
5
- Android. A private build-input configuration extracts the original AAR's
6
- `classes.jar`. Crust embeds this JAR, preserving Kotlin metadata, while only its
7
- source-built JNI library reaches consuming apps. `quickjs-consumer-rules.pro` in
8
- the Android module preserves the original AAR's R8 rules so JNI class names remain
9
- valid in minified builds. Do not use `pickFirst` to choose between libraries.
10
-
11
- Source provenance (licenses accompany each source):
12
-
13
- - `jni/`, `common/`: quickjs-kt commit `d2fefdc451678d09bbef5526c3b00f12e41cd5cf`.
14
- - `engine/`: Bellard QuickJS commit `36911f0d3ab1a4c190a4d5cbe7c2db225a455389`, alpha13's submodule pin; only required build inputs.
15
- - `c-vector/`: alpha13 submodule pin `774773d4cb1e66dd736e90e7f482d4f22af464c6`.
16
-
17
- Upstream source changes are confined to `jni/jni_globals.{c,h}` and
18
- `jni/quickjs_jni.c`. They backport the shared-resource lifetime fix from
19
- [4a003f6](https://github.com/dokar3/quickjs-kt/commit/4a003f64b1d5e608df1768e6c1a743b603434e10).
20
- A mutex synchronizes VM initialization, instance counts and final cache disposal. Shared caches remain valid until the final instance closes.
21
-
22
- Shared-resource lifetime is unconditional; there is no setting or native toggle.
23
- A native Android rebuild is required. iOS does not use this JNI library.
24
-
25
- Run the Linux integration test with
26
- `python3 mobile/modules/crust/android/scripts/test-quickjs-lifecycle.py` from the
27
- repository root. It requires JDK 17, CMake/Ninja and cached Gradle dependencies.
28
- It compiles the real JNI library and exercises Kotlin callbacks across both
29
- close orders, sequential/concurrent teardown and clean restart. Plain JavaScript
30
- arithmetic is insufficient: this regression requires a callback into Kotlin.