Skip to content

Commit 4391d0d

Browse files
committed
Add workflow using matrix.
1 parent a405046 commit 4391d0d

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

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

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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: Check OCaml toolchain
63+
run: |
64+
echo "📦 OCaml version:"
65+
eval $(opam env)
66+
ocamlc -version
67+
echo ""
68+
69+
echo "📍 ocamlc path: $(which ocamlc)"
70+
echo "📍 ocamlopt path: $(which ocamlopt)"
71+
echo "📍 ocamlfind path: $(which ocamlfind)"
72+
echo ""
73+
74+
echo "🔍 Checking common OCaml tools:"
75+
for bin in ocamlc ocamlc.opt ocamlopt ocamlopt.opt ocamldep ocamldep.opt ocamlfind; do
76+
if command -v $bin >/dev/null 2>&1; then
77+
echo "✅ Found $bin at: $(which $bin)"
78+
else
79+
echo "❌ Missing $bin"
80+
fi
81+
done
82+
83+
echo ""
84+
echo "📂 Listing OPAM switch bin directory:"
85+
ls -al "$OPAM_SWITCH_PREFIX/bin"
86+
exit 1
87+
88+
# Configure
89+
- name: Configure with CMake
90+
env:
91+
RUNNER_OS: ${{ runner.os }}
92+
CC: ${{ matrix.os == 'macos-latest' && 'ccache clang' || 'ccache gcc' }}
93+
CXX: ${{ matrix.os == 'macos-latest' && 'ccache clang++' || 'ccache g++' }}
94+
run: |
95+
mkdir -p build
96+
cd build
97+
eval $(opam env)
98+
echo "CC: $CC"
99+
echo "CXX: $CXX"
100+
echo "OCAMLFIND: $(which ocamlfind)"
101+
echo "OCAML: $(which ocamlc)"
102+
echo "OCAML_VERSION: $(ocamlc -version)"
103+
echo "OCAMLLIB: $OCAMLLIB"
104+
env | grep OCAML
105+
cmake .. \
106+
-G Ninja \
107+
-DZ3_BUILD_LIBZ3_SHARED=ON \
108+
-DZ3_BUILD_OCAML_BINDINGS=ON \
109+
-DZ3_BUILD_JAVA_BINDINGS=OFF \
110+
-DZ3_BUILD_PYTHON_BINDINGS=OFF \
111+
-DZ3_BUILD_CLI=OFF \
112+
-DZ3_BUILD_TEST_EXECUTABLES=OFF \
113+
-DCMAKE_VERBOSE_MAKEFILE=TRUE
114+
115+
- name: Build Z3 and OCaml bindings
116+
run: |
117+
ccache -z || true
118+
cd build
119+
ninja build_z3_ocaml_bindings
120+
ccache -s || true
121+
122+
- name: Compile ml_example.byte
123+
run: |
124+
ocamlfind ocamlc -o ml_example.byte \
125+
-package zarith \
126+
-linkpkg \
127+
-I build/src/api/ml \
128+
-dllpath build/src/api/ml \
129+
build/src/api/ml/z3ml.cma \
130+
examples/ml/ml_example.ml
131+
132+
- name: Run ml_example.byte
133+
run: ./ml_example.byte
134+
135+
- name: Compile ml_example (native)
136+
run: |
137+
ocamlfind ocamlopt -o ml_example \
138+
-package zarith \
139+
-linkpkg \
140+
-I build/src/api/ml \
141+
build/src/api/ml/z3ml.cmxa \
142+
examples/ml/ml_example.ml
143+
144+
- name: Run ml_example (native)
145+
run: ./ml_example

0 commit comments

Comments
 (0)