Skip to content

generate jni-wrapping code from Rust#473

Draft
milyin wants to merge 26 commits into
mainfrom
zenoh-flat-jni
Draft

generate jni-wrapping code from Rust#473
milyin wants to merge 26 commits into
mainfrom
zenoh-flat-jni

Conversation

@milyin
Copy link
Copy Markdown
Contributor

@milyin milyin commented May 25, 2026

Use https://github.com/milyin/prebindgen utility to make JNI code from simple flat rust zenoh wrapping library

milyin and others added 26 commits May 23, 2026 17:13
BFS from each required-but-unresolved type through struct fields, enum
variants, generic args, and impl Fn args, surfacing transitively
unresolved entries that propagate_required cannot reach (because subs
edges don't exist past an unresolved parent). Without this, a missing
declaration in build.rs for a type only referenced as a field of another
unresolved struct went unreported.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
.method() is a namespace declaration — every #[prebindgen] fn must
be assigned to a typed handle, data class, enum, or kotlin_package.
There is no third "orphan" bucket, so JNIOrphaned was always emitted
empty and the duplicate declared_function_names helper just repeated
the PrebindgenExt::declared_functions trait method.

- delete write_jni_orphaned, jni_orphaned_class_name, the stale
  generated JNIOrphaned.kt file
- rename render_jni_orphaned_source -> render_jni_package_source,
  drop the now-redundant include_only_promoted / wrap_in_object /
  declared / class_name params
- drop declared_function_names; render_jni_native_source now takes
  &HashSet<syn::Ident> from declared_functions() directly

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Replace the five scattered self.qualify_emitted_type() calls (build_input_fn,
build_output_fn, opaque_handle_input, build_handle_destructor_items,
option_input) with a single AST visitor pass applied once at write time.

The previous design qualified only at specific emit sites — each new emit
site had to remember the call. emit_into_dispatcher missed it, so the
impl-Into dispatcher body emitted bare KeyExpr/ZKeyExpr references that
failed to resolve in the binding crate's scope.

Architecture:
- New PrebindgenExt::post_process_item(item: &mut syn::Item) trait hook
  (default no-op), invoked by write_rust on every emitted item.
- JniExt implements it via qualify_item, which runs QualifyEmittedTypes —
  a syn::visit_mut::VisitMut that walks the full AST (signatures, generic
  args, type ascriptions in let bindings, *mut/*const in cast expressions)
  and prefixes every bare single-segment Type::Path matching a registered
  source-module name with source_module.
- option_input no longer takes &JniExt; the body uses the bare t1 token
  and the post-emit visitor qualifies it later.

Also fixes the pre-existing TypeEntry field-name drift in
final_invariant_reports_unresolved_field_of_unresolved_struct.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant