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

贡献者指南