gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.36k stars 547 forks source link

Java(jmod) support? #2425

Open chengenzhao opened 6 years ago

chengenzhao commented 6 years ago

Short info header:

Hi, recently Java provide a new way to generate jre, which is jmod http://openjdk.java.net/jeps/261 and is it possible to provide jmod format support? thus all jvm languages could use gfx-rs to create games I think the way to do this is similar to JavaFX project https://github.com/javafxports/openjdk-jfx

kvark commented 6 years ago

I have no idea what you are talking about. Can you provide a gist of the links involved? Can java link with Rust/C libraries now? Or can it compile with LLVM?

chengenzhao commented 6 years ago

I have no idea what you are talking about. Can you provide a gist of the links involved? Can java link with Rust/C libraries now? Or can it compile with LLVM?

Hi, yes, Java could link Rust&C libs now, so basically the way to do it is like this: https://github.com/jni-rs/jni-rs tutorial: https://docs.rs/jni/0.10.2/jni/ so basically what we suggest is to expose gfx-rs api to jvm and then wrap it as a jmod using jmod command in java/home/bin/ directory thus when we wants to use it, we could create our own runtime and put rust crate(gfx-rs) in the runtime and then all other languages including Java could use gfx-rs as its own api

The other way is to use graal which could transform llvm bitcode into bytecode but I think that way is a little bit slow since there are transformations in the runtime

kvark commented 6 years ago

@chengenzhao this is very interesting, thank you for the info! I think it would be great to have, but the only way to get there is to have somebody (knowledgeable of Java) to lead the way.

vitvakatu commented 6 years ago

Hi @kvark, hello @chengenzhao To be honest, I'm not quite following the idea. JMOD files replace plain-old JARs when you need incorporate some native code with your Java. We can, indeed, provide Java bindings for gfx-rs, but it's possible right now, even without jmod. Jmod doesn't bring any new opportunity here.

In my opinion, it must be the part of gfx-portability initiative, because it's much easier to use existing C-API instead of wrapping Rust code in C.

kvark commented 6 years ago

@vitvakatu good point! If Java has any access to Vulkan, they can just run with gfx-portability.