This repository contains a prototype-grade OCaml compatibility build inspired by
TigerBeetle, with the upstream Zig codebase kept in repo/ as the reference.
This is not a full reimplementation. Treat it as a behavior and tooling spike:
- core ledger API only
- server + CLI compatibility surface
- partial blackbox compatibility
- useful for focused experiments, not production claims
tb_ocaml/: OCaml implementationrepo/: upstream TigerBeetle submodulebenchmarks/: local comparison harnessesscripts/: helper scripts outside Dunezig/: local Zig toolchain used for some upstream/build helper tasks
The upstream reference is a submodule:
git clone --recurse-submodules https://github.com/tusharhqq/6666.gitor after cloning:
git submodule update --init --recursiveCommands below assume:
ROOT=$(git rev-parse --show-toplevel)
cd "$ROOT"- OCaml
5.4+ - Dune
3.21+ - Python
3 - a Python virtualenv at
$ROOT/.venv_pytestsfor the upstream Python blackbox - a checksum helper at
$ROOT/tb_ocaml/_build_tools/tb_checksum
Set up the Python env once:
ROOT=$(git rev-parse --show-toplevel)
cd "$ROOT"
python3 -m venv .venv_pytests
. .venv_pytests/bin/activate
pip install -U pip pytest tigerbeetleROOT=$(git rev-parse --show-toplevel)
cd "$ROOT/tb_ocaml"
dune build
dune test
dune runtest
dune build @docSupporting tools used here:
Dunefor build, test, docs, and cram orchestrationAlcotestfor deterministic unit testsQCheckfor property testsbisect_ppxfor coverageocamlformatfor formattingppx_inline_testwhen the local switch can support it- optional
junit_alcotestif CI needs JUnit XML
Formatting is pinned by tb_ocaml/.ocamlformat.
ROOT=$(git rev-parse --show-toplevel)
cd "$ROOT/tb_ocaml"
ocamlformat --check $(find . -path './_build' -prune -o \( -name '*.ml' -o -name '*.mli' \) -print)
ocamlformat -i $(find . -path './_build' -prune -o \( -name '*.ml' -o -name '*.mli' \) -print)Warnings are strict in tb_ocaml/dune:
-w +A-41-42-70-warn-error +A-41-42-70
The main OCaml CI workflow is .github/workflows/tb_ocaml_ci.yml. It runs:
opam install . --deps-only --with-test --with-doc
dune build
dune build @doc
dune runtest
ocamlformat --check $(find . -path './_build' -prune -o \( -name '*.ml' -o -name '*.mli' \) -print)Every public library module now has an .mli:
tb_ocaml/lib/u128.mlitb_ocaml/lib/types.mlitb_ocaml/lib/multibatch.mlitb_ocaml/lib/codec.mlitb_ocaml/lib/state.mlitb_ocaml/lib/checksum.mlitb_ocaml/lib/repl.mlitb_ocaml/lib/server.mli
Docs are generated from the same Dune package:
ROOT=$(git rev-parse --show-toplevel)
cd "$ROOT/tb_ocaml"
dune build @docGenerated HTML:
tb_ocaml/_build/default/_doc/_html/
The package landing page is tb_ocaml/tb_ocaml.mld.
ROOT=$(git rev-parse --show-toplevel)
cd "$ROOT/tb_ocaml"
dune exec ./bin/tigerbeetle.exe -- version
TB_OCAML_CHECKSUM_BIN="$ROOT/tb_ocaml/_build_tools/tb_checksum" \
dune exec ./bin/tigerbeetle.exe -- format --cluster=0 --replica=0 --replica-count=1 --development /tmp/0_0.tigerbeetle
TB_OCAML_CHECKSUM_BIN="$ROOT/tb_ocaml/_build_tools/tb_checksum" \
dune exec ./bin/tigerbeetle.exe -- start --development=true --addresses=0 /tmp/0_0.tigerbeetleThen in another shell:
ROOT=$(git rev-parse --show-toplevel)
cd "$ROOT/tb_ocaml"
TB_OCAML_CHECKSUM_BIN="$ROOT/tb_ocaml/_build_tools/tb_checksum" \
dune exec ./bin/tigerbeetle.exe -- repl --cluster=0 --addresses=<port> --command="create_accounts id=17 code=718 ledger=1"
TB_OCAML_CHECKSUM_BIN="$ROOT/tb_ocaml/_build_tools/tb_checksum" \
dune exec ./bin/tigerbeetle.exe -- repl --cluster=0 --addresses=<port> --command="lookup_accounts id=17"Main test layers:
tb_ocaml/tests/unit_tests.ml: Alcotest unit teststb_ocaml/tests/property_tests.ml: QCheck property teststb_ocaml/tests/cli.t: cram CLI teststb_ocaml/tests/core_blackbox.py: repo-local compatibility smoke test
The unit suite currently covers:
- codec and multibatch round-trips
- status/flag rendering in
Types - REPL parsing in
Repl - basic create/lookup/query behavior in
State
Run them with Dune:
ROOT=$(git rev-parse --show-toplevel)
cd "$ROOT/tb_ocaml"
dune test
dune runtestThe cram layer checks real CLI behavior:
--helpinspect --helpversionversion --verboseformat- unsupported
inspectsubcommands
This runs the original upstream Python test file from repo/ against the OCaml
server:
ROOT=$(git rev-parse --show-toplevel)
cd "$ROOT/tb_ocaml"
dune build @upstream-python-blackboxCurrent status: it still fails at upstream test_create_accounts. That means
the project is not yet a trusted compatibility layer.
Coverage is wired through bisect_ppx, but in this local switch the available
bisect_ppx conflicts with OCaml 5.4.0. The authoritative path is CI in
.github/workflows/tb_ocaml_coverage.yml.
When coverage is available, treat it as a blind-spot finder, not a percentage goal. Prioritize:
tb_ocaml/lib/state.mltb_ocaml/lib/codec.mltb_ocaml/lib/multibatch.ml
benchmarks/compare_server_cli.py is useful for comparing the current
prototype workflow, not normalized engine throughput.
The current OCaml implementation still contains prototype scaffolding that materially affects benchmark results:
tb_ocaml/lib/checksum.mlshells out to an external checksum helper per calltb_ocaml/lib/server.mlserializes stateful work behind one mutextb_ocaml/lib/state.mlpersists snapshots withMarshal
Treat benchmark output as "how this spike behaves today", not "how an OCaml TigerBeetle would perform after architectural cleanup."
- Persistence is temporary test scaffolding, not a durable format.
- Compatibility coverage is still shallow relative to upstream behavior.
- Some upstream blackbox suites remain blocked by environment/tooling.
- Inline tests are still blocked in this local macOS arm64 OCaml
5.4switch.