DUNE-BUILD(1)
π dune-build β the manual, but make it make sense π
okay bestie, gather round, because this is the DUNE-BUILD(1) page from the Dune Manual and we're gonna get through it together. it's long. it's giving "reference documentation." but we're built different and we're gonna slay it. π¦
β¨ NAME β¨
dune-build β build the targets you asked for, or the default ones if you didn't ask for any. that's it. that's the whole vibe. π
πΈ SYNOPSIS πΈ
dune build [OPTION]β¦ [TARGET]β¦
π DESCRIPTION π
so here's the one thing to internalize: targets that start with a @ get interpreted as aliases. that's the whole description. no cap. π«Ά
π OPTIONS π
--action-stderr-on-success=VALβ same as--action-stdout-on-successbut for standard error instead of standard output. for big ol' mono-repos, a genuinely good default combo is--action-stdout-on-success=swallowplus--action-stderr-on-success=must-be-empty. why? because it guarantees a successful build has a "clean," empty output. iconic behavior honestly. β¨--action-stdout-on-success=VALβ tells Dune how to deal with the standard output of actions when they succeed. the possible values are:printβ just print it to Dune's output.swallowβ completely ignore it.must-be-emptyβ enforce that the action printed nothing. with this one, if the action printed anything to standard output, Dune will consider the action failed. π
the default is print.
--alias=ALIASβ buildALIASin its parent directory only. equivalent to the build target@@ALIAS. example:--alias dir/foobuilds thefooalias indir/only. repeatable, so you can stack 'em. π--alias-rec=ALIASβ build the aliasALIASin its parent directory and all subdirectories. equivalent to the build target@ALIAS. example:--alias-rec dir/foobuilds thefooalias indir/and all its subdirectories. also repeatable. π--build-infoβ show build information.--display-separate-messagesβ separate error messages with a blank line. a lil breathing room, bestie. π--error-reporting=VAL(absent=deterministic) β controls when build errors get reported:earlyβ reports errors as soon as they're discovered.deterministicβ reports errors at the end of the build, in a deterministic order.twiceβ reports each error twice: once as soon as it's discovered, and then again at the end of the build, in a deterministic order.
-f,--forceβ force actions associated with aliases to be re-executed even if their dependencies haven't changed. sometimes you just need a redo. π--file-watcher=VAL(absent=automatic) β the mechanism used to detect changes in the source.Automaticmeans dune runs an external program to detect changes.Manualmeans you notify dune that files have changed, yourself, manually, with your own two hands. π--passive-watch-modeβ similar to[--watch], but it only starts a build when instructed externally by an RPC.--sandbox=VAL(absentDUNE_SANDBOXenv) β set the sandboxing mode. heads up: some actions require a certain sandboxing mode, so they will ignore this setting. the allowed values are:none,symlink,copy,hardlink. π§--stop-on-first-errorβ stop the build as soon as an error is encountered. no finishing the race, we're pulling over. π-w,--watchβ instead of terminating the build after completion, wait continuously for file changes. it just keeps watching. like that one friend who never leaves the group chat. π₯--wait-for-filesystem-clockβ okay so Dune digests file contents for better incrementality, and those digests are themselves cached. in some cases, Dune needs to drop some digest cache entries in order for things to be reliable. this option makes Dune wait for the file system clock to advance, so that it doesn't need to drop anything. you should probably not care about this option; it's mostly useful for Dune developers to make Dune tests of the digest cache more reproducible. iykyk. π€
β COMMON OPTIONS β
these options are common to all commands, so they're basically the shared playlist. π§
--always-show-command-lineβ always show the full command lines of programs executed by dune.--auto-promoteβ automatically promote files. this is similar to runningdune promoteafter the build. β¨--build-dir=FILE(absentDUNE_BUILD_DIRenv) β specify the build directory. it's_buildif unspecified.--cache=VAL(absentDUNE_CACHEenv) β enable or disable Dune cache. one ofdisabled,enabled-except-user-rules, orenabled. default is`enabled-except-user-rules'.--cache-check-probability=VAL(absentDUNE_CACHE_CHECK_PROBABILITYenv) β check build reproducibility by re-executing randomly chosen rules and comparing their results with those stored in Dune cache. β οΈ note: by increasing the probability of such checks you slow down the build. the default probability is zero, i.e. no rules are checked.--cache-storage-mode=VAL(absentDUNE_CACHE_STORAGE_MODEenv) β Dune cache storage mode, one ofauto,hardlink, orcopy. default is`hardlink'.--config-file=FILEβ load this configuration file instead of the default one.--debug-backtracesβ always print exception backtraces.--debug-dependency-pathβ in case of error, print the dependency path from the targets on the command line to the rule that failed. detective mode. π--debug-package-logs(absentDUNE_DEBUG_PACKAGE_LOGSenv) β always print the standard logs when building packages.--default-target=TARGET(absent=@@default) β set the default target that's used when none is specified todune build.--diff-command=VAL(absentDUNE_DIFF_COMMANDenv) β shell command to use to diff files. use-to disable printing the diff.--disable-promotion(absentDUNE_DISABLE_PROMOTIONenv) β disable all promotion rules.--display=MODEβ control the display mode of Dune. seedune-config(5)for more details. valid values for this option areprogress,verbose,short,quietortui.--dump-gc-stats=FILEβ dump the garbage collector stats to a file after the build is complete.--help[=FMT](default=auto) β show this help in formatFMT. the valueFMTmust be one ofauto,pager,grofforplain. withauto, the format ispagerorplainwhenever theTERMenv var isdumbor undefined.--ignore-promoted-rulesβ ignore rules with(mode promote), except ones with(only ...). the variable%{ignoring_promoted_rules}in dune files reflects whether this option was passed or not.--instrument-with=BACKENDS(absentDUNE_INSTRUMENT_WITHenv) β enable instrumentation byBACKENDS.BACKENDSis a comma-separated list of library names, each one of which must declare an instrumentation backend.-j JOBS(absentDUNE_JOBSenv) β run no more thanJOBScommands simultaneously.JOBSmust be a positive integer orautoto auto-detect the number of cores (which is the default). πͺ--no-bufferβ do not buffer the output of commands executed by dune. by default dune buffers the output of subcommands, in order to prevent interleaving when multiple commands are executed in parallel. however, this can be an issue when debugging long running tests. with--no-buffer, commands have direct access to the terminal. β οΈ note that as a result their output won't be captured in the log file. you should use this option in conjunction with-j 1, to avoid interleaving. additionally you should use--verboseas well, to make sure that commands are printed before they're being executed.--no-configβ do not load the configuration file.--no-print-directoryβ suppress "Entering directory" messages.--only-packages=PACKAGESβ ignore stanzas referring to a package that isn't inPACKAGES.PACKAGESis a comma-separated list of package names. note that this has the same effect as deleting the relevant stanzas from dune files. it's mostly meant for releases. during development, it's likely that what you want instead is to build a particular<package>.installtarget. π‘-p PACKAGES,--for-release-of-packages=PACKAGES(required) β shorthand for--release --pkg=disabled --only-packages PACKAGE. π¨ you must use this option in your<package>.opamfiles, in order to build only what's necessary when your project contains multiple packages, as well as getting reproducible builds.--pkg=VALβ enable or disable package management. the default behaviour depends on whether a lock directory exists.--profile=VAL(absentDUNE_PROFILEenv) β select the build profile, for instancedevorrelease. the default isdev.--promote-install-files[=VAL](default=true) β promote any generated<package>.installfiles to the source tree.--releaseβ put dune into a reproducible release mode. shorthand for--root . --ignore-promoted-rules --no-config --profile release --always-show-command-line --promote-install-files --require-dune-project-file --default-target @install. you should use this option for release builds. for instance, you must use this option in your<package>.opamfiles. except if you already use-p, as-pimplies this option. π--require-dune-project-file[=VAL](default=true) β fail if adune-projectfile is missing.--root=DIR(absentDUNE_ROOTenv) β use this directory as workspace root instead of guessing it. note that this option doesn't change the interpretation of targets given on the command line. it's only intended for scripts. π€--store-orig-source-dir(absentDUNE_STORE_ORIG_SOURCE_DIRenv) β store original source location indune-packagemetadata.--target-exec=TOOLCHAIN=CMD(absentDUNE_TARGET_EXECenv) β wrapper command for running target binaries when cross-compiling. format:TOOLCHAIN=CMD(e.g.,'windows=wine').--terminal-persistence=MODEβ change how the log of build results is displayed to the console between rebuilds while in--watchmode. supported modes:preserve,clear-on-rebuild,clear-on-rebuild-and-flush-history.--trace-file=FILEβ output trace data in catapult format (compatible withchrome://tracing). π--verboseβ same as--display verbose.--versionβ show version information.--watch-exclusions=REGEXβ adds a POSIX regular expression that will exclude matching directories fromdune build --watch. the option--watch-exclusionscan be repeated to add multiple exclusions. semicolons can also be used as a separator. if no exclusions are provided, then a standard set of exclusions is used; however, if one or more--watch-exclusionsare used, none of the standard exclusions are used. the standard exclusions are:^_opam/_opam^_esy/_esy^\.#.*/\.#.*~$^#[^#]*#$/#[^#]*#$^4913$/4913$/.git/.hg:/windows. π«--workspace=FILE(absentDUNE_WORKSPACEenv) β use this specific workspace file instead of looking it up.-x VAL(absentDUNE_CROSS_TARGETenv) β cross-compile using this toolchain.
π«Ά MORE HELP π«Ά
use `dune COMMAND --help' for help on a single command. one command at a time, bestie, we got this. π
π EXIT STATUS π
dune build exits with:
0β on success. slay. π1β if an error happened. π130β if it was interrupted by a signal. π΅
and that's where part 1 wrapsβ¦ but we're not done, keep scrolling because there's more coming. π β¨
π ENVIRONMENT π
okay so these little environment variables? they're like the mood ring of build π
set them and they change how the whole thing behaves:
CLICOLORβ if it's anything other than0, ANSI colors are supported and should be used (as long as the program isn't piped, obviously π). If it's exactly0, bestie, no ANSI color escape codes for you.CLICOLOR_FORCEβ if this one is anything other than0, ANSI colors get enabled no matter what. zero chill, zero exceptions β¨DUNE_BUILD_DIRβ the build directory you're specifying. If you don't set it at all, it's just_build. lowkey the default everyone forgets exists πDUNE_CACHEβ turns the Dune cache on or off. pick one ofdisabled,enabled-except-user-rulesorenabled. The default?enabled-except-user-rules. she's the default girlie πDUNE_CACHE_CHECK_PROBABILITYβ checks build reproducibility by re-executing randomly chosen rules and comparing their results against what's stored in the Dune cache. β οΈ note bestie: cranking up this probability slows your build down, so it's not a free snack. Default probability is zero, aka no rules get checked, periodt.DUNE_CACHE_ROOTβ if you set it, it decides where all the different caches used by dune live. one root to rule them all π§DUNE_CACHE_STORAGE_MODEβ the Dune cache storage mode, one ofauto,hardlinkorcopy. Default ishardlinkπDUNE_CROSS_TARGETβ cross-compile using this toolchain. it's giving very much platform-hopping energy π¦DUNE_DEBUG_PACKAGE_LOGSβ always print the standard logs when building packages. no more "where did the logs go" moments πDUNE_DIFF_COMMANDβ the shell command used to diff files. want the diff to just not? use-to disable printing the diff entirely πDUNE_DISABLE_PROMOTIONβ disables all promotion rules. all of them. not one survivor πDUNE_INSTRUMENT_WITHβ enables instrumentation by BACKENDS. BACKENDS is a comma-separated list of library names, and every single one of them has to declare an instrumentation backend. no freeloaders allowed πΈDUNE_JOBSβ run no more than JOBS commands simultaneously. JOBS has to be a positive integer, orautoto auto-detect the number of cores. and yes,autois the default, because duh β¨DUNE_PROFILEβ the build profile.devif you don't specify anything, orreleaseif-pis set. your vibe, your choice πDUNE_ROOTβ use this directory as the workspace root instead of letting dune guess it. π«Ά heads up tho: this option does not change how targets given on the command line are interpreted. it's only intended for scripts, iykyk.DUNE_SANDBOXβ the sandboxing mode to use by default. (peep--sandboxfor the details π)DUNE_STORE_ORIG_SOURCE_DIRβ stores the original source location in thedune-packagemetadata. archival queen behavior π¦DUNE_TARGET_EXECβ wrapper command for running target binaries when cross-compiling. Format isTOOLCHAIN=CMD(e.g.,'windows=wine'). so fancy π·DUNE_WORKSPACEβ use this specific workspace file instead of going looking for one. no detective work needed π
π BUGS π
Spotted a bug? don't suffer in silence bestie, check the bug reports at:
https://github.com/ocaml/dune/issues
π SEE ALSO π
dune(1)β the main character, obviously π
π EXAMPLES π
- Build every target in the current source tree:
dune build
- Build targets inside the
./foo/bardirectory:
dune build ./foo/bar
- Build the minimal set of targets that tooling like Merlin needs (so useful for spotting errors fast, no cap):
dune build @check
- Run all the code formatting tools in-place:
dune build --auto-promote @fmt
aaaand that's the whole page bestie, you made it π this was Dune 3.24.1, DUNE-BUILD(1), go build something iconic πβ¨π
π¦ where this page comes from
- ubuntu stonking: ocaml-dune 3.24.1-4 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms