dune
Build OCaml projects reproducibly
TLDR
Build all targets
Clean up the workspace
Run all tests
Start the utop REPL with compiled modules automatically loaded into it, to remove the need to load them by hand
SYNOPSIS
dune
Common commands:
dune build [TARGET]
dune runtest
dune exec
dune install
dune clean
dune help [COMMAND]
PARAMETERS
-p, --profile
Set the build profile (e.g., 'dev', 'release').
--root
Set the root directory of the workspace.
--watch
Watch for file changes and rebuild automatically.
--display
Control the display mode of output (e.g., 'short', 'quiet', 'verbose').
--force
Force a rebuild of all targets, ignoring cached results.
DESCRIPTION
Dune is a sophisticated and highly efficient build system specifically crafted for OCaml and Reason projects.
It aims to streamline and automate the entire development workflow, from compiling source code to running tests and generating documentation.
Unlike general-purpose build tools, Dune is opinionated and leverages the structure of OCaml projects to provide sensible defaults, significantly reducing the amount of explicit configuration required. Its core strengths include automatic dependency tracking, parallel execution for faster builds, and ensuring reproducibility across diverse environments.
Dune operates by reading simple `dune` configuration files (S-expressions) placed within project directories, making project setup intuitive and maintainable. It has become the de-facto standard for building OCaml software, replacing older, more complex solutions.
CAVEATS
Dune is tightly coupled with the OCaml and Reason programming languages.
It is not a general-purpose build system for other languages or system-level tasks. A functional OCaml toolchain (typically managed by opam) must be installed for Dune to operate correctly.
SUBCOMMAND-BASED OPERATION
Dune is invoked using a subcommand-based interface. Instead of a single command with many options, specific tasks are handled by distinct subcommands (e.g., dune build, dune runtest), making its usage modular and clear.
DECLARATIVE CONFIGURATION WITH 'DUNE' FILES
Project configuration in Dune is managed through declarative 'dune' files. These S-expression-based files, placed in relevant directories, describe libraries, executables, tests, and other project artifacts, simplifying project setup and ensuring portability.
HISTORY
Dune evolved from Jenga, an internal build system developed at Jane Street, a prominent user of OCaml.
Initially open-sourced as Jbuilder, it was later renamed Dune to reflect its broader vision and independent identity within the OCaml ecosystem. Since its inception, it has rapidly become the community's preferred and effectively standard build tool for OCaml, replacing older, more disparate build approaches like custom Makefiles or ocamlbuild.