From 10f97de31d72908783bf9977c001214fca7fa39b Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Thu, 19 Nov 2026 15:06:13 +0100 Subject: [PATCH 1/4] Fix #74: name static linking as the cause when a library cannot load --- CHANGELOG.md | 4 ++ README.md | 2 +- doc/guide.md | 8 ++++ src/babashka/ffi.clj | 58 ++++++++++++++++++++++-- test-native/babashka/ffi/native_test.clj | 6 +++ test/babashka/ffi_test.clj | 33 ++++++++++++++ 6 files changed, 105 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4808c6a..02c8f19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ [babashka.ffi](https://github.com/babashka/ffi): call C libraries from Clojure, babashka and Node.js. +## Unreleased + +- [#74](https://github.com/babashka/ffi/issues/74): in a statically linked Linux executable, `load-library`, `load-system-library` and a call through the default lookup throw an error that names static linking as the cause + ## 0.1.3 (2026-11-09) - [#65](https://github.com/babashka/ffi/issues/65): `write-string` writes a NUL-terminated string into existing memory diff --git a/README.md b/README.md index b063bad..544fe0c 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ org.babashka/ffi {:mvn/version "0.1.2"} | Platform | Requirement | Notes | |---|---|---| | JVM | JDK 25 or newer | Uses the Java FFM API. | -| babashka | 1.13.220 or newer | Built in, no dependency needed. | +| babashka | 1.13.220 or newer | Built in, no dependency needed. Use the dynamically linked Linux binary, not `linux-amd64-static`. | | GraalVM native image | GraalVM 25 or newer | See [Build your own native image](doc/guide.md#build-your-own-native-image). | | Node.js | 26.1 or newer | Works with [nbb](https://github.com/babashka/nbb), ClojureScript, shadow-cljs and [squint](https://github.com/squint-cljs/squint) through `node:ffi`. See [On Node.js](doc/guide.md#on-nodejs). | diff --git a/doc/guide.md b/doc/guide.md index 49a10b0..8ace763 100644 --- a/doc/guide.md +++ b/doc/guide.md @@ -57,6 +57,11 @@ becomes `libz.dylib`, `libz.so`, or `z.dll`, depending on the operating system. ## Load a library +Use a dynamically linked executable. A statically linked one, such as the +`linux-amd64-static` babashka binary, cannot load a library or call a C +function, and `load-library`, `load-system-library` and `cfn` throw an error +that says so. + Use `load-system-library` for a short library name: ```clojure @@ -1203,6 +1208,9 @@ The library includes call trampolines and reachability metadata. Use `graal-build-time` to initialize `babashka.ffi` and the other Clojure namespaces at build time. +Do not pass `--static`. A fully static image cannot load a library. +`-H:+StaticExecutableWithDynamicLibC` links libc dynamically and can. + See `script/native_test.clj` for a complete build example. For a Windows image, add these options in step 4: diff --git a/src/babashka/ffi.clj b/src/babashka/ffi.clj index 3dfd1a1..4ee1bc2 100644 --- a/src/babashka/ffi.clj +++ b/src/babashka/ffi.clj @@ -607,6 +607,40 @@ (def ^:private last-lookup-error (volatile! nil)) +(declare ^:private native-image?) + +(defn- static-elf? + "Returns true if path is a 64-bit little-endian ELF file without a + PT_INTERP program header." + [^String path] + (try + (clojure.core/with-open [f (java.io.RandomAccessFile. path "r")] + (let [hdr (byte-array 64) + _ (.readFully f hdr) + buf (.order (java.nio.ByteBuffer/wrap hdr) java.nio.ByteOrder/LITTLE_ENDIAN)] + (and (= 0x464c457f (.getInt buf 0)) + (= 2 (aget hdr 4)) + (= 1 (aget hdr 5)) + (let [phoff (.getLong buf 0x20) + phentsize (long (.getShort buf 0x36)) + phnum (long (.getShort buf 0x38))] + (not-any? (fn [^long i] + (.seek f (+ phoff (* i phentsize))) + (= 3 (Integer/reverseBytes (.readInt f)))) + (range phnum)))))) + (catch Exception _ false))) + +(def ^:private static-executable? + (delay (and native-image? + (= :linux (os-key)) + (some-> (.command (.info (java.lang.ProcessHandle/current))) + (.orElse nil) + static-elf?)))) + +(defn- static-executable-ex [data cause] + (ex-info "babashka.ffi: a statically linked executable cannot load shared libraries, use a dynamically linked build" + data cause)) + (defn- try-lookup ^SymbolLookup [^String path] (try (SymbolLookup/libraryLookup path (Arena/global)) (catch java.lang.IllegalCallerException e @@ -662,6 +696,8 @@ (vector? lib) (mapv str lib) :else [(str lib)]) m (or (some lookup-one paths) + (when @static-executable? + (throw (static-executable-ex {:library lib} @last-lookup-error))) (throw (ex-info (str "babashka.ffi: cannot load library: " (str/join ", " paths) " (bare names also searched in " @@ -706,6 +742,8 @@ (search-dirs))] (swap! libraries conj (:lookup m)) m) + (when @static-executable? + (throw (static-executable-ex {:library name} @last-lookup-error))) (throw (ex-info (str "babashka.ffi: cannot find library " name " (tried " base " and " base ".* in " (pr-str (vec (search-dirs))) ")") @@ -731,12 +769,22 @@ (pr-str lib)) {:library lib}))))) +(defn- find-in ^MemorySegment [^SymbolLookup l ^String sym] + (.orElse (.find l sym) nil)) + +(defn- find-default ^MemorySegment [^String sym] + (try (find-in (.defaultLookup ^Linker @linker*) sym) + (catch Throwable e + (if @static-executable? + (throw (static-executable-ex {:symbol sym} e)) + (throw e))))) + (defn- lookup-symbol ^MemorySegment [lib ^String sym] - (let [;; nil? and not truthiness: false is not "no library", it is a wrong one - lookups (if (nil? lib) - (conj @libraries (.defaultLookup ^Linker @linker*)) - [(resolve-library lib)])] - (some (fn [^SymbolLookup l] (.orElse (.find l sym) nil)) lookups))) + ;; nil? and not truthiness: false is not "no library", it is a wrong one + (if (nil? lib) + (or (some #(find-in % sym) @libraries) + (find-default sym)) + (find-in (resolve-library lib) sym))) (defn- require-symbol ^MemorySegment [lib sym] (if (instance? MemorySegment sym) diff --git a/test-native/babashka/ffi/native_test.clj b/test-native/babashka/ffi/native_test.clj index 1cfb299..dbfdb23 100644 --- a/test-native/babashka/ffi/native_test.clj +++ b/test-native/babashka/ffi/native_test.clj @@ -250,6 +250,12 @@ (check-throws "a callback with eight arguments" #"libffi" #(ffi/callback (ffi/global-arena) + (vec (repeat 8 :int)) :int)))) + (println "static linking") + (check "ProcessHandle returns the path of the image" true + (some? (.orElse (.command (.info (java.lang.ProcessHandle/current))) nil))) + (check "a dynamically linked image is not static" false + (boolean @@#'ffi/static-executable?)) + (println) (if (zero? @failures) (println "native image: all checks passed") diff --git a/test/babashka/ffi_test.clj b/test/babashka/ffi_test.clj index 2265843..b1c3b63 100644 --- a/test/babashka/ffi_test.clj +++ b/test/babashka/ffi_test.clj @@ -1127,3 +1127,36 @@ (is (= 0.95 (strtod "0.95" ffi/null)))) (finally (setlocale lc-numeric original))))))))) + +(defn- elf-file [phdr-types] + (let [phnum (count phdr-types) + buf (doto (java.nio.ByteBuffer/allocate (+ 64 (* 56 phnum))) + (.order java.nio.ByteOrder/LITTLE_ENDIAN) + (.putInt 0 0x464c457f) + (.put 4 (byte 2)) + (.put 5 (byte 1)) + (.putLong 0x20 64) + (.putShort 0x36 (short 56)) + (.putShort 0x38 (short phnum))) + f (fs/create-temp-file {:prefix "elf"})] + (doseq [[i t] (map-indexed vector phdr-types)] + (.putInt buf (int (+ 64 (* 56 i))) (int t))) + (fs/write-bytes f (.array buf)) + (str f))) + +(deftest static-elf-test + (when-not (System/getProperty "babashka.version") + (let [static-elf? @(resolve 'babashka.ffi/static-elf?)] + (testing "an ELF file with PT_LOAD and no PT_INTERP is static" + (is (true? (static-elf? (elf-file [1 1]))))) + (testing "an ELF file with PT_INTERP is not static" + (is (false? (static-elf? (elf-file [6 3 1]))))) + (testing "a file that is not ELF is not static" + (let [f (fs/create-temp-file)] + (fs/write-bytes f (byte-array 100)) + (is (false? (static-elf? (str f)))))) + (testing "a missing file is not static" + (is (false? (static-elf? "/nonexistent/exe")))) + (when (fs/exists? "/proc/self/exe") + (testing "the running JVM is not static" + (is (false? (static-elf? "/proc/self/exe")))))))) From 527393d1cf16498020967bf90f67fa667e112e05 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Thu, 19 Nov 2026 15:19:25 +0100 Subject: [PATCH 2/4] Test the static linking error in a fully static image --- .github/workflows/ci.yml | 30 ++++++ bb.edn | 2 +- doc/ai/AGENTS.md | 8 ++ script/native_test.clj | 117 +++++++++++++---------- test-native/babashka/ffi/native_test.clj | 25 ++++- 5 files changed, 125 insertions(+), 57 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a4193e..c9e8e87 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -190,6 +190,36 @@ jobs: - name: Build and run the native image with libffi run: bb test:native + static: + name: Fully static native image + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: graalvm/setup-graalvm@v1 + with: + java-version: '25' + distribution: graalvm + native-image-musl: true + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: | + ~/.m2/repository + ~/.gitlibs + key: deps-${{ runner.os }}-${{ hashFiles('deps.edn', 'bb.edn') }} + restore-keys: deps-${{ runner.os }}- + + - uses: DeLaGuardo/setup-clojure@13.4 + with: + cli: latest + bb: latest + + - name: Build and run the static image + run: bb test:native --static + cljs: name: ClojureScript and shadow-cljs runs-on: ubuntu-latest diff --git a/bb.edn b/bb.edn index 9ab5ca4..d965ef1 100644 --- a/bb.edn +++ b/bb.edn @@ -20,7 +20,7 @@ "-m" "babashka.ffi-test")} test:native {:doc "Build a native image of babashka.ffi and run test-native against it. Needs GRAALVM_HOME." :task (do (load-file "script/native_test.clj") - ((resolve 'native-test/-main)))} + (apply (resolve 'native-test/-main) *command-line-args*))} test:cljs {:doc "Run the Node.js tests compiled with ClojureScript. Pass advanced for an :advanced build." :requires ([babashka.fs :as fs]) :task (if (= "advanced" (first *command-line-args*)) diff --git a/doc/ai/AGENTS.md b/doc/ai/AGENTS.md index 4edffc7..fc4d0fd 100644 --- a/doc/ai/AGENTS.md +++ b/doc/ai/AGENTS.md @@ -174,6 +174,14 @@ signature are refused. The second links the libffi of the system with -lffi and checks that they are called. BABASHKA_LIBFFI can also be the path of an archive. CI runs both on Linux, macOS and Windows. +```sh +bb test:native --static +``` + +builds a fully static image with musl and checks that babashka.ffi names +static linking when it cannot load a library. It needs a GraalVM with musl +support, so CI runs it on Linux only. + Node.js, needs Node.js 26.1 or newer on PATH. The three commands run test-node under nbb, ClojureScript and shadow-cljs. The last two need JDK 25 or newer: diff --git a/script/native_test.clj b/script/native_test.clj index 1e979da..3d21961 100644 --- a/script/native_test.clj +++ b/script/native_test.clj @@ -14,7 +14,13 @@ other value is the path of a libffi archive or import library. bb test:native - BABASHKA_LIBFFI=system bb test:native" + BABASHKA_LIBFFI=system bb test:native + + With --static, the image is fully static, linked with musl on Linux, and + checks that babashka.ffi names static linking when it cannot load a + library. Needs a GraalVM with musl support. + + bb test:native --static" (:require [babashka.deps :as deps] [babashka.fs :as fs] [babashka.process :as p] @@ -58,57 +64,64 @@ [& args] (-> (deps/clojure (vec args)) deref p/check)) -(defn -main [& _] - (fs/delete-tree out) - (fs/create-dirs classes) - - (step "the fixture") - (if (fs/windows?) - (p/shell "cl" "/nologo" "/LD" fixture (str "/Fe:" lib) - (str "/Fo:" (fs/path "target" "ffistructs.obj"))) - (p/shell "cc" "-shared" "-fPIC" "-o" lib fixture)) - - (step "javac") - (let [sdk (classpath :native) - cp (str/join fs/path-separator [sdk "test-native" (str classes)])] - (p/shell (graalvm-bin "javac") "--release" "25" "-cp" sdk "-d" (str classes) - "src-java/babashka/ffi/impl/FfiTrampoline.java" - "src-java/babashka/ffi/impl/FfiTrampolineOrdered.java" - "src-java/babashka/ffi/impl/Libffi.java" - "src-java/babashka/ffi/impl/LibffiClosure.java") - - (step "compiling the namespaces") - (clojure "-Scp" cp "-J--enable-native-access=ALL-UNNAMED" - "-e" (pr-str (list 'binding ['*compile-path* (str classes)] - '(compile 'babashka.ffi.native-test)))) - - (step (str "native-image, " (if libffi (str "with libffi: " libffi) "without libffi"))) - (apply p/shell {:extra-env {"BABASHKA_FEATURE_LIBFFI" (str (boolean libffi))}} - (graalvm-bin "native-image") - "-cp" cp - "--features=clj_easy.graal_build_time.InitClojureClasses" - "-H:+UnlockExperimentalVMOptions" - "-H:+ForeignAPISupport" - "--enable-native-access=ALL-UNNAMED" - "--no-fallback" - "-O1" - (concat - ;; Windows assigns argument registers by position, so its image - ;; loads the ordered trampolines, and the upcall shapes only they - ;; need are in a metadata file of their own - (when (fs/windows?) - ["-H:ConfigurationResourceRoots=babashka/ffi/native-image-windows"]) - ;; babashka.ffi reads the variable when the image is built, and - ;; loads the libffi bindings only then - ["-EBABASHKA_FEATURE_LIBFFI"] - (when libffi - [(str "-H:NativeLinkerOption=" - (if (= "system" libffi) "-lffi" (str (fs/absolutize libffi))))]) - ["-o" (str (fs/path out "ffi-native-test")) - "babashka.ffi.native_test"]))) - - (step "running the image") - (p/shell (str (fs/absolutize image)) lib)) +(defn -main [& args] + (let [static? (= "--static" (first args)) + libffi (when-not static? libffi)] + (fs/delete-tree out) + (fs/create-dirs classes) + + (when-not static? + (step "the fixture") + (if (fs/windows?) + (p/shell "cl" "/nologo" "/LD" fixture (str "/Fe:" lib) + (str "/Fo:" (fs/path "target" "ffistructs.obj"))) + (p/shell "cc" "-shared" "-fPIC" "-o" lib fixture))) + + (step "javac") + (let [sdk (classpath :native) + cp (str/join fs/path-separator [sdk "test-native" (str classes)])] + (p/shell (graalvm-bin "javac") "--release" "25" "-cp" sdk "-d" (str classes) + "src-java/babashka/ffi/impl/FfiTrampoline.java" + "src-java/babashka/ffi/impl/FfiTrampolineOrdered.java" + "src-java/babashka/ffi/impl/Libffi.java" + "src-java/babashka/ffi/impl/LibffiClosure.java") + + (step "compiling the namespaces") + (clojure "-Scp" cp "-J--enable-native-access=ALL-UNNAMED" + "-e" (pr-str (list 'binding ['*compile-path* (str classes)] + '(compile 'babashka.ffi.native-test)))) + + (step (str "native-image, " (cond static? "fully static" + libffi (str "with libffi: " libffi) + :else "without libffi"))) + (apply p/shell {:extra-env {"BABASHKA_FEATURE_LIBFFI" (str (boolean libffi))}} + (graalvm-bin "native-image") + "-cp" cp + "--features=clj_easy.graal_build_time.InitClojureClasses" + "-H:+UnlockExperimentalVMOptions" + "-H:+ForeignAPISupport" + "--enable-native-access=ALL-UNNAMED" + "--no-fallback" + "-O1" + (concat + ;; Windows assigns argument registers by position, so its image + ;; loads the ordered trampolines, and the upcall shapes only they + ;; need are in a metadata file of their own + (when (fs/windows?) + ["-H:ConfigurationResourceRoots=babashka/ffi/native-image-windows"]) + ;; babashka.ffi reads the variable when the image is built, and + ;; loads the libffi bindings only then + ["-EBABASHKA_FEATURE_LIBFFI"] + (when static? + ["--static" "--libc=musl"]) + (when libffi + [(str "-H:NativeLinkerOption=" + (if (= "system" libffi) "-lffi" (str (fs/absolutize libffi))))]) + ["-o" (str (fs/path out "ffi-native-test")) + "babashka.ffi.native_test"]))) + + (step "running the image") + (p/shell (str (fs/absolutize image)) (if static? "--static" lib)))) (when (= *file* (System/getProperty "babashka.file")) (apply -main *command-line-args*)) diff --git a/test-native/babashka/ffi/native_test.clj b/test-native/babashka/ffi/native_test.clj index dbfdb23..4e2489c 100644 --- a/test-native/babashka/ffi/native_test.clj +++ b/test-native/babashka/ffi/native_test.clj @@ -37,7 +37,27 @@ (println " expected a message matching" (pr-str (str re))) (println " actual: " (pr-str msg)))))) +(defn- report [] + (println) + (if (zero? @failures) + (println "native image: all checks passed") + (do (println "native image:" @failures "failed") (System/exit 1)))) + +(defn- static-checks [] + (println "a fully static image") + (check "static-executable? is true" true (boolean @@#'ffi/static-executable?)) + (check-throws "load-library names static linking" #"statically linked" + #(ffi/load-library "libz.so.1")) + (check-throws "load-system-library names static linking" #"statically linked" + #(ffi/load-system-library "z")) + (check-throws "a call through the default lookup names static linking" #"statically linked" + #((ffi/cfn "abs" [:int] :int) -5)) + (report)) + (defn -main [& args] + (when (= "--static" (first args)) + (static-checks) + (System/exit 0)) (let [lib (or (first args) "target/libffistructs.dylib")] (ffi/load-library lib) @@ -256,7 +276,4 @@ (check "a dynamically linked image is not static" false (boolean @@#'ffi/static-executable?)) - (println) - (if (zero? @failures) - (println "native image: all checks passed") - (do (println "native image:" @failures "failed") (System/exit 1))))) + (report))) From b363e6ef3fc1ff095c0845c1dbc7e9e7154efe58 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Thu, 19 Nov 2026 15:39:39 +0100 Subject: [PATCH 3/4] Read /proc/self/exe directly, and name both static binaries --- README.md | 2 +- src/babashka/ffi.clj | 4 +--- test-native/babashka/ffi/native_test.clj | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 544fe0c..635c29b 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ org.babashka/ffi {:mvn/version "0.1.2"} | Platform | Requirement | Notes | |---|---|---| | JVM | JDK 25 or newer | Uses the Java FFM API. | -| babashka | 1.13.220 or newer | Built in, no dependency needed. Use the dynamically linked Linux binary, not `linux-amd64-static`. | +| babashka | 1.13.220 or newer | Built in, no dependency needed. On Linux, use a dynamically linked binary, not a `-static` one. | | GraalVM native image | GraalVM 25 or newer | See [Build your own native image](doc/guide.md#build-your-own-native-image). | | Node.js | 26.1 or newer | Works with [nbb](https://github.com/babashka/nbb), ClojureScript, shadow-cljs and [squint](https://github.com/squint-cljs/squint) through `node:ffi`. See [On Node.js](doc/guide.md#on-nodejs). | diff --git a/src/babashka/ffi.clj b/src/babashka/ffi.clj index 4ee1bc2..8e0498c 100644 --- a/src/babashka/ffi.clj +++ b/src/babashka/ffi.clj @@ -633,9 +633,7 @@ (def ^:private static-executable? (delay (and native-image? (= :linux (os-key)) - (some-> (.command (.info (java.lang.ProcessHandle/current))) - (.orElse nil) - static-elf?)))) + (static-elf? "/proc/self/exe")))) (defn- static-executable-ex [data cause] (ex-info "babashka.ffi: a statically linked executable cannot load shared libraries, use a dynamically linked build" diff --git a/test-native/babashka/ffi/native_test.clj b/test-native/babashka/ffi/native_test.clj index 4e2489c..cc3cca5 100644 --- a/test-native/babashka/ffi/native_test.clj +++ b/test-native/babashka/ffi/native_test.clj @@ -271,8 +271,6 @@ #(ffi/callback (ffi/global-arena) + (vec (repeat 8 :int)) :int)))) (println "static linking") - (check "ProcessHandle returns the path of the image" true - (some? (.orElse (.command (.info (java.lang.ProcessHandle/current))) nil))) (check "a dynamically linked image is not static" false (boolean @@#'ffi/static-executable?)) From 061d4b1ef9aafe155be6f6bf8af1e33673449c58 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Thu, 19 Nov 2026 15:50:55 +0100 Subject: [PATCH 4/4] Leave the static linking note to the error message --- CHANGELOG.md | 2 +- README.md | 2 +- doc/guide.md | 8 -------- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02c8f19..a87afd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ Clojure, babashka and Node.js. ## Unreleased -- [#74](https://github.com/babashka/ffi/issues/74): in a statically linked Linux executable, `load-library`, `load-system-library` and a call through the default lookup throw an error that names static linking as the cause +- [#74](https://github.com/babashka/ffi/issues/74): a statically linked executable throws an error that names static linking when it cannot load a library ## 0.1.3 (2026-11-09) diff --git a/README.md b/README.md index 635c29b..b063bad 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ org.babashka/ffi {:mvn/version "0.1.2"} | Platform | Requirement | Notes | |---|---|---| | JVM | JDK 25 or newer | Uses the Java FFM API. | -| babashka | 1.13.220 or newer | Built in, no dependency needed. On Linux, use a dynamically linked binary, not a `-static` one. | +| babashka | 1.13.220 or newer | Built in, no dependency needed. | | GraalVM native image | GraalVM 25 or newer | See [Build your own native image](doc/guide.md#build-your-own-native-image). | | Node.js | 26.1 or newer | Works with [nbb](https://github.com/babashka/nbb), ClojureScript, shadow-cljs and [squint](https://github.com/squint-cljs/squint) through `node:ffi`. See [On Node.js](doc/guide.md#on-nodejs). | diff --git a/doc/guide.md b/doc/guide.md index 8ace763..49a10b0 100644 --- a/doc/guide.md +++ b/doc/guide.md @@ -57,11 +57,6 @@ becomes `libz.dylib`, `libz.so`, or `z.dll`, depending on the operating system. ## Load a library -Use a dynamically linked executable. A statically linked one, such as the -`linux-amd64-static` babashka binary, cannot load a library or call a C -function, and `load-library`, `load-system-library` and `cfn` throw an error -that says so. - Use `load-system-library` for a short library name: ```clojure @@ -1208,9 +1203,6 @@ The library includes call trampolines and reachability metadata. Use `graal-build-time` to initialize `babashka.ffi` and the other Clojure namespaces at build time. -Do not pass `--static`. A fully static image cannot load a library. -`-H:+StaticExecutableWithDynamicLibC` links libc dynamically and can. - See `script/native_test.clj` for a complete build example. For a Windows image, add these options in step 4: