Search code examples
ocamlocaml-dune

What's the purpose of a package.opam file in dune?


The Dune documentation writes:

A typical dune project will have a dune-project and one or more .opam file at the root as well as dune files wherever interesting things are: libraries, executables, tests, documents to install, etc…

What's the purpose of this package-name.opam file at the root? As far as I can tell it has something to do with packaging things up nicely for export to opam, but if we don't want to publish our code as a package to opam, is there no other purpose for the package.opam file?


Solution

  • The opam file is considered by the opam CLI to be the source of truth for installing the dependencies of the project. Nowadays, we are encouraged to put our actual project dependencies in the dune-project file and let dune generate the opam file for us.

    But opam itself doesn't know about dune or dune-project. If you go to a directory which contains an opam file and run opam install --deps-only to install its dependencies, it looks for the listing in the opam file.