graalvm 2023-12-16

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?

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?

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

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

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

👍 1

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?

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

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

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 🙂

have you tried with Oracle GraalVM 21 instead of CE?

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

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

yeah I get the same thing with Oracle GraalVM

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

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

👍 1