A Composable Build System for OCaml
Dune is a build system for OCaml. It provides a consistent experience and takes care of the low-level details of OCaml compilation. You need only to provide a description of your project, and Dune will do the rest.
Dune implements a scheme that's inspired from the one used inside Jane Street and adapted to the open source world. It has matured over a long time and is used daily by hundreds of developers, meaning it's highly tested and productive.
Dune comes with a manual. If you want to get started without reading too much, look at the quick start guide or watch this introduction video.
The example directory contains examples of projects using Dune.
How does it work?
Dune reads project metadata from
dune files, which are static files with a
simple S-expression syntax. It uses this information to setup build rules,
generate configuration files for development tools such as Merlin,
handle installation, etc.
Dune itself is fast, has very little overhead, and supports parallel builds on all platforms. It has no system dependencies. OCaml is all you need to build Dune and packages using Dune.
In particular, one can install OCaml on Windows with a binary installer and then use only the Windows Console to build Dune and packages using Dune.
Dune is composable, meaning that multiple Dune projects can be arranged together, leading to a single build that Dune knows how to execute. This allows for monorepos of projects.
Dune makes simultaneous development on multiple packages a trivial task.
Gracefully Handles Multi-Package Repositories
Dune knows how to handle repositories containing several packages. When building via opam, it is able to correctly use libraries that were previously installed, even if they are already present in the source tree.
The magic invocation is:
$ dune build --only-packages <package-name> @install
Build Against Several Configurations at Once
Dune can build a given source code repository against several configurations simultaneously. This helps maintaining packages across several versions of OCaml, as you can test them all at once without hassle.
In particular, this makes it easy to handle cross-compilation. This feature requires opam.
Dune requires OCaml version 4.08.0 to build itself and can build OCaml projects using OCaml 4.02.3 or greater.
We recommended installing Dune via the opam package manager:
$ opam install dune
If you are new to opam, make sure to run
eval $(opam config env) to make
dune available in your
dune binary is self-contained and
relocatable, so you can safely copy it somewhere else to make it permanently
You can also build it manually with:
$ make release $ make install
If you do not have
make, you can do the following:
$ ocaml boot/bootstrap.ml $ ./dune.exe build -p dune --profile dune-bootstrap $ ./dune.exe install dune
The first command builds the
dune.exe binary. The second builds the additional
files installed by Dune, such as the man pages, and the last simply installs
all of that on the system.
Please note: unless you ran the optional
./configure script, you can
dune.exe anywhere and it will just work.
dune is fully
relocatable and discovers its environment at runtime rather than hard-coding it
at compilation time.
If you have questions or issues about Dune, you can ask in our GitHub discussions page or open a ticket on GitHub.