OCaml: Toolchains & Ecosystem Last updated May 16, 2022
Status: very rough as of 5/25/22. |
Standard OCaml distributions contain no fewer than four toolchains. …
The current OBazl toolsuite uses one OPAM-based Bazel toolchain that contains all the tools in the selected OPAM switch (i.e. OCaml distribution). Build mode (bytecode or native) is controlled by a configurable default rule passed on the command line; see X for details. The profiling compilers are not supported. The next version will contain one Bazel toolchain for each OCaml toolchain. |
Compilers
bytecode binaries | native binaries | remarks | |
---|---|---|---|
emit bytecode: |
ocamlc.byte |
ocamlc.opt |
std compilers |
ocamlcp.byte |
ocamlcp.opt |
profiling compilers |
|
emit native code: |
ocamlopt.byte |
ocamlopt.opt |
std compilers |
ocamloptp.byte |
ocamloptp.opt |
profiling compilers |
These are all utility commands. The actually compilers are
implemented as libraries; these commands are actually drivers, like
the gcc command of the GNU toolchain. They run the compilers but may
also run other tools.
|
The *.opt
versions are native code binaries; the *.byte
versions
are bytecode binaries, which must be executed with
ocamlrun.
The profiling complers instrument the source code, adding code to record how many times functions are called, branches of conditionals are taken, etc. See also Runtime tracing with the instrumented runtime.
By default, names without an extension are symlinked to the optimized (native) binaries:
-
ocamlc → ocamlc.opt
-
ocamlcp → ocamlcp.opt
-
ocamlopt → ocamlopt.opt
-
ocamloptp → ocamloptp.opt
By default, the OBazl rules use ocamlopt.opt
: the native-code compiler binary that emits native code.
Linkage
Native-mode compilers depend on a C toolchain; they may emit and compile assembly code, and use the linker.
Bytecode-mode compilers handle everything by themselves; they do not need a linker or other C tools (unless the source code uses interop to use libraries produced by another language system (C, Rust, etc.) ?)
Other tools in the distribution
The OCaml toolchain includes a variety of tools, most of which come in
*.byte
and *.opt
variants. Some but not all come with a man
page.
-
ocaml - a toplevel system (i.e. REPL) for OCaml
-
ocamlcmt
- reads a.cmt
file and prints related information -
ocamldebug - the OCaml source-level replay debugger
-
ocamldep - dependency generator: scans source files and emits dependency information
-
ocamldoc - documentation generator
-
ocamllex - lexer generator
-
ocamlmklib
- generate libraries with mixed C / Caml code -
ocamlmktop
- builds OCaml toplevels that contain user code preloaded at start-up -
ocamlobjinfo
- prints information from.cmo/.cmx/.cmi
files -
ocamlprof - OCaml profiler
-
ocamlrun - executes bytecode files produced by the linking phase of the ocamlc command.
-
ocamlrund
- debug version ofocamlrun
-
ocamlruni
- instrumented variant ofocamlrun
(see Runtime tracing with the instrumented runtime) -
ocamlyacc - parser generator
OPAM
Third-party Tools
ocamlfind and the findlib library
findlib is an OCaml package manager library. It has largely been supplanted by OPAM, but the metadata language it defines is used by OPAM.
ocamlfind is a commonly used command-line interface to the findlib
library.
OPAM
OPAM is the standard OCaml package manager.
Dune
Dune is the most commonly used build system for OCaml. Many if not most OPAM packages use Dune.
OBazl is an alternative to Dune.