3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-07-01 12:58:54 +00:00

Fix OCaml static build: ensure stublibs dir is in ld.conf after ocamlfind install (#10003)

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>
This commit is contained in:
Copilot 2026-06-30 08:43:02 -07:00 committed by GitHub
parent 2490e86d3f
commit cfee267068
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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: |