ocaml/dune

select stanza

Offen

#397 geöffnet am 09.01.2018

 (41 Kommentare) (12 Reaktionen) (0 zugewiesene Personen)OCaml (478 Forks)github user discovery
help wantedrule

Repository-Metriken

Stars
 (1.882 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 20h) (345 gemergte PRs in 30 T)

Beschreibung

It's common to have to choose between several files and/or dependencies depending on some external parameters, such as the version of the compiler, the OS, etc...

Currently one can select between several files and dependencies depending on the existence or non-existence of libraries using a (select ...) form in library dependencies:

(library
 ((name foo)
  (libraries (bar (select file.ml from
                   (unix  -> foo.unix.ml)
                   (!unix -> foo.no-unix.ml))))))

The current solution is:

  • limited: one can only dispatch using the fact that some libraries exist or not
  • not very nice: it feel weird to do file selection in the middle of a dependency list

The idea would be to introduce a select stanza to support all kind of selection between several files and dependencies.

I haven't though about the syntax in detail, but something like this could do:

(select
 ((files (file.ml))
  (choices
   ((<  ${ocaml_version} 4.05) (file.404.ml))
   ((>= ${ocaml_version} 4.05) (file.405.ml)))))

(select
 ((files (backend.ml))
  (choices
   ((= ${os} win32) (backend.win32.ml))
   (true            (backend.others.ml)))))

When we choose between several dependencies, the select stanza would be named and the name would be used as a library name:

(select
 ((files (x.ml))
  (public_name foo.backend)
  (choices
   ((lib-dep unix) (x.unix.ml))
   (true           (x.no-unix.ml)))))

(library
 ((name foo)
  (libraries (bar foo.backend))))

Contributor Guide