prebindgen_jni/lib.rs
1//! JNI / Kotlin language adapter — the [`JniGenBuilder`] back-end.
2//!
3//! Sibling of the C adapter (now the separate `prebindgen-c` crate): it implements the
4//! language-agnostic [`prebindgen_registry::Prebindgen`] trait to
5//! turn a flat `#[prebindgen]` library into a Rust file of JNI `extern "C"`
6//! wrappers plus a fan-out of generated Kotlin sources.
7//!
8//! Pipeline:
9//! 1. [`prebindgen_registry::Registry::builder`] describes a binding over a model built from
10//! `(syn::Item, SourceLocation)` (typically `source.items_all()`).
11//! 2. `Registry::write_rust` resolves every
12//! required type via a configured [`JniGenBuilder`] and writes the generated
13//! Rust bindings file.
14//! 3. `JniGenBuilder::write_kotlin` walks the resolved registry to emit the
15//! secondary Kotlin artifacts (typed-handle classes, data/enum classes,
16//! exception classes, the centralized `JNINative` holder).
17//!
18//! # Fixed-width unsigned integers
19//!
20//! JniGenBuilder exposes Rust's fixed-width unsigned scalars without narrowing their
21//! domain at the Kotlin boundary:
22//!
23//! | Rust | Kotlin surface | JNI wire |
24//! |------|----------------|----------|
25//! | `u8` | `Int` | `jint` |
26//! | `u16` | `Int` | `jint` |
27//! | `u32` | `Long` | `jlong` |
28//! | `u64` | `ULong` | `jlong` / `Long` bit pattern |
29//!
30//! Inputs for `u8`, `u16`, and `u32` are range-checked and report a
31//! [`JniBindingError`] through the generated binding-error handler. `u64`
32//! uses Kotlin's bit-preserving `ULong.toLong()` / `Long.toULong()` bridge.
33//! These mappings compose through nullable/result outputs, generated data
34//! classes, callbacks, const getters, and supported output collections.
35
36pub mod jni;
37#[cfg(test)]
38mod test_util;
39pub(crate) mod util;
40
41pub use jni::{
42 box_jboolean, box_jbyte, box_jchar, box_jdouble, box_jfloat, box_jint, box_jlong, box_jshort,
43 decode_byte_array, decode_string, encode_byte_array, encode_string, matching, null_byte_array,
44 null_string, CachedIfaceMethod, ClassDecl, ConstDecl, ConvertDecl, ConvertSourceDecl,
45 DataClassDecl, Declarations, EnumClassDecl, ExpandDecl, ExpandParamDecl, ExpandReturnDecl,
46 FieldsDecl, FunctionDecl, IgnoreDecl, JniBindingError, JniGen, JniGenBuilder, PackageDecl,
47 PtrClassDecl, SealedClassDecl, VariantDecl,
48};
49// Kotlin emission types now live in the standalone `kotlin-codegen` crate;
50// re-exported here so the public `lang::` surface is unchanged (`KotlinFile`
51// aliases the model's `KtFile`).
52pub use kotlin_codegen::KtFile as KotlinFile;
53pub use kotlin_codegen::WriteKotlinError;