Files
sx/examples/ffi-jni-main-01-emit.sx
agra 5648337749 ffi #jni_main: accept #jni_main as Android entry; modern smoke shape
Loosens lower.zig's `checkRequiredEntryPoints` to accept either a
`#jni_main #jni_class("...")` decl OR the legacy `android_main`
trampoline. The diagnostic now shows both options when neither is
present.

Updates the slice 2 smoke (`examples/ffi-jni-main-01-emit.sx`) to
express the modern shape — drops `android_main`, declares
`Bundle :: #foreign #jni_class("android/os/Bundle")`, and overrides
`onCreate :: (self: *Self, b: *Bundle) { }` inside the #jni_main class.
The emitted Java now correctly declares `void onCreate(Bundle b)` as
@Override + a matching `private native void sx_onCreate(Bundle b)`
delegate, verified via dexdump.

Full retirement of `android_main` (deleting native_app_glue from the
Android link path, dropping `AndroidPlatform.run_frame_loop`, migrating
chess/EGL demo to the Java-driven lifecycle) is multi-slice rework
and stays as follow-up.
2026-05-20 14:50:21 +03:00

32 lines
1.4 KiB
Plaintext

// `#jni_main` pipeline slice 2 (PLAN-FFI.md): the compiler renders a
// `.java` source for a `#jni_main #jni_class("...")` declaration, runs
// `javac` + `d8`, and bundles `classes.dex` into the APK.
//
// Slice 2 only wires the plumbing — the manifest still points at
// `android.app.NativeActivity`, so the user's class isn't loaded at
// runtime. Slice 3 (manifest synthesis) and slice 4 (RegisterNatives)
// land in follow-up commits.
//
// Build to inspect APK contents (requires Android SDK + JDK):
// /Users/agra/projects/sx/zig-out/bin/sx build --target android \
// --apk /tmp/sxjnimain.apk --bundle-id co.swipelab.sxjnimain \
// -o /tmp/libsxjnimain.so examples/ffi-jni-main-01-emit.sx
// unzip -l /tmp/sxjnimain.apk | grep classes.dex
#import "modules/std.sx";
#import "modules/compiler.sx";
// `*Bundle` resolves through the class registry to `android.os.Bundle`
// in the emitted Java — needed for `onCreate`'s @Override to match
// NativeActivity's superclass signature.
Bundle :: #foreign #jni_class("android/os/Bundle") { }
// `#jni_main` flags this as the launchable Android Activity class. The
// `onCreate` body is empty for now — slice 4 wires `RegisterNatives`
// so the `sx_onCreate` native delegate actually binds to a sx-side fn.
SxApp :: #jni_main #jni_class("co/swipelab/sxjnimain/SxApp") {
onCreate :: (self: *Self, b: *Bundle) { }
}
main :: () -> s32 { 0; }