# Run \`ocamlc -i\` with \`dune\`

**URL:** <https://discuss.ocaml.org/t/run-ocamlc-i-with-dune/9876>\
**Category:** Learning\
**Created:** [May 17, 2022, 12:59pm UTC](https://discuss.ocaml.org/t/run-ocamlc-i-with-dune/9876 "2022-05-17T12:59:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![thierry-martinez](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/thierry-martinez/32/1481_2.png) [@thierry-martinez](https://discuss.ocaml.org/u/thierry-martinez)\
**Post date:** [May 17, 2022, 12:59pm UTC](https://discuss.ocaml.org/t/run-ocamlc-i-with-dune/9876/1 "2022-05-17T12:59:49Z")

</div>

How can we run `ocamlc -i` on a module that is supposed to be compiled with `dune` (with local and non-local libraries and possibly other things that make manual compilation outside dune non-trivial)?

Ideally, I would like to run the same command that dune uses to compile the module, but with the option `-i`. (I could copy-paste the output of `dune --verbose` and add the option manually, but there is probably a more convenient way!)

---

<div class="post-metadata">

**Author:** ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)\
**Post date:** [May 17, 2022, 1:02pm UTC](https://discuss.ocaml.org/t/run-ocamlc-i-with-dune/9876/2 "2022-05-17T13:02:19Z")

</div>

Is using `cmitomli` on the cmi file produced by dune not an option?

---

<div class="post-metadata">

**Author:** ![thierry-martinez](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/thierry-martinez/32/1481_2.png) [@thierry-martinez](https://discuss.ocaml.org/u/thierry-martinez)\
**Post date:** [May 17, 2022, 1:07pm UTC](https://discuss.ocaml.org/t/run-ocamlc-i-with-dune/9876/3 "2022-05-17T13:07:35Z")

</div>

Yes, it can work, thanks for the suggestion! If no one proposes a more direct solution (for instance, a solution that does not require to go manually in `_build/default/*/*.objs/byte/`), I will accept yours!

---

<div class="post-metadata">

**Author:** ![vds](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/vds/32/2013_2.png) [@vds](https://discuss.ocaml.org/u/vds)\
**Post date:** [May 17, 2022, 3:56pm UTC](https://discuss.ocaml.org/t/run-ocamlc-i-with-dune/9876/4 "2022-05-17T15:56:20Z")

</div>

You can write a custom rule to have Dune run `cmitomli` for you:

```auto
(rule
 (alias make_mli)
 (mode promote)
 (action
  (with-stdout-to mysig.sig 
   (run cmitomli %{cmi:path_to_module/wihout_extension}))))

```

And then run `dune @make_mli`.  
There is a lot of improvement that can be made and it probably need some adaptation…

The rule documentation: [Stanza Reference — dune documentation](https://dune.readthedocs.io/en/stable/dune-files.html#rule)  
Actions documentation: [General Concepts — dune documentation](https://dune.readthedocs.io/en/stable/concepts.html#user-actions-1)  
Specific variables for artifacts: [Other Topics — dune documentation](https://dune.readthedocs.io/en/stable/advanced-topics.html#variables-for-artifacts-1)

---

<div class="post-metadata">

**Author:** ![gadmm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/gadmm/32/877_2.png) [@gadmm](https://discuss.ocaml.org/u/gadmm)\
**Post date:** [May 17, 2022, 5:19pm UTC](https://discuss.ocaml.org/t/run-ocamlc-i-with-dune/9876/5 "2022-05-17T17:19:13Z")

</div>

Relevant previous discussion: [How can I generate .mli files from .ml files?](https://discuss.ocaml.org/t/how-can-i-generate-mli-files-from-ml-files/5427)

---

<div class="post-metadata">

**Author:** ![rgrinberg](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rgrinberg/32/40_2.png) [@rgrinberg](https://discuss.ocaml.org/u/rgrinberg)\
**Post date:** [May 17, 2022, 5:32pm UTC](https://discuss.ocaml.org/t/run-ocamlc-i-with-dune/9876/6 "2022-05-17T17:32:59Z")

</div>

It’s a bit of a shame we haven’t solved this in dune yet. There are problems in dune that make adding this feature not entirely trivial, but we should really fix the engine to accommodate features like this.

---

<div class="post-metadata">

**Author:** ![thierry-martinez](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/thierry-martinez/32/1481_2.png) [@thierry-martinez](https://discuss.ocaml.org/u/thierry-martinez)\
**Post date:** [May 17, 2022, 10:17pm UTC](https://discuss.ocaml.org/t/run-ocamlc-i-with-dune/9876/7 "2022-05-17T22:17:10Z")

</div>

Thank you all for your suggestions and pointers! Since `cmitomli` is the state of the art, I accept @octachron’s solution, but, yes, that would be great if `dune` could do this more conveniently!
