4 ms·
It would be at least as important to be able to call Java from Rust. Does anyone know if that's hard?
by tormeh 12y ago
It would be at least as important to be able to call Java from Rust. Does anyone know if that's hard?
- jbooth 12y agoIt's probably possible to create a situation where a JVM process calls Rust code which then calls back to some Java function, if you're inclined to spend enough time hacking with JNI (is it possible to pass a function pointer out of JVM land?). But if you started as a native Rust process, there's no JVM runtime to call into, you'd need start that up first.
- tormeh 12y agoCan't Rust just use the OS to start a JVM?
- the_why_of_y 12y agoIt's definitely possible to bootstrap the JVM in-process but there are quite some steps to it and it requires a bunch of platform dependent code to locate and load the library via LoadLibrary(jvm.dll) / dlopen(libjvm.so). IIRC the JNI functions all have C linkage so it should be easy to do from Rust.
- AntiRush 12y agoThere's a library[1] that wraps the jni, allowing just that. I haven't tried it, but it looks featureful enough to be useful. [1] https://github.com/Monnoroch/RustJni https://github.com/Monnoroch/RustJni
- kodablah 12y agoI think the continuation of this would be a neat project. The lib starts up a JVM, it would be interesting to see a macro [1] (or will probably have to be a compiler plugin [2]) to model Java objects and make it clear the ownership of memory. 1 - http://doc.rust-lang.org/0.12.0/guide.html#macros http://doc.rust-lang.org/0.12.0/guide.html#macros 2 - http://doc.rust-lang.org/0.12.0/guide-plugin.html http://doc.rust-lang.org/0.12.0/guide-plugin.html