mirror of
https://github.com/Z3Prover/z3
synced 2025-08-17 16:52:15 +00:00
Update on building OCaml binding with CMake (#7698)
* fix: add generating META for ocamlfind. * Patch macos. We need to keep the `@rpath` and use environment var to enable the test because we need to leave it to be fixed by package managers. * Trigger CI. * Debug. * Debug. * Debug. * Debug. * Debug. * Debug. * Hacky fix for ocaml building warning. * Fix typo and rename variables.
This commit is contained in:
parent
2de40ff220
commit
c2efd3dc6d
6 changed files with 100 additions and 208 deletions
125
.github/workflows/ocaml-all.yaml
vendored
125
.github/workflows/ocaml-all.yaml
vendored
|
@ -1,125 +0,0 @@
|
|||
name: OCaml Binding CI (Ubuntu + macOS)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "**" ]
|
||||
pull_request:
|
||||
branches: [ "**" ]
|
||||
|
||||
jobs:
|
||||
build-test:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ ubuntu-latest, macos-latest]
|
||||
ocaml-version: ["5"]
|
||||
fail-fast: false
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Cache ccache (shared across runs)
|
||||
- name: Cache ccache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.ccache
|
||||
key: ${{ runner.os }}-ccache-${{ github.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-ccache-
|
||||
|
||||
# Cache opam (compiler + packages)
|
||||
- name: Cache opam
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.opam
|
||||
key: ${{ runner.os }}-opam-${{ matrix.ocaml-version }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-opam-${{ matrix.ocaml-version }}-
|
||||
|
||||
# Setup OCaml via action
|
||||
- uses: ocaml/setup-ocaml@v3
|
||||
with:
|
||||
ocaml-compiler: ${{ matrix.ocaml-version }}
|
||||
opam-disable-sandboxing: true
|
||||
|
||||
# Platform-specific dependencies
|
||||
- name: Install system dependencies (Ubuntu)
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
bubblewrap m4 libgmp-dev pkg-config ninja-build ccache
|
||||
|
||||
- name: Install system dependencies (macOS)
|
||||
if: matrix.os == 'macos-latest'
|
||||
run: |
|
||||
brew install gmp pkg-config ninja ccache
|
||||
|
||||
- name: Install required opam packages
|
||||
run: opam install -y ocamlfind zarith
|
||||
|
||||
# Configure
|
||||
- name: Configure with CMake
|
||||
env:
|
||||
RUNNER_OS: ${{ runner.os }}
|
||||
CC: ${{ matrix.os == 'macos-latest' && 'ccache clang' || 'ccache gcc' }}
|
||||
CXX: ${{ matrix.os == 'macos-latest' && 'ccache clang++' || 'ccache g++' }}
|
||||
run: |
|
||||
mkdir -p build
|
||||
cd build
|
||||
eval $(opam env)
|
||||
echo "CC: $CC"
|
||||
echo "CXX: $CXX"
|
||||
echo "OCAMLFIND: $(which ocamlfind)"
|
||||
echo "OCAMLC: $(which ocamlc)"
|
||||
echo "OCAMLOPT: $(which ocamlopt)"
|
||||
echo "OCAML_VERSION: $(ocamlc -version)"
|
||||
echo "OCAMLLIB: $OCAMLLIB"
|
||||
env | grep OCAML
|
||||
cmake .. \
|
||||
-G Ninja \
|
||||
-DZ3_BUILD_LIBZ3_SHARED=ON \
|
||||
-DZ3_BUILD_OCAML_BINDINGS=ON \
|
||||
-DZ3_BUILD_JAVA_BINDINGS=OFF \
|
||||
-DZ3_BUILD_PYTHON_BINDINGS=OFF \
|
||||
-DZ3_BUILD_CLI=OFF \
|
||||
-DZ3_BUILD_TEST_EXECUTABLES=OFF \
|
||||
-DCMAKE_VERBOSE_MAKEFILE=TRUE
|
||||
|
||||
- name: Build Z3 and OCaml bindings
|
||||
run: |
|
||||
ccache -z || true
|
||||
eval $(opam env)
|
||||
cd build
|
||||
ninja build_z3_ocaml_bindings
|
||||
ccache -s || true
|
||||
|
||||
- name: Compile ml_example.byte
|
||||
run: |
|
||||
eval $(opam env)
|
||||
ocamlfind ocamlc -o ml_example.byte \
|
||||
-package zarith \
|
||||
-linkpkg \
|
||||
-I build/src/api/ml \
|
||||
-dllpath build/src/api/ml \
|
||||
build/src/api/ml/z3ml.cma \
|
||||
examples/ml/ml_example.ml
|
||||
|
||||
- name: Run ml_example.byte
|
||||
run: |
|
||||
eval $(opam env)
|
||||
ocamlrun ./ml_example.byte
|
||||
|
||||
- name: Compile ml_example (native)
|
||||
run: |
|
||||
eval $(opam env)
|
||||
ocamlfind ocamlopt -o ml_example \
|
||||
-package zarith \
|
||||
-linkpkg \
|
||||
-I build/src/api/ml \
|
||||
build/src/api/ml/z3ml.cmxa \
|
||||
examples/ml/ml_example.ml
|
||||
|
||||
- name: Run ml_example (native)
|
||||
run: ./ml_example
|
77
.github/workflows/ocaml.yaml
vendored
77
.github/workflows/ocaml.yaml
vendored
|
@ -1,4 +1,4 @@
|
|||
name: OCaml Binding CI (Ubuntu)
|
||||
name: OCaml Binding CI (Ubuntu + macOS)
|
||||
|
||||
on:
|
||||
push:
|
||||
|
@ -7,44 +7,74 @@ on:
|
|||
branches: [ "**" ]
|
||||
|
||||
jobs:
|
||||
build-test-ocaml:
|
||||
runs-on: ubuntu-latest
|
||||
build-test:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ ubuntu-latest, macos-latest ]
|
||||
ocaml-version: ["5"]
|
||||
fail-fast: false
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Cache ccache (shared across runs)
|
||||
- name: Cache ccache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.ccache
|
||||
key: ${{ runner.os }}-ccache-${{ github.ref }}
|
||||
key: ${{ runner.os }}-ccache-${{ github.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-ccache-
|
||||
|
||||
- name: Install system dependencies
|
||||
# Cache opam (compiler + packages)
|
||||
- name: Cache opam
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.opam
|
||||
key: ${{ runner.os }}-opam-${{ matrix.ocaml-version }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-opam-${{ matrix.ocaml-version }}-
|
||||
|
||||
# Setup OCaml via action
|
||||
- uses: ocaml/setup-ocaml@v3
|
||||
with:
|
||||
ocaml-compiler: ${{ matrix.ocaml-version }}
|
||||
opam-disable-sandboxing: true
|
||||
|
||||
# Platform-specific dependencies
|
||||
- name: Install system dependencies (Ubuntu)
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
opam bubblewrap m4 \
|
||||
libgmp-dev pkg-config \
|
||||
ninja-build ccache
|
||||
bubblewrap m4 libgmp-dev pkg-config ninja-build ccache
|
||||
|
||||
- name: Init opam (no sandbox, no default switch)
|
||||
- name: Install system dependencies (macOS)
|
||||
if: matrix.os == 'macos-latest'
|
||||
run: |
|
||||
opam init --bare --no-setup --disable-sandboxing
|
||||
opam switch create 5.3.0
|
||||
eval $(opam env)
|
||||
opam install -y ocamlfind zarith
|
||||
eval $(opam env)
|
||||
brew install gmp pkg-config ninja ccache
|
||||
|
||||
- name: Install required opam packages
|
||||
run: opam install -y ocamlfind zarith
|
||||
|
||||
# Configure
|
||||
- name: Configure with CMake
|
||||
env:
|
||||
CC: ${{ matrix.os == 'macos-latest' && 'ccache clang' || 'ccache gcc' }}
|
||||
CXX: ${{ matrix.os == 'macos-latest' && 'ccache clang++' || 'ccache g++' }}
|
||||
run: |
|
||||
eval $(opam env)
|
||||
export CC="ccache gcc"
|
||||
export CXX="ccache g++"
|
||||
mkdir -p build
|
||||
cd build
|
||||
eval $(opam env)
|
||||
echo "CC: $CC"
|
||||
echo "CXX: $CXX"
|
||||
echo "OCAMLFIND: $(which ocamlfind)"
|
||||
echo "OCAMLC: $(which ocamlc)"
|
||||
echo "OCAMLOPT: $(which ocamlopt)"
|
||||
echo "OCAML_VERSION: $(ocamlc -version)"
|
||||
echo "OCAMLLIB: $OCAMLLIB"
|
||||
cmake .. \
|
||||
-G Ninja \
|
||||
-DZ3_BUILD_LIBZ3_SHARED=ON \
|
||||
|
@ -57,19 +87,15 @@ jobs:
|
|||
|
||||
- name: Build Z3 and OCaml bindings
|
||||
run: |
|
||||
ccache -z || true
|
||||
eval $(opam env)
|
||||
export CC="ccache gcc"
|
||||
export CXX="ccache g++"
|
||||
ocamlc -version
|
||||
ccache -z # reset stats
|
||||
cd build
|
||||
ninja build_z3_ocaml_bindings
|
||||
ccache -s # show stats
|
||||
ccache -s || true
|
||||
|
||||
- name: Compile ml_example.byte
|
||||
run: |
|
||||
eval $(opam env)
|
||||
ocamlc -version
|
||||
ocamlfind ocamlc -o ml_example.byte \
|
||||
-package zarith \
|
||||
-linkpkg \
|
||||
|
@ -81,12 +107,12 @@ jobs:
|
|||
- name: Run ml_example.byte
|
||||
run: |
|
||||
eval $(opam env)
|
||||
export DYLD_LIBRARY_PATH=$(pwd)/build
|
||||
ocamlrun ./ml_example.byte
|
||||
|
||||
- name: Compile ml_example (native)
|
||||
run: |
|
||||
eval $(opam env)
|
||||
ocamlopt -version
|
||||
ocamlfind ocamlopt -o ml_example \
|
||||
-package zarith \
|
||||
-linkpkg \
|
||||
|
@ -96,4 +122,5 @@ jobs:
|
|||
|
||||
- name: Run ml_example (native)
|
||||
run: |
|
||||
./ml_example
|
||||
export DYLD_LIBRARY_PATH=$(pwd)/build
|
||||
./ml_example
|
Loading…
Add table
Add a link
Reference in a new issue