Easily generate type-safe bindings for calling Java APIs from Rust.
- Generates fully safe Rust bindings to call Java APIs.
- Supports both static and nonstatic methods and fields.
- Constant fields (
static final) are converted to Rust constants. - Allows implementing Java interfaces or subclassing Java classes using generated Java proxies. Useful for callback/listener APIs. It generates:
- a Rust trait matching the Java interface/class for you to implement
- a proxy Java class where all methods call into Rust
- Rust glue to receive and forward calls to the Rust trait
- Flexible configuration based on glob rules matching Java classes. All matching rules are merged.
- (NOT IMPLEMENTED YET) The ability to use pre-generated binding sources instead of having to rebind whole ABIs
- (NOT IMPLEMENTED YET) Generate stubbed JARs that you can include in your source code without issues (Always read the applicable licenses first, though)
- (NOT FULLY WRITTEN YET) Actual documentation on how to generate bindings
This project started out as a fork of java-spaghetti-gen, which is originally a fork jni-bindgen.
java-spaghetti-gen took the route of generating "mini-bindings", that are tailored specifically to your project, and can be embeded within your crate. This design, however, is not suited for large-scale bindings that are intended to be used as/in libraries. java-oxide partially goes back to the design of jni-bindgen, it generates crates with bindings for a whole java API (or multiple).
A list of differences from java-spaghetti-gen are:
- Configuration using TOML instead of YAML, to better fit in with the rest of the rust ecosystem.
- Generated code uses absolute paths (
crate::...) instead of relative paths (super::...), because relative path chains can be confusing to read. - (NOT IMPLEMENTED YET) Code is generated as multiple files following the package layout of the source JARs.
- (NOT IMPLEMENTED YET) Generated code does use some macros, cause it's easier to read that way (at least to me).
- EVEN MORE modernized rust and updated dependencies.
java-spaghettiis stale, and slightly broken on newer rust versions. - (NOT IMPLEMENTED YET) The ability to use pre-generated binding sources instead of having to rebind whole ABIs
- Better logging and error reporting
A list of differences from jni-bindgen are listed in java-spaghetti-gen's README.
- Switch back to a
.tomlconfiguration format - Allow Glob Paths as inputs
- Add external pre-generated binding sources
- Fix code gen issues
- Use absolute paths (
crate::...) - Use SOME macros to improve readability
- "Correctly" format generated code
- Report to user what missing classes are causing incomplete code generations
- Use absolute paths (
- Use
ristretto_classfileinstead ofcafebabe - Implement stub generation
- Actually do documentation
Licensed under the MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)