graalvm 2024-02-29

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

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=“….”

trying this now

-H:ExcludeResources=".*/config.edn$"
let’s see what happens

check 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))))

haha oops, that didn’t click yet:sweat_smile: but you are correct haha

like how you can do @…. and it will reference the person on Gh