Using the dune `install` stanza to install generated files

I have a somewhat complex build setup. The file layout is like this:

└── bin/
    ├── theme/
    │   └── js-source/
    │       └── main.js
    ├── main.ml
    └── dune

I need to use esbuild to generate theme/main.js and to then use the install stanza to copy the entire theme directory to the installation site. Presently the problem is that the output of the rule that runs esbuild places the file in the _build directory, but the install stanza copies the theme directory directly from the source tree.

I have two possible solutions in mind, but have not been able to implement them:

  • Make sure that the output of the build step gets placed into the source tree directly
  • In the install stanza, specify that it should copy the theme directory from the _build directory.
(generate_sites_module
 (module theme_site)
 (sites forester))

(install
 (section
  (site
   (forester theme)))
 (files
  (glob_files_rec theme/*)))

(subdir
 theme
 (rule
  (target ./main.js)
  (deps
    js-source/main.js
    (source_tree node_modules))
  (action
   (progn
    (run
     esbuild
     --minify
     --bundle
     js-source/index.js
     --outfile=%{target})))))

Do you get the desired behavior if you use (dirs theme) instead?

If I use (dirs theme), it says No rule found for bin/theme.

Not sure if I missed something when I made the original post, but it seems to be working fine with using glob_files_rec.