ocaml/dune

select stanza

開放

#397 建立於 2018年1月9日

 (41 則留言) (12 個反應) (0 位負責人)OCaml (478 個分叉)github user discovery
help wantedrule

倉庫指標

星標
 (1,882 顆星)
PR 合併指標
 (平均合併 1天 20小時) (30 天內合併 345 個 PR)

描述

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

貢獻者指南