DUNE-FMT(1)

πŸ’… DUNE-FMT(1) β€” aka dune-fmt, straight outta the Dune manual (section 1, bestie) πŸŽ€

okay so you opened a manual page, and it's about formatting your source code. no cap, this is the glow-up your OCaml is begging for. let's get into it ✨


✨ NAME ✨

dune-fmt β€” format source code. that's it. that's the whole job. and it eats. πŸ’…


🌸 SYNOPSIS 🌸

dune fmt [OPTION]…

like, you run it, you give it options, it formats. iconic. πŸ¦‹


πŸ’– DESCRIPTION πŸ’–

so dune fmt runs the formatter on your source code. and the way it just... picks the formatter for you?? main character energy fr fr. you don't have to choose, it already knows:

  • ocamlformat gets used for OCaml source code β€” that's your *.ml and *.mli files 🧚
  • refmt gets used for Reason source code β€” that's your *.re and *.rei files πŸ’œ

so it looks at what you wrote, and it handles it. slay. no cap. 🌈


πŸ”₯ OPTIONS πŸ”₯

  • --action-stderr-on-success=VAL β€” literally the same as --action-stdout-on-success but for standard error instead of standard output. and ngl, a really good default for large mono-repositories is --action-stdout-on-success=swallow plus --action-stderr-on-success=must-be-empty. that combo means a successful build has a "clean" empty output. chef's kiss. πŸ‘‘
  • --action-stdout-on-success=VAL β€” tells Dune how to deal with an action's standard output when that action succeeds. 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 at all

and with must-be-empty, Dune will consider the action failed if it printed anything to standard output. 😭 the default is print.

  • --build-info β€” show build information. πŸŽ€
  • --display-separate-messages β€” separates error messages with a blank line. breathing room bestie 🌸
  • --error-reporting=VAL (absent=deterministic) β€” controls when build errors get reported. the options are:
    • early β€” reports errors as soon as they are 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

two-for-one, kinda obsessed 🫢

  • -f, --force β€” force actions associated with aliases to be re-executed even if their dependencies haven't changed. it's giving "I do what I want." πŸ’…
  • --file-watcher=VAL (absent=automatic) β€” the mechanism used to detect changes in the source. automatic makes dune run an external program to detect changes. manual means you notify dune that files have changed manually. πŸ¦‹
  • --passive-watch-mode β€” similar to --watch, but it only starts a build when it's instructed externally by an RPC. it just sits there, waiting for the group chat to ping it πŸ’€
  • --preview β€” just prints the changes that would be made, without actually applying them. and heads up: this takes precedence over auto-promote, because that flag is assumed for this command. πŸ‘€
  • --sandbox=VAL (absent DUNE_SANDBOX env) β€” sets the sandboxing mode. some actions require a certain sandboxing mode, so they'll ignore this setting. allowed values: none, symlink, copy, hardlink. 🧚
  • --stop-on-first-error β€” stops the build the second it hits an error. dramatic exit, love that for it 😭
  • -w, --watch β€” instead of terminating the build after completion, it waits continuously for file changes. it's got main character energy and it's not leaving the party πŸŽ€
  • --wait-for-filesystem-clock β€” ok 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 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's mostly useful for Dune developers to make Dune tests of the digest cache more reproducible.

🌈 COMMON OPTIONS 🌈

