dune icon indicating copy to clipboard operation
dune copied to clipboard

Solver error when one local package depends on another local package with version constraints

Open gridbugs opened this issue 1 year ago • 1 comments

Consider this example from https://github.com/shonfeder/alg_structs:

(version 0.1.3)

(package
 (name alg_structs)
 (depends
  (dune (>= 1.11.3))
  (ocaml (>= 4.08.0))
  (ppx_deriving (>= 4.4))
))

(package
 (name alg_structs_qcheck)
 (depends
  (dune (>= 1.11.3))

  (ocaml (>= 4.08.0))
  (alg_structs (and (>= 0.1.3) (< 0.2.0)))
  (qcheck (>= 0.11))

  (alcotest (and :with-test (>= 0.8.5)))
  (qcheck-alcotest (and :with-test (>= 0.11)))
))

The second package alg_structs_qcheck depends on the first package with version constraints (alg_structs (and (>= 0.1.3) (< 0.2.0))). Solving this project with dune gives the error:

 $ dune pkg lock
Error: Unable to solve dependencies for the following lock directories:
Lock directory dune.lock:
Can't find all required versions.
Selected: alg_structs.dev base-threads.base base-unix.base cppo.1.6.9
          ocaml.5.3.0 ocaml-config.3 ocamlfind.1.9.6+dune ppx_derivers.1.2.1
          ppx_deriving.6.0.2 alg_structs&alg_structs_qcheck ocaml
          ocaml-base-compiler ocaml-base-compiler
- alg_structs_qcheck -> (problem)
    Rejected candidates:
      alg_structs_qcheck.dev: Requires alg_structs >= 0.1.3 & < 0.2.0
- dune -> dune.3.16.0
    User requested = 3.17
- ocaml-base-compiler -> (problem)
    Rejected candidates:
      ocaml-base-compiler.5.2.0: Requires ocaml = 5.2.0
      ocaml-base-compiler.5.1.1: Requires ocaml = 5.1.1
      ocaml-base-compiler.5.1.0: Requires ocaml = 5.1.0
      ocaml-base-compiler.5.0.0: Requires ocaml = 5.0.0
      ocaml-base-compiler.4.14.2: Requires ocaml = 4.14.2
      ...
- ppxlib -> (problem)
    ppx_deriving 6.0.2 requires >= 0.32.0
    Rejected candidates:
      ppxlib.0.33.0: Requires ocaml >= 4.04.1 & < 5.3.0
      ppxlib.0.32.1: Requires ocaml >= 4.04.1 & < 5.3.0
      ppxlib.0.32.0: Requires ocaml >= 4.04.1 & < 5.2.0 & <> 5.1.0~alpha1
      ppxlib.0.31.0: Incompatible with restriction: >= 0.32.0
      ppxlib.0.30.0: Incompatible with restriction: >= 0.32.0
      ...

The problem is that dune treats the version number of local packages as dev, and alg_structs.dev doesn't satisfy the version constraint (alg_structs (and (>= 0.1.3) (< 0.2.0))).

The alg_structs project happens to have a top-level (version 0.1.3) field, so it might be reasonable for dune to treat local packages as being version 0.1.3 rather than version dev which would solve this problem.

Alternatively we could treat this as an error with the project, and require that local packages that depend on other local packages avoid version constraints with explicit version numbers. Should this be the behaviour for projects with no top-level version field?

gridbugs avatar Aug 20 '24 06:08 gridbugs

Alternatively we could treat this as an error with the project, and require that local packages that depend on other local packages avoid version constraints with explicit version numbers. Should this be the behaviour for projects with no top-level version field?

I don't think this option is going to work. There's a lot of legitimate reasons to have constraints on packages in the same workspace.

The most obvious solution is just to drop the version constraints on local packages. I don't really see how the solver could make use of them for anything useful.

rgrinberg avatar Aug 20 '24 08:08 rgrinberg

I think this is now solved by #11517?

Leonidas-from-XIV avatar Mar 20 '25 10:03 Leonidas-from-XIV