Skip to content

Commit c573028

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

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+
# , macos-latest
14+
os: [ubuntu-latest]
15+
ocaml-version: ["5"]
16+
fail-fast: false
17+
runs-on: ${{ matrix.os }}
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
# Cache ccache (shared across runs)
24+
- name: Cache ccache
25+
uses: actions/cache@v4
26+
with:
27+
path: ~/.ccache
28+
key: ${{ runner.os }}-ccache-${{ github.sha }}
29+
restore-keys: |
30+
${{ runner.os }}-ccache-
31+
32+
# Cache opam (compiler + packages)
33+
- name: Cache opam
34+
uses: actions/cache@v4
35+
with:
36+
path: ~/.opam
37+
key: ${{ runner.os }}-opam-${{ matrix.ocaml-version }}-${{ github.sha }}
38+
restore-keys: |
39+
${{ runner.os }}-opam-${{ matrix.ocaml-version }}-
40+
41+
# Setup OCaml via action
42+
- uses: ocaml/setup-ocaml@v3
43+
with:
44+
ocaml-compiler: ${{ matrix.ocaml-version }}
45+
opam-disable-sandboxing: true
46+
47+
# Platform-specific dependencies
48+
- name: Install system dependencies (Ubuntu)
49+
if: matrix.os == 'ubuntu-latest'
50+
run: |
51+
sudo apt-get update
52+
sudo apt-get install -y \
53+
bubblewrap m4 libgmp-dev pkg-config ninja-build ccache
54+
55+
- name: Install system dependencies (macOS)
56+
if: matrix.os == 'macos-latest'
57+
run: |
58+
brew install gmp pkg-config ninja ccache
59+
60+
- name: Install required opam packages
61+
run: opam install -y ocamlfind zarith
62+
63+
- name: 🔍 Debug ocamlfind + ocamlc.opt issue
64+
run: |
65+
set -e # fail on error
66+
67+
eval $(opam env)
68+
69+
echo "🔎 ocamlc: $(which ocamlc)"
70+
echo "🔎 ocamlopt: $(which ocamlopt)"
71+
echo "🔎 ocamlfind: $(which ocamlfind)"
72+
echo "🔎 All ocamlfind on path:"
73+
which -a ocamlfind
74+
75+
echo ""
76+
echo "📄 Writing test.ml"
77+
echo 'let () = print_endline "Hello from OCaml"' > test.ml
78+
79+
echo ""
80+
echo "🧪 ocamlc compile"
81+
ocamlc test.ml -o test_bytecode
82+
83+
echo ""
84+
echo "🧪 ocamlopt compile"
85+
ocamlopt test.ml -o test_native
86+
87+
echo ""
88+
echo "🧪 ocamlfind ocamlc compile"
89+
ocamlfind ocamlc -package zarith -linkpkg test.ml -o test_bytecode_find
90+
91+
echo ""
92+
echo "🧪 ocamlfind ocamlopt compile"
93+
ocamlfind ocamlopt -package zarith -linkpkg test.ml -o test_native_find
94+
95+
echo ""
96+
echo "🧪 FULLPATH ocamlfind ocamlc compile"
97+
/home/runner/work/z3/z3/_opam/bin/ocamlfind ocamlc -package zarith -linkpkg test.ml -o test_bytecode_full
98+
99+
echo ""
100+
echo "🧪 FULLPATH ocamlfind ocamlopt compile"
101+
/home/runner/work/z3/z3/_opam/bin/ocamlfind ocamlopt -package zarith -linkpkg test.ml -o test_native_full
102+
103+
echo ""
104+
echo "✅ All compiles passed."
105+
106+
# Configure
107+
- name: Configure with CMake
108+
env:
109+
RUNNER_OS: ${{ runner.os }}
110+
CC: ${{ matrix.os == 'macos-latest' && 'ccache clang' || 'ccache gcc' }}
111+
CXX: ${{ matrix.os == 'macos-latest' && 'ccache clang++' || 'ccache g++' }}
112+
run: |
113+
mkdir -p build
114+
cd build
115+
eval $(opam env)
116+
echo "CC: $CC"
117+
echo "CXX: $CXX"
118+
echo "OCAMLFIND: $(which ocamlfind)"
119+
echo "OCAMLC: $(which ocamlc)"
120+
echo "OCAMLOPT: $(which ocamlopt)"
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)