Does anyone know how to ensure a resources/config.edn file (or any config file) is only loaded at runtime for GraalVM Native image?
in the code, i’m doing this:
(def read-config
(-> "resources/config.edn"
(slurp)
(edn/read-string)))and the Jar still reads it at runtime
don't do it on the top level but in a function or in a delay
i’m looking at your Babashka code / github to try to find how you did it haha
but can’t really find it, as this line
(let [bb-edn-resource (fs/file bb-edn-dir "META-INF" "bb.edn")]add it’s to the jar i think
https://www.graalvm.org/latest/reference-manual/native-image/dynamic-features/Resources/
read those docs + don't cause any side effects on the top level, they will be executed during image build. Do it in a function
unless you want to cause the side effect to be executed during image build of course
yeah i have found that Accessing Resources link, but couldn’t figure out how to use it:sweat_smile:
can’t i just use -H:ExcludeResources=“….”
you can
trying this now
-H:ExcludeResources=".*/config.edn$"
let’s see what happenscheck out how clj-kondo does it, it includes the entire resources/clj_kondo/impl directory inside the binary
Native Image takes a while to compile on 2019 MBP Intel ha
Use the -O1 flag, it will speed up compilation
or even -Ob
thanks, i will experiment
probably you’ve had to invest COUNTLESS hours in figuring out GraalVM Native Image ha
although i was surprised to see it actually became easier with GraalVM 21.0.2
hmm tried several approaches with the -H:ExcludeResources=“..” but none of them work
Awesome, wrapping it in an fn did the trick easily
(def read-config
(fn []
(-> "resources/config.edn"
(slurp)
(edn/read-string))))
aka defn
haha oops, that didn’t click yet:sweat_smile: but you are correct haha
done, https://github.com/naxels/my-pocket-parser/commit/fd34037202dd96a1b5d46e3f3d87fd12b33acbd0
like how you can do @…. and it will reference the person on Gh