ocaml / dune

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

`dune-project` stanza for `opam depext` #5506

Open Niols opened 2 years ago

Niols commented 2 years ago

Desired Behaviour

Since OPAM 2.1, the depext plugin handling external dependencies is included in OPAM directly, so one can do eg. opam install . --depext-only. The syntax in .opam files is unchanged, eg.:

depexts: [
  [ "timidity++" "freepats-general-midi" "inkscape" "lilypond" "sassc" ]
    { os-distribution = "archlinux" }
  [ "timidity" "freepats" "inkscape" "lilypond" "sassc" ]
    { os-distribution = "debian" }
]

For now, if I am not mistaken, the way to provide this field when generating OPAM files is through a .opam.template. My question (or feature request) is the following:

Are there any plans to introduce a stanza for dune-project that would allow declaring those external dependencies directly in there and generate the appropriate field in .opam?

Example of Current Behaviour

For now, I have a dune-project file containing most of the metadata:

$ cat dune-project
(lang dune 2.5)
(generate_opam_files)
...
(package
 (name example)
 ...
 (depends
  (cohttp-lwt-jsoo     (>= 4.0.0))
  (cohttp-lwt-unix     (>= 4.0.0))
  (dune                 :build)
   js_of_ocaml
   js_of_ocaml-lwt
  (js_of_ocaml-ppx      :build)
  (lwt_ppx              :build)
  (ocaml               (and :build (>= 4.08.0)))
  (yojson              (>= 1.6.0))))

And a .opam.template file containing the external dependencies:

$ cat example.opam.template
depexts: [
  [ "timidity++" "freepats-general-midi" "inkscape" "lilypond" "sassc" ]
    { os-distribution = "archlinux" }
  [ "timidity" "freepats" "inkscape" "lilypond" "sassc" ]
    { os-distribution = "debian" }
]

Both together allow the generation of the expected .opam file:

$ dune build
$ cat example.opam
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
...
depends: [
  "cohttp-lwt-jsoo" {>= "4.0.0"}
  "cohttp-lwt-unix" {>= "4.0.0"}
  "dune" {build}
  "js_of_ocaml"
  "js_of_ocaml-lwt"
  "js_of_ocaml-ppx" {build}
  "lwt_ppx" {build}
  "ocaml" {build & >= "4.08.0"}
  "yojson" {>= "1.6.0"}
]
...
depexts: [
  [ "timidity++" "freepats-general-midi" "inkscape" "lilypond" "sassc" ]
    { os-distribution = "archlinux" }
  [ "timidity" "freepats" "inkscape" "lilypond" "sassc" ]
    { os-distribution = "debian" }
]

Example of Expected Behaviour

I would like to have a dune-project file containing all the metadata:

$ cat dune-project
(lang dune 2.5)
(generate_opam_files)
...
(package
 (name example)
 ...
 (depends
  (cohttp-lwt-jsoo     (>= 4.0.0))
  (cohttp-lwt-unix     (>= 4.0.0))
  (dune                 :build)
   js_of_ocaml
   js_of_ocaml-lwt
  (js_of_ocaml-ppx      :build)
  (lwt_ppx              :build)
  (ocaml               (and :build (>= 4.08.0)))
  (yojson              (>= 1.6.0)))
 (depexts
  ((timidity++
    freepats-general-midi
    inkscape
    lilypond
    sassc)
   (= os-distribution archlinux))
  ((timidity
    freepats
    inkscape
    lilypond
    sassc)
   (= os-distribution debian)))

No .opam.template file:

$ cat example.opam.template
cat: example.opam.template: No such file or directory

And the same generated .opam as before:

$ dune build
$ cat example.opam
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
...
depends: [
  "cohttp-lwt-jsoo" {>= "4.0.0"}
  "cohttp-lwt-unix" {>= "4.0.0"}
  "dune" {build}
  "js_of_ocaml"
  "js_of_ocaml-lwt"
  "js_of_ocaml-ppx" {build}
  "lwt_ppx" {build}
  "ocaml" {build & >= "4.08.0"}
  "yojson" {>= "1.6.0"}
]
...
depexts: [
  [ "timidity++" "freepats-general-midi" "inkscape" "lilypond" "sassc" ]
    { os-distribution = "archlinux" }
  [ "timidity" "freepats" "inkscape" "lilypond" "sassc" ]
    { os-distribution = "debian" }
]
craff commented 1 year ago

Yes, this is needed, or there is another solution?