DUNE-EXEC(1)
π dune-exec β the dune exec glow-up guide π
okay bestie, sit down, hydrate, and let me tell you about dune-exec from the Dune Manual. This is the one where you get to run your stuff in basically the same environment as if you'd actually installed it. iconic behaviour honestly. π
β¨ NAME β¨
dune-exec β run a command in an environment that's ~basically~ the same as if an installation had actually gone down. no cap.
πΈ SYNOPSIS πΈ
dune exec [OPTION]β¦ PROG [ARGS]β¦
π¦ DESCRIPTION π¦
so here's the tea: dune exec -- COMMAND should behave exactly like if you did this whole ritual:
$ dune install
$ COMMAND
like, same energy, same outcome. fr fr.
and specifically? if you run dune exec ocaml, you get access to all the libraries defined in your workspace using your usual directives (think #require and friends). yes bestie, it just works. π
now, the path girlies need to pay attention:
- When a leading
/is present in the command (absolute path), then the path is interpreted as an absolute path. - When a
/is present at any other position (relative path), then the path is interpreted as relative to the build context + current working directory (or the value of--rootwhen you run it outside of the project root).
it's giving "know where you are before you run things." π§
π OPTIONS π
okay this is the long part, but every single one matters, so we're doing all of them. no skipping. periodt.
--action-stderr-on-success=VALβ literally the same as--action-stdout-on-successexcept it's for standard error instead of standard output. and if you're in a big ol' mono-repo, the slay combo is--action-stdout-on-success=swallow --action-stderr-on-success=must-be-empty. that combo guarantees a successful build has a "clean" empty output. chef's kiss. β¨--action-stdout-on-success=VALβ this one controls how Dune deals with the standard output of actions when they ~succeed~. the possible values are:printβ just print it to Dune's outputswallowβ completely ignore itmust-be-emptyβ enforce that the action printed nothing. withmust-be-empty, Dune will consider the action failed if it printed anything to its standard output. π
the default is print.
--build-infoβ show build information. simple. cute. useful.--context=CONTEXT(absent=default) β run the command in this build context.--display-separate-messagesβ separate error messages with a blank line. breathing room for your errors, we love to see it.--error-reporting=VAL(absent=deterministic) β controls when build errors get reported. the options:earlyβ reports errors as soon as they are discovereddeterministicβ reports errors at the end of the build, in a deterministic ordertwiceβ 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 to aliases to be re-executed even if their dependencies haven't changed. pushing through regardless, respect. πͺ--file-watcher=VAL(absent=automatic) β the mechanism to detect changes in the source.Automaticmakes dune run an external program to detect changes.Manualmeans you notify dune that files have changed manually. you're in charge, bestie.--no-buildβ don't rebuild target before executing. straight to the good part.--passive-watch-modeβ similar to[--watch], but it only starts a build when instructed externally by an RPC. it waits for the signal like a good student. π«Ά--sandbox=VAL(absentDUNE_SANDBOXenv) β set sandboxing mode. 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 dragging it out.-w,--watchβ instead of terminating the build after completion, it waits continuously for file changes. she's committed. π--wait-for-filesystem-clockβ Dune digests file contents for better incrementality, and these 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 it doesn't need to drop anything. you should probably not care about this option; it is mostly useful for Dune developers to make Dune tests of the digest cache more reproducible. (iykyk, if you're not a Dune dev, this is not your problem, bestie. π)
π COMMON OPTIONS π
these ones are common to all commands, so they show up everywhere like that one friend who's at every party. π
--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) β specified build directory._buildif unspecified.--cache=VAL(absentDUNE_CACHEenv) β enable or disable Dune cache. one ofdisabled,enabled-except-user-rulesorenabled. default isenabled-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,hardlinkorcopy. default ishardlink.--config-file=FILEβ load this configuration file instead of the default one.--debug-backtracesβ always print exception backtraces. the receipts, forever.--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 is 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. garbage collection data?? we love an informed queen. ποΈβ¨--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 (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 are 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 is not 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 is mostly meant for releases. during development, it is 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. mandatory, bestie. π--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 is 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 are 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 be also 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. like, if you want the deep lore on just one command, that's your girl. π
π EXIT STATUS π
so when dune exec finishes, here's the vibe check on what it hands back to you:
0β it worked bestie!! success, slay, everything ate β¨1β okay so something went wrong, an error happened π130β it got interrupted by a signal π (yes this is the classic "someone hit Ctrl+C" number)
π ENVIRONMENT π
these env vars are the little backstage crew that changes how exec behaves. know them, love them π
DUNE_BUILD_DIRβ tells Dune which build directory to use. if you don't say anything it's_build, periodt.DUNE_CACHEβ turns the Dune cache on or off. pick one ofdisabled,enabled-except-user-rules, orenabled. the default isenabled-except-user-rulesπDUNE_CACHE_CHECK_PROBABILITYβ this one checks whether your builds are reproducible by re-running randomly chosen rules and comparing the results to what's stored in the Dune cache. > β οΈ heads up bestie: cranking up this probability slows your build down. the default probability is zero, meaning literally no rules get checked.DUNE_CACHE_STORAGE_MODEβ how the Dune cache stores stuff. pick one ofauto,hardlink, orcopy. default ishardlinkβ¨DUNE_CROSS_TARGETβ cross-compile using this toolchain.DUNE_DEBUG_PACKAGE_LOGSβ always prints the standard logs when building packages. no crumbs hidden πDUNE_DIFF_COMMANDβ the shell command used to diff files. use-to disable printing the diff entirely.DUNE_DISABLE_PROMOTIONβ disables all promotion rules, every single one π«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 backend, no dice.DUNE_JOBSβ run no more than JOBS commands at the same time. JOBS has to be a positive integer, orautoto auto-detect the number of cores (which is the default, and honestly a very good default π).DUNE_PROFILEβ the build profile. it'sdevif unspecified, orreleaseif-pis set.DUNE_ROOTβ use this directory as the workspace root instead of letting Dune guess. > ngl this one's a little special: it doesn't change how targets given on the command line are interpreted. it is 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 inside thedune-packagemetadata.DUNE_TARGET_EXECβ a wrapper command for running target binaries when you're cross-compiling. format:TOOLCHAIN=CMD(like, for example,'windows=wine').DUNE_WORKSPACEβ use this specific workspace file instead of looking one up.
π BUGS π
found something cursed? check the bug reports at https://github.com/ocaml/dune/issues β the devs wanna hear it fr fr
π SEE ALSO π
dune(1)β the main character, go read it
πΈ EXAMPLES πΈ
- run the executable named
my_exec:
dune exec my_exec
- run the executable defined in
foo.mlwith the argumentarg:
dune exec -- ./foo.exe arg
and that's the whole page bestie, you made it to the end π this was Dune 3.24.1, page DUNE-EXEC(1), so go forth and dune exec your little heart out. obsessed with you. bye!! πβ¨π¦
π¦ 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