these options are common to all commands. yes, all of them. equal opportunity flags ✨

  • --always-show-command-line β€” always show the full command lines of programs executed by dune. full transparency, we love to see it πŸ’œ
  • --auto-promote β€” automatically promote files. this is similar to running dune promote after the build. πŸ¦‹
  • --build-dir=FILE (absent DUNE_BUILD_DIR env) β€” specified build directory. it's _build if unspecified. πŸ“
  • --cache=VAL (absent DUNE_CACHE env) β€” enable or disable Dune cache. one of disabled, enabled-except-user-rules or enabled. the default is enabled-except-user-rules. πŸ”₯
  • --cache-check-probability=VAL (absent DUNE_CACHE_CHECK_PROBABILITY env) β€” 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. so like, zero is free. πŸ“
  • --cache-storage-mode=VAL (absent DUNE_CACHE_STORAGE_MODE env) β€” Dune cache storage mode, one of auto, hardlink or copy. 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. follow the crime scene tape 🚨
  • --debug-package-logs (absent DUNE_DEBUG_PACKAGE_LOGS env) β€” always print the standard logs when building packages. πŸ“œ
  • --default-target=TARGET (absent=@@default) β€” set the default target that is used when none is specified to dune build. 🎯
  • --diff-command=VAL (absent DUNE_DIFF_COMMAND env) β€” shell command to use to diff files. use - to disable printing the diff. πŸ™ˆ
  • --disable-promotion (absent DUNE_DISABLE_PROMOTION env) β€” disable all promotion rules. 🚫
  • --display=MODE β€” control the display mode of Dune. see dune-config(5) for more details. valid values for this option are progress, verbose, short, quiet or tui. pick your aesthetic πŸ‘‘
  • --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 format FMT. the value FMT must be one of auto, pager, groff or plain. with auto, the format is pager or plain whenever the TERM env var is dumb or 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 (absent DUNE_INSTRUMENT_WITH env) β€” enable instrumentation by BACKENDS. BACKENDS is a comma-separated list of library names, and each one of them must declare an instrumentation backend. πŸ”¬
  • -j JOBS (absent DUNE_JOBS env) β€” run no more than JOBS commands simultaneously. JOBS must be a positive integer or auto to auto-detect the number of cores (that's 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 --verbose as well, to make sure that commands are printed before they are being executed. a whole little ritual, honestly πŸ•―οΈ
  • --no-config β€” do not load the configuration file. πŸ™…
  • --no-print-directory β€” suppress "Entering directory" messages. quiet luxury πŸ’…
  • --only-packages=PACKAGES β€” ignore stanzas referring to a package that is not in PACKAGES. PACKAGES is 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>.install target. πŸ‘€
  • -p PACKAGES, --for-release-of-packages=PACKAGES (required) β€” shorthand for --release --pkg=disabled --only-packages PACKAGE. you must use this option in your <package>.opam files, in order to build only what's necessary when your project contains multiple packages, as well as getting reproducible builds. periodt πŸ“Œ
  • --pkg=VAL β€” enable or disable package management. the default behaviour depends on whether a lock directory exists. πŸ”
  • --profile=VAL (absent DUNE_PROFILE env) β€” select the build profile, for instance dev or release. the default is dev. πŸŽ€
  • --promote-install-files[=VAL] (default=true) β€” promote any generated <package>.install files 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>.opam files β€” except if you already use -p, as -p implies this option. ✨
  • --require-dune-project-file[=VAL] (default=true) β€” fail if a dune-project file is missing. no file, no vibes πŸ’€
  • --root=DIR (absent DUNE_ROOT env) β€” use this directory as the 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 (absent DUNE_STORE_ORIG_SOURCE_DIR env) β€” store original source location in dune-package metadata. πŸ“
  • --target-exec=TOOLCHAIN=CMD (absent DUNE_TARGET_EXEC env) β€” 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 --watch mode. supported modes: preserve, clear-on-rebuild, clear-on-rebuild-and-flush-history. πŸ–₯️
  • --trace-file=FILE β€” output trace data in catapult format (compatible with chrome://tracing). πŸ”
  • --verbose β€” same as --display verbose. wordy queen πŸ‘‘
  • --version β€” show version information. 🏷️
  • --watch-exclusions=REGEX β€” adds a POSIX regular expression that will exclude matching directories from dune build --watch. the option --watch-exclusions can 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-exclusions are used, none of the standard exclusions are used. the standard exclusions are:
^_opam /_opam ^_esy /_esy ^\.#.* /\.#.* ~$ ^#[^#]*#$ /#[^#]*#$ ^4913$ /4913$ /.git /.hg :/windows

🚫

  • --workspace=FILE (absent DUNE_WORKSPACE env) β€” use this specific workspace file instead of looking it up. πŸ”Ž
  • -x VAL (absent DUNE_CROSS_TARGET env) β€” cross-compile using this toolchain. 🌍

🫢 MORE HELP 🫢

use dune COMMAND --help for help on a single command. one command at a time, bestie, we're doing this right πŸ’–


⭐ EXIT STATUS ⭐

dune fmt exits with:

  • 0 β€” on success. we love a win πŸŽ‰
  • 1 β€” if an error happened. it's giving unfortunate 😭
  • 130 β€” if it was interrupted by a signal. πŸ’€

lowkey obsessed with you for reading the docs, fr fr. more coming πŸ‘€βœ¨

🌿 ENVIRONMENT 🌿

okay so these little environment variables? they literally change how fmt runs, bestie. set them, unset them, whatever β€” but know what they do first πŸ’…

  • CLICOLOR β€” if this is anything other than 0, then ANSI colors are supported and should be used whenever the program isn't piped. but if it's equal to 0? no ANSI color escape codes for you, periodt. 🎨
  • CLICOLOR_FORCE β€” if this is different than 0, ANSI colors get enabled no matter what. like, it doesn't care. it said what it said. ✨
  • DUNE_BUILD_DIR β€” the build directory you want specified. and if you don't say anything? it's _build. default behavior, iconic. πŸ“
  • DUNE_CACHE β€” turn Dune cache on or off. your options are one of disabled, enabled-except-user-rules or enabled. and the default? it's `enabled-except-user-rules'. that's just the vibe it ships with. πŸ’Ύ
  • DUNE_CACHE_CHECK_PROBABILITY β€” this one checks build reproducibility by re-executing randomly chosen rules and comparing the results against what's stored in Dune cache. ⚠️ note: if you crank up the probability of these checks, you slow down the build. lowkey a tradeoff. the default probability is zero, meaning like, no rules get checked. not one. πŸ™ˆ
  • DUNE_CACHE_ROOT β€” if you set this, it determines where all the different caches that dune uses live. one home for all of them. 🏠
  • DUNE_CACHE_STORAGE_MODE β€” Dune cache storage mode, and it's one of auto, hardlink or copy. default is `hardlink'. ✨
  • DUNE_CROSS_TARGET β€” cross-compile using this toolchain. πŸ› οΈ
  • DUNE_DEBUG_PACKAGE_LOGS β€” always print the standard logs when building packages. always. every time. main character logging energy. πŸ“œ
  • DUNE_DIFF_COMMAND β€” the shell command to use for diffing files. and if you use -? that disables printing the diff entirely. bye diff. πŸ’€
  • DUNE_DISABLE_PROMOTION β€” disables all promotion rules. all of them. 🚫
  • DUNE_INSTRUMENT_WITH β€” enable instrumentation by BACKENDS. BACKENDS here is a comma-separated list of library names, and each single one of them has to declare an instrumentation backend. no backend declared, no deal. πŸ”¬
  • DUNE_JOBS β€” run no more than JOBS commands at the same time. JOBS has to be a positive integer, or auto to auto-detect the number of cores (and auto is the default, bestie). βš™οΈ
  • DUNE_PROFILE β€” the build profile. it's dev if unspecified, or release if -p is set. 🌸
  • DUNE_ROOT β€” use this directory as the workspace root instead of letting it guess. πŸ“Œ but heads up: 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 --sandbox for more πŸ‘€)
  • DUNE_STORE_ORIG_SOURCE_DIR β€” stores the original source location in the dune-package metadata. πŸ“¦
  • DUNE_TARGET_EXEC β€” wrapper command for running target binaries when cross-compiling. the format is: TOOLCHAIN=CMD (for example, 'windows=wine'). 🍷
  • DUNE_WORKSPACE β€” use this specific workspace file instead of hunting it down. πŸ”

πŸ› BUGS πŸ›

found something cursed? check the bug reports at https://github.com/ocaml/dune/issues β€” that's where the receipts live, bestie πŸ’–


πŸ‘€ SEE ALSO πŸ‘€

  • dune(1) β€” literally go read it, it's right there 🌟

and that's the whole page!! this was Dune 3.24.1, served up fresh as DUNE-FMT(1) ✨ mwah, go format something gorgeous πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from