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

1

9

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?

Witter answered 9/4, 2023 at 20:44 Comment(0)
F
-1

The intended flow is:

  • opam install newdependency1 newdependency2 ...
  • edit dune-project
  • dune build
Flin answered 12/12, 2023 at 18:43 Comment(3)
But HOW do you edit dune project?Sardella
If you had (depends dep1) and want to add dep2 and dep3 you must change it to: (depends dep1 dep2 dep3). `Flin
To me this is an acceptable answer to the question, because my question was really two questions: 1) if it's possible, how can I use the flow I described, and 2) is this the intended flow. This answer says that (2) what I described is not the intended flow. I assume, then,, that there is no way to do what I described.Witter

© 2022 - 2024 — McMap. All rights reserved.