ocaml / dune

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

Opam-project depends syntax for package alternatives #5815

Open AllanBlanchard opened 2 years ago

AllanBlanchard commented 2 years ago

Desired Behavior

In Opam files, one can write something like:

depends: [
  ( "alt-ergo-free" | "alt-ergo" )
]

to say that either a package or another is needed. For example, here : any of alt-ergo or alt-ergo-free is OK (basically because they provide the same executable). However, it seems that while there is a syntax to say that we expect a version or another, we do not have the same for packages themselves.

Example

From a dune-project like:

(lang dune 3.0)
(name ex)
(generate_opam_files true)

(package
 (name ex)
 (depends (or alt-ergo alt-ergo-free)))

I'd like to get an opam file like:

# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
depends: [
  "dune" {>= "3.0"}
  ("alt-ergo" | "alt-ergo-free")
  "odoc" {with-doc}
]
build: [
  ...
]

Currently this is an error:

File "dune-project", line 7, characters 14-22:
7 |  (depends (or alt-ergo alt-ergo-free)))
                  ^^^^^^^^
Error: Unknown constructor alt-ergo
emillon commented 2 years ago

I don't think it's supported at the moment. In the dune abstraction, a package has a list of dependencies, and a dependency is a package name with an optional constraint. As a workaround for now it's possible to put the depends: field in a .opam.template file.

rgrinberg commented 1 year ago

cc @Leonidas-from-XIV and @gridbugs

if the 0install solver supports this, then we are free to add this feature.

Leonidas-from-XIV commented 1 year ago

According to my tests (test/blackbox-tests/test-cases/pkg/lockfile-generation.t/run.t) the 0install solver has no issues finding solutions to such requests.

rgrinberg commented 8 months ago

Re-assigning this to @gridbugs. He will try to find a more comprehensive and unified way of handling all possible constraints.