[ANN] dkml-dune-dsl 0.x.x - Parameterizable Dune files embedded in OCaml

I am pleased to announce dkml-dune-dsl, an embedding of Dune inside OCaml (aka. an eDSL) for developers that need to simplify complex Dune logic. An excerpt from the README:

Once installed you will be able to write DSL expressions like:

open DkmlDuneDsl

module Build (I : Dune.SYM) = struct
  open I

  let res =
    [
      rule
        [
          target "{{{ name }}}.txt";
          action
            (with_stdout_to "%{target}"
              (echo [ "{{{ age }}}" ]));
        ];
    ]
end

that are run over the parameters in a JSON file:

{
  "param-sets": [
    {"name": "batman", "age": 39},
    {"name": "robin", "age": 24}
  ]
}

You can do also do aggregation or, if you are really adventurous, define your own interpreter. Even if you don’t use parameterization you get things you take for granted with OCaml: type-safety, auto-complete and let constants.

The full documentation including installation instructions and examples are available in the README.

A few cautionary notes:

  • The current version (0.1.0 as of Oct 17 2022) does not have 100% coverage of all Dune expressions; it just has the parts of Dune I’ve needed in my own projects. That includes an encoding of the Ordered Set Language and virtual libraries but not (for example) select forms, plugins, ctypes and lex/yacc. But I strongly suspect the same people who need a tool like dkml-dune-dsl are the same people who can easily contribute a PR to add any parts of Dune they need.
  • The API is unstable; if someone adds more Dune expressions they may have to tweak the API. And I haven’t settled on whether the API needs some first-class features to track Dune’s (lang dune X.Y.Z) versioning.
  • This is not blessed in any way by the Dune team! Hopefully they don’t mind though.

Thanks, Jonah

5 Likes