From cfee26706883ba11172a53b6c7f4b1d36882fa85 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 30 Jun 2026 08:43:02 -0700 Subject: [PATCH] Fix OCaml static build: ensure stublibs dir is in ld.conf after ocamlfind install (#10003) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "Ubuntu with OCaml on z3-static" CI job intermittently fails with `Fatal error: exception End_of_file` from the OCaml bytecode linker when compiling `ml_example_static.byte`. ## Root cause `ocamlfind install z3-static build/api/ml/* build/libz3-static.a` auto-recognizes `dllz3ml-static.so` (starts with `dll`) as a C stub and copies it to `stublibs`, but without an explicit `-dll` flag it **does not update `ld.conf`**—confirmed by the CI warning: ``` ocamlfind: [WARNING] You have installed DLLs but the directory .../stublibs is not mentioned in ld.conf ``` `ocamlc` searches `ld.conf` for stub DLLs at bytecode link time; the missing entry causes `End_of_file`. The non-static job is unaffected because it passes `-dll build/libz3.*` explicitly, which triggers the `ld.conf` update as a side-effect. ## Fix After `ocamlfind install`, append the `stublibs` path to `ld.conf` if absent: ```bash STUBLIBS="$(dirname "$(ocamlfind printconf destdir)")/stublibs" LDCONF="$(ocamlfind printconf ldconf)" if [ -d "$STUBLIBS" ] && ! grep -qF "$STUBLIBS" "$LDCONF" 2>/dev/null; then echo "$STUBLIBS" >> "$LDCONF" fi ``` Idempotent; uses `ocamlfind printconf` to avoid hardcoded paths. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Lev Nachmanson <5377127+levnach@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .github/workflows/ci.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dcd19a5719..67ed3e4796 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -248,7 +248,19 @@ jobs: cd .. - name: Install Z3 OCaml package - run: eval `opam config env`; ocamlfind install z3-static build/api/ml/* build/libz3-static.a + run: | + eval `opam config env` + ocamlfind install z3-static build/api/ml/* build/libz3-static.a + # Ensure the stublibs directory where dllz3ml-static.so was installed is + # listed in ld.conf so the OCaml bytecode linker can find it. When no + # explicit -dll flag is passed, ocamlfind installs dll* files to stublibs + # but may not update ld.conf, causing "Fatal error: exception End_of_file" + # in ocamlc when it cannot locate the stub shared library at link time. + STUBLIBS="$(ocamlfind printconf destdir)/stublibs" + LDCONF="$(ocamlfind printconf ldconf)" + if [ -d "$STUBLIBS" ] && ! grep -qF "$STUBLIBS" "$LDCONF" 2>/dev/null; then + echo "$STUBLIBS" >> "$LDCONF" + fi - name: Build and run OCaml examples run: |