Skip to content
MaulingMonkey edited this page Jan 11, 2020 · 1 revision

There are three possible sides to this.

Rust builds Java

I'm currently handling this via my jerk build script / metabuild crate. This doesn't play well with platform specific compilation though, and build scripts are annoying to write, so I'm quite tempted to try and have proc macros actually cause Java code to be compiled. Since Rust doesn't export rich type metadata, and Java's compilers wouldn't know what to do with it even if it did, my approach is to have Java exclusively declare JVM types. Bonus: this avoids any compilation cycles.

Java calls Rust

Rust should be able to implement Java native methods, without resorting to unsafe, soundly. As JNI method mangling doesn't include return types in the function signature, this means we must instead resort to reading the Java metadata for verification. This also potentially allows much nicer error reporting than random link failures if you typo a class name.

Rust calls Java

Rust can call into Java methods via jni-bindgen generated crates. The big up front approach suffers from poor scaling and iteration times, however, and doesn't play nicely with importing user defined Java code. The ideal was to make types sharable between crates, but that seems like a relatively niche use case - and a poorly served one at that.

Clone this wiki locally