Not sure if anyone is interested in yet another example of how to compile a native image, but if so https://gitlab.com/tvaughan/kibit-runner#native-image. Only docker is required. For anyone looking to reproduce this without docker, Clojure 1.10.2 is required and for some reason this needs to be specified in deps.edn. A recent version of depstar is also required.
Just upgraded rewrite-clj v1 branch tests to use Graal v21.0.0. One more datapoint, @borkdude, for the https://github.com/borkdude/clj-reflector-graal-java11-fix not being needed!
For my Graal sci test under JDK11, I did still need to include borkdude/sci.impl.reflector
. Did not dig in at all, did you expect this still to be needed @borkdude?
yes, this lib is needed, but already pulled in by sci itself?
probably yes, since I removed from clojure-lsp and still works
Oh sorry, I meant the 0.0.1-java11
override version of borkdude/sci.impl.reflector
for JDK11.
Right, that one isn't needed anymore, since it has the same MethodHandle code
Cool, thanks, I’ll retry without it.
If I retry my rewrite-clj sci tests without overriding borkdude/sci.impl.reflector
to 0.0.1-java11
, native-image compile works fine, but when I interpret my tests I get java.lang.NoSuchMethodError: java.lang.reflect.AccessibleObject.canAccess
exceptions. I’ll create a todo for myself to look at this sometime later.
@lee I have encountered this error as well. Adding this method to the reflection config did the trick for me
See comment here: https://github.com/seancorfield/next-jdbc/issues/157#issuecomment-770192263
Huh, I thought I had tried that! Worth another shot, thanks!
@lee I think this is because the method is looked up using reflection: https://github.com/clojure/clojure/blob/140ed11e905de46331de705e955c50c0ef79095b/src/jvm/clojure/lang/Reflector.java#L38
(or something)
so basically it's missed by the analysis and you have to help it a little bit
This might become a very common config for projects that hit this path, so probably worth documenting
[{"name": "java.lang.reflect.AccessibleObject",
"methods" : [{"name":"canAccess"}]},
...
Ya, I’ll add a note to clj-graal-docs.
I think I'll copy your note to the reflector graal-fix repo then as well, since if you ran into that one, you'll probably now need this
ah, good idea!
Note that I did not need it when 1) compiling rewrite-clj and its tests, only when 2) compiling rewrite-clj for sci tests. But I don’t use a reflection.json for 1, so maybe that’s the diff.
yeah, sci uses this Reflector class to do interop
so that makes sense
Ah, right.
reflection.json fix you shared above works for rewrite-clj sci tests, thanks!
🎉
oh poo, I guess I’ll need to generate a different reflection.json for jdk8 than I do for jdk11.
in babashka I generate these using a script
different feature flags also need different reflection configs there
yeah, I stole that at one point, maybe I just need to grab an update!
ok, good stuff, should not tax my wee brain too much! :simple_smile:
there is only so much manual JSON or YAML my brain can handle before I switch to a clojure script