What you are looking for is called “preprocessing with an action”. Your action will be passed the file name of the input file and it is supposed to output the preprocessed file on standard output.
This is not an exact answer to your question but you can tell dune to only compile the libraries/executables in directory foo by doing dune build @@foo/all or dune build @@foo/check (the @check target only compiles and does not link, so it is faster). The double at-sign means that dune does not look recursively for things to build. If you prefer a recursive build you can use a single @.
I am also looking how to tell dune: hey, this library depends on this executable, because this is the preprocessor for it…
I tried to find in dune’s documentation, but it is quite obscure for me.
if name and public_name are equal, you can just put (public_name)
if there’s just one buildable thing in the directory, you don’t have to specify (modules). So you can make a prefilter subdirectory with a dune file and prefilter.ml and use the following dune files: