dune

composable build system for OCaml projects

TLDR

Build the project
$ dune build
Run tests
$ dune test
Run an executable
$ dune exec [program]
Clean build artifacts
$ dune clean
Build and watch for changes
$ dune build --watch
Format code
$ dune fmt
Create new project
$ dune init project [name]

SYNOPSIS

dune command [options]

DESCRIPTION

Dune is the standard build system for OCaml and Reason projects. It automatically discovers project structure, handles dependencies, and provides fast incremental builds with caching.Projects are configured with dune files using an S-expression syntax. Dune integrates with opam for package management and supports cross-compilation, multiple build contexts, and IDE integration.

PARAMETERS

build [targets]

Build specified targets or all.
test
Run tests.
exec program
Build and execute program.
clean
Remove build artifacts.
init component name
Initialize new component (project, library, executable, test).
fmt
Format source code using ocamlformat.
promote
Promote expected test outputs.
cache
Manage the shared build artifact cache.
install
Install packages defined in the project.
--watch, -w
Rebuild continuously on file changes.
--force
Force rebuild of all targets.
--verbose
Display full command lines of executed programs.

CONFIGURATION

dune

Per-directory build configuration files using S-expression syntax defining libraries, executables, and tests.
dune-project
Project-level configuration at repository root specifying project metadata and language version.
dune-workspace
Optional workspace configuration for multi-context builds and advanced project settings.

DUNE FILE EXAMPLE

$ (library
 (name mylib)
 (libraries str unix))

(executable
 (name main)
 (libraries mylib))

(test
 (name test_mylib)
 (libraries mylib alcotest))

INSTALL

sudo apt install ocaml-dune
sudo dnf install ocaml-dune
sudo pacman -S dune
sudo apk add dune
sudo zypper install ocaml-dune
brew install dune
nix profile install nixpkgs#dune

CAVEATS

Requires OCaml or Reason compiler. Build artifacts go in the _build directory. Dune files use S-expression syntax, not YAML or TOML. Package management requires opam.

HISTORY

Dune was originally called jbuilder, created by Jane Street in 2016. It was renamed to Dune in 2018 and became the de facto standard build system for the OCaml ecosystem. The project aims to provide a modern, fast, and user-friendly build experience.

SEE ALSO

ocaml(1), opam(1), ocamlfind(1), make(1)