Show HN: Hello World Java Polyglot (github.com)
I wanted to see how much simpler native code integration has become with GraalVM's polyglot, when compared to JNI.
It's less than 100 lines all up (including the POM).
(I feel kinda stupid posting a "hello world" to HN, but this is a hell of an improvement.)
Linux only at the moment.
4 comments
[ 3.0 ms ] story [ 16.0 ms ] threadIt should/might be possible to make it produce a platform independent and cross compile it - but there's a bit of toolchain fuckery that I haven't yet looked into.
Graal supports LLVM IR both from the front-end and the back-end. Using that I think that it should be possible to use the frontend to produce a cross platform jar, and the backend to compile the whole thing back down to LLVM IR.
Then that can be used with LLVM's cross compiling capabilities to produce both Linux and Windows binaries.
'mvn install works with $JAVA_HOME set to a Graal JDK (tested with 22.3).
--native-image works with the current development build (23.0.0), but-- bugs out with the current release version.
native-image doesn't yet do what it should.'
I'm still trying to figure out how to embed the native dependency libraries into that executable.
You can build the binary (with the dev version - 23.0.0) and it will run from the target directory (because the dependencies are available in ./resources/languages/llvm/native/lib), but it won't run from anywhere else.
I'm still trying to figure out what's missing from my native-image build command.
But if you're happy with just running it as a (platform dependent) jar, there's no problem.