ocaml/dune

select stanza

オープン

#397 opened on 2018/01/09

 (41 件のコメント) (12 件のリアクション) (0 人の担当者)OCaml (478 件のフォーク)github user discovery
help wantedrule

Repository metrics

Stars
 (1,882 個のスター)
PR merge metrics
 (平均マージ 1d 20h) (30d で 345 merged PRs)

説明

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))))

コントリビューターガイド