Why is dune refusing to download dependencies?

292 Views Asked by At

I expected dune to automatically download dependencies when running dune build, but that doesn't happen.

I've tried multiple variants of this, and I tried with ocaml versions 4.14 and 5.0, and with different dune versions written in the dune-project file (although I didn't try to manually download specific dune versions, I wasn't sure that would happen automatically), my globally installed dune version is the latest, 3.10.

This specific set of instructions below was tried in an empty directory, and following the instructions of dune's official documentation.

~> echo '(lang dune 3.10)' > dune-project
~> echo '(executable
          (name hello_world)
          (libraries core)
          (preprocess (pps ppx_jane)))' > dune
~> echo 'open Core

         let () =
           Sexp.to_string_hum [%sexp ([3;4;5] : int list)]
           |> print_endline' > hello_world.ml'
~> dune build
File "dune", line 3, characters 12-16:
3 |  (libraries core)
                ^^^^
Error: Library "core" not found.
-> required by _build/default/hello_world.exe
-> required by alias all
-> required by alias default
File "dune", line 4, characters 18-26:
4 |  (preprocess (pps ppx_jane)))
                      ^^^^^^^^
Error: Library "ppx_jane" not found.
-> required by _build/default/hello_world.pp.ml
-> required by alias all
-> required by alias default

The error I get is always related to dependencies not ever being found. I tried copying other projects, running other tutorials with different sets of dependencies and whatnot, it's always the same error. I tried to manually meddle with an .opam file, but it looks like dune just ignores that and rewrites it.

Running a project without any dependencies works fine.

1

There are 1 best solutions below

4
Chris On

Opam is the package manager for OCaml and its role is installing dependencies.

Dune on the other hand is a build system. The two have distinct roles.

Running dune build will give you errors about missing dependencies, but it should also update your project's opam file, allowing you to install the needed dependencies with opam install . --deps-only. Once this is done, dune build should succeed as long as the missing dependencies are the only source of errors.