Echoing what @sim642 mentioned, you can use copy_files or copy actions, or in the worst case, just shell out to bash (assuming you donβt care much about supporting non-unix environments (who uses them anyway? )). For example, Iβm not sure if this was the most elegant way, but I was able to use dune to setup a website generator that performed some fairly complex re-arrangment of the source directory using the following build rules:
The copy_files and copy_files# stanzas specify that files from another directory could be copied to the current directory, if needed.
This would imply that I would need a output/dune file in source root, in which I would put the copy_files stanza. This would start shaping the source structure to accommodate the output structure.
I tried various iterations of copy stanza too, but as far as I remember, dune didnβt allow any of those for some or the other reason. One reason was that the source and dest files have the same name, other was related to not being able to copy into child dir, because the path of target and deps have to be the same. Sorry if none of my explanations make sense. duneβs didnβt either.
As an aside, what I did realize from all of this though, is that dune first copies the source files (and files marked as deps in the build alias) from source dir into the build context root, and then start building. This explains why it canβt overwrite files of the same name. I would appreciate if someone validates or corrects this assumption.
I donβt mind using the Unix tools as long as reaching out for bash and run actions in dune is the only blessed way for my problem (i.e., as long as I am not missing any other approach).
If so, then I will mark Gopiβs answer as a solution.
I do wish I didnβt have to specify (alias) in every substanza of subdir.
I still couldnβt make (rule ... (action (copy))) work here. I think I tripped up at (target output/icons) stanza, which probably does not create a nested dir automatically.