ocaml / ocaml/dune

select stanza

Open
#397 41 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted rule
Dominant language
OCaml
Stars
1.9k
Forks
500
Avg merge
15h 21m
Merged PRs (30d)
277

Description

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing (select ...) form in library dependencies and the implementation of library and dependency stanzas. The issue proposes a new stanza for choosing files or dependencies from compiler, OS, or library conditions, but leaves the syntax and behavior open. Done requires an agreed design and support for the described selection cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.