#android #jni #jvm #bindings-generator #bindgen

java-spaghetti

Glue code to accompany the java-spaghetti code generator for binding to JVM APIs from Rust

3 unstable releases

new 0.2.0 Apr 5, 2024
0.1.1 Mar 25, 2024
0.1.0 Mar 19, 2024

#72 in FFI

Download history 236/week @ 2024-03-19 125/week @ 2024-03-26 197/week @ 2024-04-02

558 downloads per month

MIT/Apache

71KB
1.5K SLoC

☕️🍝 java-spaghetti

Generate type-safe bindings for calling Java APIs from Rust, so you can fearlessly make your humongous Java spaghetti code aglomeration trascend language barriers and occupy an even larger fraction of the universe's space-time.

Differences vs jni-bindgen

This project originally started out as a fork of jni-bindgen.

The main difference is the intended usage: jni-bindgen aims to generate crates with bindings for a whole Java API (such as jni-android-sys) which you then use from your crate. java-spaghetti is instead designed to generate "mini-bindings" tailored to your project, that you can embed within your crate. This has a few advantages:

  • You can generate a single bindings file for e.g. part of the Android API and your project's classes at the same time, which is better because you end up with only one copy of shared classes like java.lang.String.
  • Java APIs can get big. jni-android-sys uses one Cargo feature per class to avoid compile time bloat, which is no longer allowed on crates.io.

The full list of differences are:

  • Simplified and more consistent API.
  • You can filter which classes are generated in the TOML config.
  • Generated code uses relative paths (super::...) instead of absolute paths (crate::...), so it works if you place it in a submodule not at the crate root.
  • Generated code is a single .rs file, there's no support for spltting it in one file per class. You can still run the output through form, if you want.
  • No support for generating Cargo features per class.
  • Modernized rust, updated dependencies.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Common glue code between Rust and JNI, used in autogenerated java-spaghetti glue code.

See also the Android JNI tips documentation as well as the Java Native Interface Specification.

Dependencies

~1.5MB
~35K SLoC