Default flags for the project

I have two questions regarding dune build flags.

  1. what are the default (standard) flags for ocamlopt, ocamlc, js_of_ocaml

and

  1. how to set default flags for the entire project (i.e. one containing many libs and exes)

As far as I understand I need a dune file in the root with the env stanza, something like

(env
 (release
  (ocamlopt_flags (:standard -O3 -unbox-closures))))

How to add js_of_ocaml flags to it?

The default depend on the build profile and are hard-coded in dune. You can find out the set of active flags for a given directory by running dune printenv. If you have no special configuration, this will give you the set of default flags:

$ dune printenv .
(
 (flags
  (-w
   @a-4-29-40-41-42-44-45-48-58-59-60-40
   -strict-sequence
   -strict-formats
   -short-paths
   -keep-locs))
 (ocamlc_flags (-g))
 (ocamlopt_flags (-g))
)
$ dune printenv --profile release .
(
 (flags (-w -40))
 (ocamlc_flags (-g))
 (ocamlopt_flags (-g))
)

To set the flags globally, you should indeed write an env stanza as you mentioned.

jsoo flags are currently not covered by this mechanism, but they indeed should. Do you mind opening an issue on the dune github project to track this feature?

3 Likes

I think it’s reported already, is it the same issue?

Indeed, it is the same

I’m new to ocaml/dune and trying to do the same project-wide configuration of the flags. I couldn’t figure out a way to add an env stanza to the dune-project file. Is it idiomatic to have top level dune-project and dune files?

Yes it is, but dune-project does not support the env stanza. Instead, use the dune-workspace file: dune-workspace — Dune documentation

As mentioned there, you put this file at the project root.

1 Like