LinuxCommandLibrary

dune

Build OCaml projects reproducibly

TLDR

Build all targets

$ dune build
copy

Clean up the workspace
$ dune clean
copy

Run all tests
$ dune runtest
copy

Start the utop REPL with compiled modules automatically loaded into it, to remove the need to load them by hand
$ dune utop
copy

SYNOPSIS

dune [GLOBAL-OPTIONS]... COMMAND [COMMAND-OPTIONS] [ARGS]...

PARAMETERS

--root <path>
    Root directory of the project

--build-dir <path>
    Build directory (default: _build)

--workspace <file>
    Load this workspace instead of using dune-workspace files

--x
    Allow using unstable features of Dune

--no-print-directory
    Do not print working directory header

--profile <name>
    Select build profile (default, release, dev)

-j <jobs>
    Run up to <jobs> parallel jobs

--help
    Display help

--version
    Print version information

DESCRIPTION

Dune is a composable build system for OCaml and Reason projects, emphasizing speed, reliability, and simplicity. It uses a declarative dune configuration file to define build rules, automatically handling dependencies, parallel execution, and sandboxing for reproducible builds. Dune supports multi-language projects, including C, JavaScript via js_of_ocaml, and more. Key features include incremental builds with fine-grained invalidation, promotion of generated files from _build to source tree, and seamless integration with OPAM for package management. Originally designed for large-scale projects at Jane Street, it scales from small libraries to monorepos. Dune replaces complex Makefiles with a minimal syntax, reducing boilerplate while maintaining performance superior to traditional tools like ocamlbuild or omake. Widely used in the OCaml ecosystem.

CAVEATS

Dune requires OCaml >= 4.08.0. Install via OPAM: opam install dune. Not a standard distro package; project-specific dune files needed.

COMMON SUBCOMMANDS

build: Build the project
clean: Remove build directory
exec <exe>: Run executable
install: Install libraries/executables
runtest: Run tests
fmt: Format code with ocamlformat

EXAMPLE DUNE FILE

(executable (public_name hello) (libraries core))
Builds hello.exe from hello.ml using Core library.

HISTORY

Originated as JBuilder in 2016 by Jane Street engineers. Renamed Dune in 2017 for better branding. Reached version 1.0 in 2018, becoming the official OCaml build tool. Actively maintained by OCaml core team and contributors; version 3.x introduced advanced features like artifacts and remote builds.

SEE ALSO

make(1), ninja(1), ocaml(1), opam(1), ocamlbuild(1)

Copied to clipboard