User Guide: tools_opam

if you move a project directory that has a here switch, you must run bazel run @opam//here:refresh after the move.

The tools_opam package provides:

  • OPAM bootstrapper tools that generate Bazel files containing repository and build targets for everything in the current OPAM switch. This makes all OPAM packages accessible under standard Bazel labels, such as @yojson//:yojson for yojson and @mtime//clock/os for mtime.clock.os. The bootstrapper must be run before the build; this eliminates the need to run a tool like ocamlfind during the build in order to integrate OPAM dependencies.

  • A toolchain that makes the OCaml compilers and other tools (e.g. ocamllex) accessible to the OBazl ruleset under standard Bazel labels. The toolchain depends on a workspace named @ocaml containing build targets for the OCaml tools. Executables must be targets in the @ocaml//bin package; for example, the bytecode compiler label is @ocaml//bin:ocamlc. This has the useful side-effect of making the OCaml tools accessible to genrule targets. The OPAM bootstrapper generates such a workspace, but since the OBazl-defined toolchain depends only on labels, it may be replaced with a workspace whose target labels resolve to a customized OCaml toolchain.

A primary goal of OBazl is to support fully hermetic OCaml builds. For reasons explained below, hermetic builds are not possible with a standard OPAM installation. The remainder of this article describes the problems and OBazl’s approach to addressing them.