Opam: Incorrect package conflict for cohttp?

I wanted to check out the latest cohttp.

In order to build everything in cohttp, I wanted to install all the dependencies. So I tried something like this:

$ mkdir cohttp
$ cd cohttp
$ opam switch create . 5.0.0 -y
$ git clone git clone https://github.com/mirage/ocaml-cohttp.git
$ cd ocaml-cohttp
$ opam install . --deps-only --with-test

But I get this error message:

[ERROR] Package conflict!
  * Missing dependency:
    - http < 6.0.0~alpha0
    no matching version

No solution found, exiting

Question: Why does this fail?

This is perplexing because the http package comes with the ocaml-cohttp git repository. The . should take all *.opam

Interestingly, by simply omitting cohttp-bench.opam and explictly listing everything else and asking for --deps --with-test the following succeeds:

opam install ./cohttp.opam ./http.opam ./cohttp-top.opam ./cohttp-lwt-unix.opam ./cohttp-lwt-jsoo.opam ./cohttp-lwt.opam ./cohttp-mirage.opam ./cohttp-server-lwt-unix.opam ./cohttp-eio.opam ./cohttp-curl.opam ./cohttp-curl-async.opam ./cohttp-curl-lwt.opam ./cohttp-async.opam --deps-only --with-test

Each package has a "http" {= version} requirement.

BTW cohttp-bench is not a package on the opam repository. Does this have something to do with it?

Indeed, cohttp-bench is meant for CI to install additional packages required to run benchmarks… and as such, it isn’t published on the opam repository (and never should be).

The issue is that opam install . attempts to guess the version of each package from the latest known published version. But since cohttp-bench isn’t published, opam falls back to a ~dev version (where the tilde ~ at the beginning makes it smaller than any real version)… and so the constraints {= version} between packages are now unsolvable :confused:

One solution is to not install cohttp-bench as you did! The other is to force the version of all packages before installing:

$ opam pin . --no-action --with-version=6.0.0~dev
$ opam install . --deps-only --with-test

… where the chosen 6.0.0~dev version could be anything, I generally use --with-version=dev to avoid thinking about it.

(I don’t like that opam guesses local package versions from an external source, you get different results depending on when you last ran opam update)

1 Like