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: 🔍 OCaml toolchain sanity check (with ocamlfind)
64
+ # run: |
65
+ # eval $(opam env)
66
+ # echo "📦 OCaml version: $(ocamlc -version)"
67
+ # echo ""
68
+
69
+ # echo "📍 Shell-resolved paths:"
70
+ # for bin in ocamlc ocamlopt ocamlc.opt ocamlopt.opt ocamldep ocamldep.opt ocamlfind; do
71
+ # if command -v $bin >/dev/null 2>&1; then
72
+ # echo "✅ Found $bin at: $(which $bin)"
73
+ # else
74
+ # echo "❌ Missing $bin"
75
+ # fi
76
+ # done
77
+
78
+ # echo ""
79
+ # echo "📂 OPAM_SWITCH_PREFIX/bin:"
80
+ # ls -al "$OPAM_SWITCH_PREFIX/bin"
81
+
82
+ # echo ""
83
+ # echo "📎 ocamlfind configuration:"
84
+ # if command -v ocamlfind >/dev/null 2>&1; then
85
+ # echo " 🔧 ocamlc: $(ocamlfind ocamlc -where)"
86
+ # echo " 🔧 ocamlopt: $(ocamlfind ocamlopt -where)"
87
+ # echo " 🔧 ocamldep: $(ocamlfind ocamldep -where)"
88
+ # echo " 🔧 stdlib: $(ocamlfind stdlib -where)"
89
+ # echo " 🔧 ld.conf: $(ocamlfind ld.conf -where)"
90
+ # else
91
+ # echo "⚠️ ocamlfind not found, skipping ocamlfind printconf"
92
+ # fi
93
+
94
+ # echo ""
95
+ # echo "📌 PATH: $PATH"
96
+
97
+ # # Optional fail-fast to stop build if anything is missing
98
+ # echo ""
99
+ # echo "🚨 Manually checking for required binaries..."
100
+ # for required in ocamlc ocamlopt ocamlfind; do
101
+ # if ! command -v $required >/dev/null 2>&1; then
102
+ # echo "❌ Required binary '$required' is missing. Failing build."
103
+ # exit 1
104
+ # fi
105
+ # done
106
+
107
+ # exit 1
108
+
109
+ # Configure
110
+ - name : Configure with CMake
111
+ env :
112
+ RUNNER_OS : ${{ runner.os }}
113
+ CC : ${{ matrix.os == 'macos-latest' && 'ccache clang' || 'ccache gcc' }}
114
+ CXX : ${{ matrix.os == 'macos-latest' && 'ccache clang++' || 'ccache g++' }}
115
+ run : |
116
+ mkdir -p build
117
+ cd build
118
+ eval $(opam env)
119
+ echo "CC: $CC"
120
+ echo "CXX: $CXX"
121
+ echo "OCAMLFIND: $(which ocamlfind)"
122
+ echo "OCAMLC: $(which ocamlc)"
123
+ echo "OCAMLOPT: $(which ocamlopt)"
124
+ echo "OCAML_VERSION: $(ocamlc -version)"
125
+ echo "OCAMLLIB: $OCAMLLIB"
126
+ env | grep OCAML
127
+ cmake .. \
128
+ -G Ninja \
129
+ -DZ3_BUILD_LIBZ3_SHARED=ON \
130
+ -DZ3_BUILD_OCAML_BINDINGS=ON \
131
+ -DZ3_BUILD_JAVA_BINDINGS=OFF \
132
+ -DZ3_BUILD_PYTHON_BINDINGS=OFF \
133
+ -DZ3_BUILD_CLI=OFF \
134
+ -DZ3_BUILD_TEST_EXECUTABLES=OFF \
135
+ -DCMAKE_VERBOSE_MAKEFILE=TRUE
136
+
137
+ - name : Build Z3 and OCaml bindings
138
+ run : |
139
+ ccache -z || true
140
+ cd build
141
+ ninja build_z3_ocaml_bindings
142
+ ccache -s || true
143
+
144
+ - name : Compile ml_example.byte
145
+ run : |
146
+ ocamlfind ocamlc -o ml_example.byte \
147
+ -package zarith \
148
+ -linkpkg \
149
+ -I build/src/api/ml \
150
+ -dllpath build/src/api/ml \
151
+ build/src/api/ml/z3ml.cma \
152
+ examples/ml/ml_example.ml
153
+
154
+ - name : Run ml_example.byte
155
+ run : ./ml_example.byte
156
+
157
+ - name : Compile ml_example (native)
158
+ run : |
159
+ ocamlfind ocamlopt -o ml_example \
160
+ -package zarith \
161
+ -linkpkg \
162
+ -I build/src/api/ml \
163
+ build/src/api/ml/z3ml.cmxa \
164
+ examples/ml/ml_example.ml
165
+
166
+ - name : Run ml_example (native)
167
+ run : ./ml_example
0 commit comments