# Default flags for the project

**URL:** <https://discuss.ocaml.org/t/default-flags-for-the-project/3217>\
**Category:** Ecosystem\
**Tags:** dune\
**Created:** [January 22, 2019, 8:22am UTC](https://discuss.ocaml.org/t/default-flags-for-the-project/3217 "2019-01-22T08:22:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freyr666](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/freyr666/32/591_2.png) [@Freyr666](https://discuss.ocaml.org/u/Freyr666)\
**Post date:** [January 22, 2019, 8:23am UTC](https://discuss.ocaml.org/t/default-flags-for-the-project/3217/1 "2019-01-22T08:23:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jeremiedimino](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jeremiedimino/32/699_2.png) [@jeremiedimino](https://discuss.ocaml.org/u/jeremiedimino)\
**Post date:** [January 22, 2019, 5:36pm UTC](https://discuss.ocaml.org/t/default-flags-for-the-project/3217/2 "2019-01-22T17:36:04Z")

</div>

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:

```auto
$ 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?

---

<div class="post-metadata">

**Author:** ![Freyr666](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/freyr666/32/591_2.png) [@Freyr666](https://discuss.ocaml.org/u/Freyr666)\
**Post date:** [January 23, 2019, 7:38am UTC](https://discuss.ocaml.org/t/default-flags-for-the-project/3217/3 "2019-01-23T07:38:48Z")

</div>

> [@jeremiedimino](#):
>
> Do you mind opening an issue on the dune github project to track this feature?

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

> <https://github.com/ocaml/dune/issues/1613>
>
> I want to use different js\_of\_ocaml flags in my project, depending on whether we… are in dev or release profile.
> 
> Dune \[already adds\](https://github.com/ocaml/dune/blob/55531596991f0f2d3b60f24183ea0eb3f80c2fd6/src/js\_of\_ocaml\_rules.ml#L12) \`--pretty\` and \`--source-maps-inline\` in dev, however, there are more jsoo options to play with, and I get dramatically better debugging with the \[recommended settings\](https://ocsigen.org/js\_of\_ocaml/dev/manual/options):
> 
> \`\`\`
> For Debugging: "–pretty –no-inline –debug-info" + eventually "–disable staticeval –disable share"
> For Production: "–opt 3". It minimize the generated javascript by applying various optimizations until a fix-point is reached
> \`\`\`
> 
> I tried using an \`env\` block, but couldn't make it work any way I tried it. Is there an existing way to do this, and if not:
> \- can a way to do this be added?
> \- can we pick better defaults for the dev and production env?

---

<div class="post-metadata">

**Author:** ![jeremiedimino](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jeremiedimino/32/699_2.png) [@jeremiedimino](https://discuss.ocaml.org/u/jeremiedimino)\
**Post date:** [January 24, 2019, 9:27am UTC](https://discuss.ocaml.org/t/default-flags-for-the-project/3217/4 "2019-01-24T09:27:22Z")

</div>

Indeed, it is the same

---

<div class="post-metadata">

**Author:** ![thekkid](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/thekkid/32/5479_2.png) [@thekkid](https://discuss.ocaml.org/u/thekkid)\
**Post date:** [August 20, 2024, 8:36pm UTC](https://discuss.ocaml.org/t/default-flags-for-the-project/3217/5 "2024-08-20T20:36:46Z")

</div>

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-projec`t file. Is it idiomatic to have top level `dune-project` and `dune` files?

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [August 20, 2024, 11:20pm UTC](https://discuss.ocaml.org/t/default-flags-for-the-project/3217/6 "2024-08-20T23:20:22Z")

</div>

> [@thekkid](#):
>
> 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](https://dune.readthedocs.io/en/stable/reference/dune-workspace/index.html)

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