I’ve tagged alpha versions of OBazl rules_ocaml and tools_opam. The best way to start exploring is via demos_obazl, which contains over 100 mostly simple demo/test programs, many of which are commented. Three simple commands get you configured and then bazel test test
runs all the tests.
Tested on MacOS 12.4 and Ubuntu 20.
Documentation is still in progress but there is useful info at The OBazl Book.
Lot’s of things to say about this version but I’ll stick to one point of interest. The four basic OCaml compilers are modeled by Bazel’s platforms and toolchains mechanisms. Two of the compilers are actually cross-compilers (e.g. ocamlc.opt
runs on the system arch but targets the OCaml vm), so to pick a compiler you tell OBazl which buildhost and targethost platforms you want. I’ve predefined configurations in .bazelrc; for example:
build:bcnc --host_platform=@opam//tc/host/build:bc
build:bcnc --platforms=@opam//tc/host/target:nc
which means to select the ocamlopt.byte
(cross-)compiler, pass --config=bcnc
.
Kinda cool IMHO. Maybe overkill for the basic compilers, but the mechanism is essential to support remote builds, custom compiler implementations and genuine cross-compilers.
Feedback welcome.
Gregg