Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Hello World Java Polyglot (github.com/burntmonkey)
15 points by yarg on March 7, 2023 | hide | past | favorite | 4 comments
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.



Readme says it doesn't work?

'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.'


It works fine as a jar file, native-image produces an executable that can run without an external JRE.

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.


That is pretty slick !!


It's not perfect, but I was surprised how easy it was to get it up and running.

It 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: