env

The env stanza allows one to modify the environment. The syntax is as follows:

(env
 (<profile1> <settings1>)
 (<profile2> <settings2>)
 ...
 (<profilen> <settingsn>))

The first form (<profile> <settings>) that corresponds to the selected build profile will be used to modify the environment in this directory. You can use _ to match any build profile.

Profiles are not declared by env stanzas. Any valid profile name can be selected on the command line or in dune-workspace. env stanzas only provide settings that are looked up later when a context is built with a matching profile. For example, a workspace context using (profile dbg) can pick up settings from an (env (dbg ...)) stanza in the project.

Fields supported in <settings> are:

  • any OCaml flags field. See OCaml Flags for more details.

  • (link_flags <flags>) specifies flags to OCaml when linking an executable. See executables stanza.

  • (c_flags <flags>) and (cxx_flags <flags>) specify compilation flags for C and C++ stubs, respectively. See library for more details.

  • (env_vars (<var1> <val1>) .. (<varN> <valN>)) will add the corresponding variables to the environment where the build commands are executed and are used by dune exec. This field has been available since Dune 3.24. The dashed spelling env-vars is also supported for compatibility.

  • (menhir_flags <flags>)) specifies flags for Menhir stanzas. This flag was replaced by the (menhir) field (see below) starting in version 3.0 of the Menhir extension.

  • (menhir (flags <flags>) (explain <blang expression>)) specifies the Menhir settings. See menhir for more details. This field was introduced in version 3.0 of the Menhir extension.

  • (js_of_ocaml (flags <flags>)(build_runtime <flags>)(link_flags <flags>)) specifies js_of_ocaml flags. See js_of_ocaml for more details.

  • (js_of_ocaml (compilation_mode <mode>)) controls whether to use separate compilation or not where <mode> is either whole_program or separate.

  • (js_of_ocaml (sourcemap <mode>)) controls whether to generate sourcemap or not where <mode> is either no, file (to generate sourcemap in a .map file next to the generated javascript file) or inline (to inline the sourcemap at the end of the generated JavaScript file).

  • (js_of_ocaml (runtest_alias <alias-name>)) specifies the alias under which Inline Tests and tests (tests) run for the js mode.

  • (js_of_ocaml (enabled_if <blang expression>)) specifies whether the js mode is enabled. It is enabled by default.

  • (wasm_of_ocaml (flags <flags>)(build_runtime <flags>)(link_flags <flags>)) specifies wasm_of_ocaml flags. See wasm_of_ocaml for more details.

  • (wasm_of_ocaml (compilation_mode <mode>)) controls whether to use separate compilation or not where <mode> is either whole_program or separate.

  • (wasm_of_ocaml (sourcemap <mode>)) controls whether to generate sourcemap or not where <mode> is either no, file (to generate sourcemap in a .map file next to the generated javascript file) or inline (to inline the sourcemap at the end of the generated JavaScript file).

  • (wasm_of_ocaml (runtest_alias <alias-name>)) specifies the alias under which Inline Tests and tests (tests) run for the wasm mode.

  • (wasm_of_ocaml (enabled_if <blang expression>)) specifies whether the wasm mode is enabled. It is enabled by default.

  • (binaries <binaries>), where <binaries> is a list of entries of the form (<filepath> as <name>). (<filepath> as <name>) makes the binary <filepath> available in the command search as just <name>. For instance, in a (run <name> ...) action, <name> will resolve to this file path. You can also write just the file path, in which case the name will be inferred from the basename of <filepath> by dropping the .exe suffix, if it exists. For example, (binaries bin/foo.exe (bin/main.exe as bar)) would add the commands foo and bar to the search path.

  • (inline_tests <state>), where <state> is either enabled, disabled, or ignored. This field has been available since Dune 1.11. It controls the variable’s value %{inline_tests}, which is read by the inline test framework. The default value is disabled for the release profile and enabled otherwise.

  • (odoc <fields>) allows passing options to odoc. See Passing Options to odoc for more details.

  • (rocq <rocq_fields>) allow passing options to Rocq. See Rocq Environment Fields for more details.

  • (formatting <settings>) allows the user to set auto-formatting in the current directory subtree (see formatting).

  • (bin_annot <bool>) allows the user to specify whether to generate *.cmt and *.cmti in the current directory subtree.