rust-diplomat / diplomat

Experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code
https://rust-diplomat.github.io/book/
Other
480 stars 45 forks source link

panama-backend - basic integration with jextract #499

Open jcrist1 opened 1 month ago

jcrist1 commented 1 month ago

I've implemented a basic integration with jextract for a pure java backend. This is just a baseline to start building on, that generates the C2 backend, and uses that with jextract to create the java interface to the native code. There's no code generation yet for ergonomic interfaces. I feel like enums and structs will be relatively straightforward, so once again I will start off building the wrappers for opaque type and cleanup. Also I don't actually know any java yet 🤪, but no time like the present to learn. This is as discussed in #144

Edit (2024-07-11):

I've been struggling a bit to make time for this lately as other priorities have taken precedence but I've managed another big chunk today.

I'm still missing the actual complete codegen pipeline. For the time being I'm just copy pasting generated code from the insta snapshots into the project, to test that it works, as I don't want to implement all of the features yet, and it's more convenient to just panic. Otherwise, this is starting to come together, so I'm going to add the checklist again to keep track of what I need to do still.

jcrist1 commented 1 month ago

I now manually implemented an opaque type with cleanup as well. This will be the model for the template. I also added a benchmark where I just instantiate the opaque struct because I was quite curious what the cost of GC was. With GC on the benchmark throughput more than halved. going from ~2.7M/s to 1.2 M/s. A slow down from about 350ns to ~800ns, which is just interesting. For comparison the opaque formatter in the example took ~8000ns, so this could be about a 10x speedup. All in all this seems worth pursuing and my biggest open questions for this have been resolved.