The (mode opam) build mode enables dune to build non-dune packages using their
opam build instructions.
Many OCaml packages use ./configure && make, topkg, oasis, or custom scripts.
Dune runs these build commands in a sandboxed environment with opam variables
expanded.
(vendor dir (mode opam))explicitly specified- Vendored directory has opam file but no dune files (auto-detected)
- Locked package has non-dune build commands
All opam variables are supported:
| Category | Variables |
|---|---|
| Global | %{make}%, %{jobs}%, %{arch}%, %{os}%, %{os-family}%, %{os-distribution}%, %{os-version}% |
| Directories | %{prefix}%, %{lib}%, %{bin}%, %{share}%, %{etc}%, %{doc}%, %{man}%, %{stublibs}% |
| Package | %{name}%, %{version}%, %{build}%, %{build-id}% |
| Cross-package | %{pkg:var}%, %{pkg:installed}%, %{pkg:enable}% |
Conditional commands are evaluated based on platform:
build: [
[make] {os = "linux"}
[nmake] {os = "win32"}
["./configure" "--prefix=%{prefix}%"] {os != "win32"}
]
substs:files are processed (config.ml.in→config.mlwith variables expanded)patches:are applied, including conditional patches
patches: [
"fix.patch"
"linux-only.patch" {os = "linux"}
]
build-env:sets environment for build commandssetenv:exports variables to dependent packages
_build/.pkgs/<context>/<name>/
source/ # Linked from duniverse/ or fetched to _build/.pkgs/
target/ # Build artifacts
With (install false), the build-id is included:
_build/.pkgs/<context>/<name>-<build-id>/
Content-addressable hash for deterministic caching. Same mechanism for locked and vendored packages:
build_id(pkg) = hash(
opam_file_hash, # includes url checksum for released packages
sorted(deps_build_ids), # Merkle tree over dependencies
platforms_hash
)
For vendored packages without an opam file url field, dune computes a checksum from the source directory contents.
Artifacts install to _build/install/<context>/:
- Binaries →
bin/ - Libraries →
lib/<name>/ - Stubs →
lib/stublibs/
Dune sets PATH, OCAMLPATH, CAML_LD_LIBRARY_PATH for dependent packages.
Dune sets up:
OCAMLFIND_TOOLCHAIN=<target>- Sysroot paths
- Cross-compiler variables
Non-dune packages work with cross-compilation without modification.