rustc
Implement a JVM backend for rustc
that is capable of generating Rust data structures in JVM bytecode.
Currently, Rust only has three backends, which are LLVM, Cranelift, and GCC.
The goal of this proposal is to add a new experimental rust_codegen_jvm
backend that generates Rust internal representations into JVM bytecode, and verify the bytecode by invoking java
on generated class files. This will allow Rust to eliminate Java Native Interface (JNI)
, Java Native Access (JNA)
and Foreign Function Interface (FFI)
layers for Java application to integerating with Rust libraries / applications.
The minimum viable product will be able to turn rustc
data structures into java classes / interfaces / enums, and write the output byte arrays as class files to the location specified by --out-dir
.
The first step will only involved with class generation. Method generation is not considered to be done in this proposal due to complex generation algorithm behind methods (This includes <init>
, known as constructor method, and <clinit>
, known as static initialize method).
The second step is to validate each class files with java
program, the validation output should be other than main method not found
error.
Large
Large
Revision 1
Incubating a JVM bytecode manipulation library purely in Rust that is capable of running without Java Virtual Machine.
Currently, Rust only has three backends, which are LLVM, Cranelift, and GCC.
The goal of this proposal is to incubate a native JVM bytecode manipulation library before fully putting effort into JVM backend implementation. Incubating a native JVM bytecode manipulation library not only makes the JVM bytecode generation possible without having JVM on the machine but also paves the path for future JVM backend for rustc
.
There are several JVM bytecode manipulation libraries to take as an implementation reference:
It is important to notice that after some investigation on JVM bytecode manipulation libraries, the Objectweb ASM would be the optimal implementation reference for this proposal due to the minimal dependency on JVM itself. The only part that depends on JVM is the ClassLoader
, which is used to determine the common superclass for StackMapTable
generation. This part could be resolved by building a minimal class file analyzing application to construct a class hierarchy for common superclass lookup.
The minimum viable product will be able to generate a class file with a static main
method that is capable of being executed by JVM, and also pass the unit tests written in Objectweb ASM.
The first part of MVP is expected to be variable, for example, verifying the generation of for loop
is valid and the output is correct.
The second step is to validate the generation of basic data structures defined in Rust, e.g. struct
, enum
etc.
Notice that union
type cannot be generated into JVM bytecode due to lack of manipulation of object layout.
Large
Medium