graalvm

naxels 2024-02-29T11:07:03.421439Z

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

naxels 2024-02-29T11:07:20.219039Z

in the code, i’m doing this:

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

naxels 2024-02-29T11:07:30.683609Z

and the Jar still reads it at runtime

borkdude 2024-02-29T11:11:33.814419Z

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

naxels 2024-02-29T11:11:59.696719Z

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

naxels 2024-02-29T11:12:12.353719Z

but can’t really find it, as this line

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

naxels 2024-02-29T11:12:18.299729Z

add it’s to the jar i think

borkdude 2024-02-29T11:13:12.923999Z

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

borkdude 2024-02-29T11:13:44.801749Z

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

naxels 2024-02-29T11:13:59.199389Z

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

naxels 2024-02-29T11:14:24.275149Z

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

borkdude 2024-02-29T11:15:50.296569Z

you can

naxels 2024-02-29T11:16:05.035299Z

trying this now

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

borkdude 2024-02-29T11:16:14.511609Z

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

naxels 2024-02-29T11:16:20.015759Z

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

borkdude 2024-02-29T11:17:32.791359Z

Use the -O1 flag, it will speed up compilation

borkdude 2024-02-29T11:17:39.678909Z

or even -Ob

naxels 2024-02-29T11:25:01.099849Z

thanks, i will experiment

naxels 2024-02-29T11:25:30.778859Z

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

naxels 2024-02-29T11:25:49.096989Z

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

naxels 2024-02-29T11:29:39.037649Z

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

naxels 2024-02-29T12:08:48.552699Z

Awesome, wrapping it in an fn did the trick easily

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

borkdude 2024-02-29T12:09:21.019389Z

aka defn

naxels 2024-02-29T12:09:54.706539Z

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

naxels 2024-02-29T12:13:50.705159Z

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