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.
This commit is contained in:
@@ -12,27 +12,20 @@
|
||||
// --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
|
||||
//
|
||||
// Cross-compile test (compile-only): see tests/cross_compile.sh's
|
||||
// `android | examples/ffi-jni-main-01-emit.sx` tuple. APK creation
|
||||
// itself isn't exercised by cross_compile.sh — only that the example
|
||||
// lowers and links cleanly with `#jni_main` in scope.
|
||||
|
||||
#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
|
||||
// empty body intentionally has zero methods — slice 2 just verifies the
|
||||
// .java/.dex pipeline; `onCreate` overriding lands once slice 4 wires
|
||||
// `RegisterNatives` so the `sx_<method>` symbols actually resolve.
|
||||
SxApp :: #jni_main #jni_class("co/swipelab/sxjnimain/SxApp") { }
|
||||
// `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; }
|
||||
|
||||
// Android NDK entry symbol — kept as a 3-line trampoline so this example
|
||||
// passes `--target android` builds via `tests/cross_compile.sh`.
|
||||
android_main :: (app: *void) {
|
||||
inline if OS == .android {
|
||||
main();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user