Skip to content

Commit d4d9146

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

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed

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

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

0 commit comments

Comments
 (0)