ocamlopamdune

How to add a library dependency in a dune project that manages the .opam file without an intermediate build error?


dune will generate and update a project's .opam file when you run dune build, letting you just manage the project's dependencies in dune-project.

However, this seems to require an awkward step when adding a new dependency. The only sequence of events I can figure out seems to be:

  1. Add new dependencies to dune-project's depends stanza.
  2. dune build: updates the .opam file with the new dependency, and fails with errors about the missing new dependencies.
  3. opam install . --deps-only
  4. dune build: succeeds.

Is this the intended flow? The step in which dune build fails with errors, in order to get the side effect of updating the .opam file, seems incorrect.

Is there either a dune subcommand that just updates the opam file with the dependencies in dune-project, or a dune subcommand that will update the opam file and also update the installed dependencies according to the updated opam file, as part of the build step?

Or is the above sequence of events the intended flow?


Solution

  • The intended flow is: