Selectively preprocessing files by extension

I’m currently working on a project using both *.eliom and *.ml files, where the *.eliom files can be treated exactly as normal OCaml files, except that they need to have the Eliom PPX run on them. How would I express this in Dune?

In the preprocess specification. you can list how you want a particular module to be preprocessed.

  • There’s no way to set the preprocessor per filename
  • There’s no way to set the preprocessor globally by extension

Both are annoying limitations that we hope to address one day.

Finally, I don’t believe that building .eliom files is as simple as running a ppx. AFAIK it requires some build system orchestration that is done via special makefiles or an ocamlbuild plugin. Dune has not equivalent. (cc @Drup to confirm).

However, if you have such an interest to add eliom support to dune, then we’d gladly show you how to make it work on the dune side. You will need to understand how building eliom works however.

Eliom is indeed a bit more than a simple ppx. Each *.eliom compiles to two sets of *.cm* files, one for the server, one for the client. The chalenging part being the associated dependency resolution.

If you are really motivated to work on this, I can give more detailed pointers, but it’s not a trivial task.

The thing I’m currently working on is actually building eliom itself with dune, and Eliom uses its own OCamlbuild plugin and PPX’s in the process of building the library.

So this would necessitate adding new functionality to Dune itself?

eliom is 2 things:

  • A language extension. This is written in normal OCaml
  • A “framework”/library. This is written in the eliom dialect, and thus need appropriate build tool.

I’m a bit confused since, looking at the library source, there are a lot of files not written in the Eliom dialect:

Unless I’m mistaken, the Eliom framework is composed of Eliom-dialect modules as well as normal OCaml.

Not everything is written in the exact eliom dialect, but the whole framework uses eliom-style architecture, with and files, which must not be mixed, but both should be accessible inside eliom files (in server and client sections, respectively). You also have some “normal” ocaml files, which should be available in both.

And there’s no clean way to represent such an architecture in pure Dune at this moment?

Well, that’s precisely the part that need modifications in dune. :slight_smile: