dune icon indicating copy to clipboard operation
dune copied to clipboard

Allow to generating subdir with dynamic_include

Open rlepigre opened this issue 1 year ago • 4 comments
trafficstars

Desired Behavior

Currently, dynamic_include cannot deal with files using subdir. How hard would it be to support it?

Example

The example I have in mind is simple, and involves generating rules that produce Coq files containing the representation of the AST of all the source files of a source tree. So, for each file of the source tree, say dir1/dir2/bla.cpp, I want to produce dir1/dir2/bla.v (and potentially other files as well based on the base name).

Producing these rules is kind of complicated. In our current setup, we use a script that produces a dune.inc file (produced by a wrapper Makefile), that is then included (via include, not dynamic_include). The produced dune.inc relies heavily on subdir (for simplicity, and to not have to recursively include files). Ideally, I'd like to let dune run the script producing dune.inc, and the rely on dynamic_include, to avoid the two-stage build with the Makefile.

rlepigre avatar Apr 08 '24 08:04 rlepigre

Hi, Have you tried the second approach in the howto guide? It explains how to encode this kind of "rule scheme". You'll have to change the directory structure a bit but it might work for you.

emillon avatar Apr 17 '24 08:04 emillon

I did manage to make things work with a flat directory structure based on something like the guide. However, I do want to preserve a directory structure in the generated files, since the ultimate goal is to build generated files with coq using (include_subdirs qualified). Also, we are working on a directory structure with hundreds of files, so we really can't just have a single directory. The easiest way to make things work as I intend really seems to rely on generating rules wrapped by some subdir stanzas reflecting the source tree.

Would that help if I provided an example of what we'd like to do?

rlepigre avatar Apr 17 '24 16:04 rlepigre

Unfortunately, unless you copy the sources to other directory, there is indeed a cycle problem in the way dune load rules I think, that is to say, if you have:

tests/
tests/t1/...
tests/t2/...

etc... and you want to generate an include file for the tests, you'll need to add (source_tree tests) to the deps of your program, however that would lead to a cycle with the current loading rule I think.

ejgallego avatar Apr 17 '24 16:04 ejgallego

In my experiment I do copy the sources to another directory, what I mean with a flat directory structure is that the source folder for which I want to generate rules itself has sub-folders. And ideally, I could handle all these subfolders with a single generated dune file that relies on (subdir ...).

rlepigre avatar Apr 17 '24 19:04 rlepigre