dune icon indicating copy to clipboard operation
dune copied to clipboard

dune pkg ignores :dev dependencies

Open edwintorok opened this issue 1 year ago • 6 comments

Expected Behavior

dune utop works

Actual Behavior

dune utop
    Building ocaml.5.2.0        
File "_build/default", line 1, characters 0-0:
Error: Library "utop" not found.
-> required by _build/default/.utop/utop.bc

Reproduction

1.dune init project dune_utop_test 1.cd dune_utop_test 1.Change the depends line to (depends ocaml dune (utop :dev)) 1.dune pkg lock 1.dune build 1.dune utop

Specifications

  • Version of dune (output of dune --version):
"Dune Developer Preview: build 2024-09-28T01:30:13+00:00, git revision
17071ec30d10390badcb6cb1f6a43984b1be54a6"
  • Version of ocaml (output of ocamlc --version):
dune exec ocamlc -- --version
5.2.0                               
  • Operating system (distribution and version): Fedora 40

Additional information

Would be good if utop and other "tools" could be added to the "dev dependencies" lock, without actually becoming visible/available for the project itself. opam doesn't really have good support for this either (there is some limited support for installing e.g. the opam monorepo plugin into a tools switch?), but the new dune preview seems to support separate developer tool lockfiles, where tools like the LSP server, and ocamlformat go.

edwintorok avatar Sep 29 '24 21:09 edwintorok

Actually I'm not sure whether :dev depencies would be the right way to support utop, they're probably more appropriate for optional dependencies (e.g. benchmarking tools) that you do want available in your build environment to activate various optional build rules.

dune already has a dune utop subcommand, so it'd be good if that installed utop as a dev tool automatically, just like how dune fmt installs ocamlformat.

edwintorok avatar Sep 30 '24 08:09 edwintorok

I think the right way in OPAM parlance is to mark these dependencies is to use the :with-dev-setup variable.

Leonidas-from-XIV avatar Sep 30 '24 14:09 Leonidas-from-XIV

FWIW, dune pkg also ignores :with-dev-setup.

TOTBWF avatar Jan 20 '25 17:01 TOTBWF

Hello, is there a workaround before this is fixed? I've tried manually installing utop with opam, but dune still doesn't pick it up. After opam install utop, dune utop still complains Library "utop" not found.

blurrcat avatar May 26 '25 20:05 blurrcat

@blurrcat Are you sure it is installed in the right switch? That should work, since it is independent of dune pkg.

Leonidas-from-XIV avatar May 27 '25 08:05 Leonidas-from-XIV

That was my understanding too, but it didn't work.

I'm using a local switch:

➜  which utop
/home/han/workspace/golden-sheaf/_opam/bin/utop
➜  which dune
/home/han/workspace/golden-sheaf/_opam/bin/dune

When running dune utop

➜ opam exec -- dune utop  # or just `dune utop`
File "_build/default", line 1, characters 0-0:
Error: Library "utop" not found.
-> required by _build/default/.utop/utop.bc

This is what I have in my dune-project:

(utop :with-dev-setup)

If I remove with-dev-setup and rebuild, dune utop does work.

blurrcat avatar May 28 '25 04:05 blurrcat

FWIW, dune pkg also ignores :with-dev-setup.

Hi, in case this helps someone, I have seen also evidences of this with a recent version of nightly (downloaded yesterday).

I am using a workaround for now which consist of having a ${PROJECT}-dev.opam file in the project, where I list here the dependencies of the ${PROJECT}.opam that are specified as :with-dev-setup. The key to make that work is that in the -dev.opam version of the file, these dependencies are not qualified as :with-dev-setup. This seems to do the trick for now!

mbarbin avatar Jun 30 '25 11:06 mbarbin

I'm closing this in favor of https://github.com/ocaml/dune/issues/12135 , since it has more analysis of the proposed solution.

shonfeder avatar Oct 10 '25 01:10 shonfeder