Skip to content

Commit 11d8fde

Browse files
committed
Add workflow using matrix.
1 parent a405046 commit 11d8fde

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed

Diff for: .github/workflows/ocaml-all.yaml

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
name: OCaml Binding CI (Ubuntu + macOS)
2+
3+
on:
4+
push:
5+
branches: [ "**" ]
6+
pull_request:
7+
branches: [ "**" ]
8+
9+
jobs:
10+
build-test:
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, macos-latest]
14+
ocaml-version: ["5"]
15+
fail-fast: false
16+
runs-on: ${{ matrix.os }}
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
# Cache ccache (shared across runs)
23+
- name: Cache ccache
24+
uses: actions/cache@v4
25+
with:
26+
path: ~/.ccache
27+
key: ${{ runner.os }}-ccache-${{ github.sha }}
28+
restore-keys: |
29+
${{ runner.os }}-ccache-
30+
31+
# Cache opam (compiler + packages)
32+
- name: Cache opam
33+
uses: actions/cache@v4
34+
with:
35+
path: ~/.opam
36+
key: ${{ runner.os }}-opam-${{ matrix.ocaml-version }}-${{ github.sha }}
37+
restore-keys: |
38+
${{ runner.os }}-opam-${{ matrix.ocaml-version }}-
39+
40+
# Setup OCaml via action
41+
- uses: ocaml/setup-ocaml@v3
42+
with:
43+
ocaml-compiler: ${{ matrix.ocaml-version }}
44+
opam-disable-sandboxing: true
45+
46+
# Platform-specific dependencies
47+
- name: Install system dependencies (Ubuntu)
48+
if: matrix.os == 'ubuntu-latest'
49+
run: |
50+
sudo apt-get update
51+
sudo apt-get install -y \
52+
bubblewrap m4 libgmp-dev pkg-config ninja-build ccache
53+
54+
- name: Install system dependencies (macOS)
55+
if: matrix.os == 'macos-latest'
56+
run: |
57+
brew install gmp pkg-config ninja ccache
58+
59+
- name: Install required opam packages
60+
run: opam install -y ocamlfind zarith
61+
62+
- name: 🔍 OCaml toolchain sanity check (with ocamlfind)
63+
run: |
64+
echo "📦 OCaml version: $(ocamlc -version)"
65+
echo ""
66+
67+
echo "📍 Shell-resolved paths:"
68+
for bin in ocamlc ocamlopt ocamlc.opt ocamlopt.opt ocamldep ocamldep.opt ocamlfind; do
69+
if command -v $bin >/dev/null 2>&1; then
70+
echo "✅ Found $bin at: $(which $bin)"
71+
else
72+
echo "❌ Missing $bin"
73+
fi
74+
done
75+
76+
echo ""
77+
echo "📂 OPAM_SWITCH_PREFIX/bin:"
78+
ls -al "$OPAM_SWITCH_PREFIX/bin"
79+
80+
echo ""
81+
echo "📎 ocamlfind configuration:"
82+
if command -v ocamlfind >/dev/null 2>&1; then
83+
echo " 🔧 ocamlc: $(ocamlfind printconf ocamlc)"
84+
echo " 🔧 ocamlopt: $(ocamlfind printconf ocamlopt)"
85+
echo " 🔧 ocamldep: $(ocamlfind printconf ocamldep)"
86+
echo " 🔧 stdlib: $(ocamlfind printconf stdlib)"
87+
echo " 🔧 ld.conf: $(ocamlfind printconf ld.conf)"
88+
else
89+
echo "⚠️ ocamlfind not found, skipping ocamlfind printconf"
90+
fi
91+
92+
echo ""
93+
echo "📌 PATH: $PATH"
94+
95+
# Optional fail-fast to stop build if anything is missing
96+
echo ""
97+
echo "🚨 Manually checking for required binaries..."
98+
for required in ocamlc ocamlopt ocamlfind; do
99+
if ! command -v $required >/dev/null 2>&1; then
100+
echo "❌ Required binary '$required' is missing. Failing build."
101+
exit 1
102+
fi
103+
done
104+
105+
exit 1
106+
107+
# Configure
108+
- name: Configure with CMake
109+
env:
110+
RUNNER_OS: ${{ runner.os }}
111+
CC: ${{ matrix.os == 'macos-latest' && 'ccache clang' || 'ccache gcc' }}
112+
CXX: ${{ matrix.os == 'macos-latest' && 'ccache clang++' || 'ccache g++' }}
113+
run: |
114+
mkdir -p build
115+
cd build
116+
eval $(opam env)
117+
echo "CC: $CC"
118+
echo "CXX: $CXX"
119+
echo "OCAMLFIND: $(which ocamlfind)"
120+
echo "OCAML: $(which ocamlc)"
121+
echo "OCAML_VERSION: $(ocamlc -version)"
122+
echo "OCAMLLIB: $OCAMLLIB"
123+
env | grep OCAML
124+
cmake .. \
125+
-G Ninja \
126+
-DZ3_BUILD_LIBZ3_SHARED=ON \
127+
-DZ3_BUILD_OCAML_BINDINGS=ON \
128+
-DZ3_BUILD_JAVA_BINDINGS=OFF \
129+
-DZ3_BUILD_PYTHON_BINDINGS=OFF \
130+
-DZ3_BUILD_CLI=OFF \
131+
-DZ3_BUILD_TEST_EXECUTABLES=OFF \
132+
-DCMAKE_VERBOSE_MAKEFILE=TRUE
133+
134+
- name: Build Z3 and OCaml bindings
135+
run: |
136+
ccache -z || true
137+
cd build
138+
ninja build_z3_ocaml_bindings
139+
ccache -s || true
140+
141+
- name: Compile ml_example.byte
142+
run: |
143+
ocamlfind ocamlc -o ml_example.byte \
144+
-package zarith \
145+
-linkpkg \
146+
-I build/src/api/ml \
147+
-dllpath build/src/api/ml \
148+
build/src/api/ml/z3ml.cma \
149+
examples/ml/ml_example.ml
150+
151+
- name: Run ml_example.byte
152+
run: ./ml_example.byte
153+
154+
- name: Compile ml_example (native)
155+
run: |
156+
ocamlfind ocamlopt -o ml_example \
157+
-package zarith \
158+
-linkpkg \
159+
-I build/src/api/ml \
160+
build/src/api/ml/z3ml.cmxa \
161+
examples/ml/ml_example.ml
162+
163+
- name: Run ml_example (native)
164+
run: ./ml_example

0 commit comments

Comments
 (0)