Fork me on GitHub
#graalvm
<
2024-02-29
>
naxels11:02:03

Does anyone know how to ensure a resources/config.edn file (or any config file) is only loaded at runtime for GraalVM Native image?

naxels11:02:20

in the code, i’m doing this:

(def read-config
  (-> "resources/config.edn"
      (slurp)
      (edn/read-string)))

naxels11:02:30

and the Jar still reads it at runtime

borkdude11:02:33

don't do it on the top level but in a function or in a delay

naxels11:02:59

i’m looking at your Babashka code / github to try to find how you did it haha

naxels11:02:12

but can’t really find it, as this line

(let [bb-edn-resource (fs/file bb-edn-dir "META-INF" "bb.edn")]

naxels11:02:18

add it’s to the jar i think

borkdude11:02:12

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

borkdude11:02:44

unless you want to cause the side effect to be executed during image build of course

naxels11:02:59

yeah i have found that Accessing Resources link, but couldn’t figure out how to use it:sweat_smile:

naxels11:02:24

can’t i just use -H:ExcludeResources=“….”

naxels11:02:05

trying this now

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

borkdude11:02:14

check out how clj-kondo does it, it includes the entire resources/clj_kondo/impl directory inside the binary

naxels11:02:20

Native Image takes a while to compile on 2019 MBP Intel ha

borkdude11:02:32

Use the -O1 flag, it will speed up compilation

borkdude11:02:39

or even -Ob

naxels11:02:01

thanks, i will experiment

naxels11:02:30

probably you’ve had to invest COUNTLESS hours in figuring out GraalVM Native Image ha

naxels11:02:49

although i was surprised to see it actually became easier with GraalVM 21.0.2

naxels11:02:39

hmm tried several approaches with the -H:ExcludeResources=“..” but none of them work

naxels12:02:48

Awesome, wrapping it in an fn did the trick easily

(def read-config
  (fn []
    (-> "resources/config.edn"
        (slurp)
        (edn/read-string))))

naxels12:02:54

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

naxels12:02:50

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