ReviewOS

also looking at this

craft-native/craft

feat(android): a JNI runtime layer, and the discipline it has to carry

#136
Merged glennmichael123 wants to merge feat/android-jni-runtime into main
2 files +864 -0
packages/zig/build.zigmodified+19-0
Changes to packages/zig/build.zig
@@ -399,6 +399,20 @@ pub fn build(b: *std.Build) void {
399399 .optimize = optimize,
400400 }),
401401 });
402 // The JNI layer, on its own artifact because nothing on the iOS side
403 // reaches it. It has no target gate: `JNIEnv` is a pointer to a table of
404 // pointers, so the tests build one out of Zig functions and run anywhere —
405 // no JVM, no emulator, no NDK. That is the whole reason the layer is shaped
406 // the way it is.
407 const jni_tests = b.addTest(.{
408 .root_module = b.createModule(.{
409 .root_source_file = b.path("src/jni_runtime.zig"),
410 .target = target,
411 .optimize = optimize,
412 }),
413 });
414 const run_jni_tests = b.addRunArtifact(jni_tests);
415
402416 ios_conformance_tests.root_module.addAnonymousImport("CraftApp.swift", .{
403417 .root_source_file = b.path("../ios/templates/CraftApp.swift"),
404418 });
@@ -1508,6 +1522,7 @@ pub fn build(b: *std.Build) void {
15081522 test_step.dependOn(&run_ios_module_tests.step);
15091523 }
15101524 test_step.dependOn(&run_ios_conformance_tests.step);
1525 test_step.dependOn(&run_jni_tests.step);
15111526 test_step.dependOn(&run_menubar_tests.step);
15121527 test_step.dependOn(&run_components_tests.step);
15131528 test_step.dependOn(&run_gpu_tests.step);
@@ -2180,6 +2195,10 @@ pub fn build(b: *std.Build) void {
21802195
21812196 const test_android_step = b.step("test:android", "Run Android tests");
21822197 test_android_step.dependOn(&run_android_tests.step);
2198 // The JNI layer rides the existing Android step rather than adding a
2199 // second one: `jni_runtime.zig` is the only way anything here reaches Java,
2200 // so a run that skipped it would not be an Android test run.
2201 test_android_step.dependOn(&run_jni_tests.step);
21832202
21842203 // Add Android tests to the main test step
21852204 test_step.dependOn(&run_android_tests.step);