ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.64k stars 409 forks source link

dune dependency error with `dune pkg lock` #11096

Closed maiste closed 2 weeks ago

maiste commented 3 weeks ago

The #10918 introduced a bug or a regression in the way the dune pkg lock command work. I checked and the behavior wasn't present in the commit before.

Expected Behavior

When running a project with dune in the depends stanza of a dune-project file, it should build without any error. It was the previous behaviour before the mentioned PR.

Actual Behavior

The computation fails, and it prints the following stack trace:

Internal error, please report upstream including the contents of _build/log.
Description:
  ("can't find a valid solution for the dependencies", { name = "foo" })
Raised at Stdune__Code_error.raise in file
  "otherlibs/stdune/src/code_error.ml", line 10, characters 30-62
Called from Dune_pkg__Opam_solver.reject_unreachable_packages.(fun) in file
  "src/dune_pkg/opam_solver.ml", lines 830-832, characters 14-56
Called from Stdlib__Map.Make.merge in file "map.ml", line 406, characters
  44-63
Called from Stdlib__Map.Make.merge in file "map.ml", line 403, characters
  64-79
Called from Stdlib__Map.Make.merge in file "map.ml", line 403, characters
  25-40
Called from Stdlib__Map.Make.merge in file "map.ml", line 403, characters
  25-40
Called from Stdlib__Map.Make.merge in file "map.ml", line 403, characters
  64-79
Called from Dune_pkg__Opam_solver.reject_unreachable_packages.(fun) in file
  "src/dune_pkg/opam_solver.ml", lines 802-841, characters 6-32
Called from Dune_pkg__Opam_solver.solve_lock_dir.(fun) in file
  "src/dune_pkg/opam_solver.ml", line 949, characters 10-78
Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml",
  line 76, characters 8-11
Re-raised at Stdune__Exn.raise_with_backtrace in file
  "otherlibs/stdune/src/exn.ml", line 38, characters 27-56
Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml",
  line 76, characters 8-11

I must not crash.  Uncertainty is the mind-killer. Exceptions are the
little-death that brings total obliteration.  I will fully express my cases. 
Execution will pass over me and through me.  And when it has gone past, I
will unwind the stack along its path.  Where the cases are handled there will
be nothing.  Only I will remain.

Reproduction

You can find some logs in the binary distribution preview test: https://github.com/ocaml-dune/binary-distribution/actions/runs/11656938519/job/32453884724#step:7:49

Otherwise, to reproduce, you just need to run with an executable of dune build from main:

dune init proj foo 
cd foo
dune pkg lock

If you remove the dune dependency from the (depends ...) stanza of the dune-project file, it will work without error.