Fork me on GitHub
#graalvm
<
2023-12-16
>
wombawomba13:12:46

I'm running into some problems compiling a polyglot app (using some truffle classes) using native-image after upgrading to GraalVM CE JDK 21:

Apply jar:file:///path/to/my/uberjar.jar!/META-INF/native-image/org.graalvm.truffle/native-image.properties
Error: Processing jar:file:///path/to/my/uberjar.jar!/META-INF/native-image/org.graalvm.truffle/native-image.properties failed
Caused by: com.oracle.svm.driver.NativeImage$NativeImageError: Failed to process ForceOnModulePath attribute: No module descriptor was not found in class-path entry: /path/to/my/uberjar.jar.
com.oracle.svm.driver.NativeImage$NativeImageError: Processing jar:file:///path/to/my/uberjar.jar!/META-INF/native-image/org.graalvm.truffle/native-image.properties failed
I had to add [org.graalvm.polyglot/polyglot "23.1.1"] and [org.graalvm.truffle/truffle-api "23.1.1"] as dependencies since graalvm jdk 21 deprecated the whole gu toolchain. If I remove these dependencies (and all my polyglot code) the native-image error disappears. /META-INF/native-image/org.graalvm.truffle/native-image.properties has the following line, which I presume is what the error refers to:
ForceOnModulePath = org.graalvm.truffle
I suspect the reason for this is that something's getting mangled/shadowed when building the uberjar (through lein uberjar). Does anybody have any idea what might be happening here and what can be done about it?

wombawomba14:12:31

The error seems to originate here: https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java#L652-L655 This code seems to look for module data for org.graalvm.truffle in my jar file. I did find what I think is the relevant file, at /META-INF/versions/21/module-info.class (it contains a bunch of strings related to truffle, and it's not there when I remove the polyglot/truffle dependencies). Any idea why the module info isn't getting picked up?

wombawomba14:12:02

FWIW there are also module files at /module-info.class, /META-INF/versions/9/module-info.class, and /META-INF/versions/11/module-info.class. None of these include any strings referring to truffle

borkdude15:12:58

you might have better luck in the native-image channel on the GraalVM slack community

wombawomba15:12:19

yeah I kind of figured, so I asked there as well 🙂

👍 1
wombawomba15:12:27

No responses yet though. I'm pretty sure this has to do with how uberjars are merged, and afaict uberjars aren't used that much with native-image outside the clojure community?

wombawomba15:12:18

Curious if it's possible to build Clojure apps without uberjars, or if there are ways to see what files are overwritten/shadowed when building uberjars using Leiningen

borkdude15:12:26

you can unzip your uberjar and check what is inside of it

wombawomba15:12:01

yeah that's what I did to find those module-info.class files – it doesn't tell me what's not there but should be, though 🙂

borkdude15:12:06

have you tried with Oracle GraalVM 21 instead of CE?

borkdude15:12:42

you can build your app without creating an uberjar, just provide the classpath

wombawomba15:12:54

I think the problem here is that the paths for the module-info.class files aren't namespaced in the jars, so they end up getting messed up when there are multiple jars with modules going into the uberjar

wombawomba15:12:10

yeah I get the same thing with Oracle GraalVM

wombawomba15:12:18

Yeah I guess I should try building a classpath.. any pointers on how to build a classpath string? AFAICT I can't just tell native-image to go look in ~/.m2/repository

wombawomba15:12:18

oh, it's just lein classpath. well then, I'll try that

👍 1