Installing many files with dune

Hello,

The library that I am developing needs a certain number of additional files (config, images, fonts, etc.) that seem to fit well in the share directory. I would like to have dune install them automatically.

Basically, I want to do (taken from https://dune.readthedocs.io/en/stable/installation.html):

(install
 (files hello.txt)
 (section share)
 (package mypackage))

but replacing hello.txt by a (large) number of files. What’s the best way to do this?
I would be happy, for instance, if I could just indicate the name of the directory in order to select all its files.

Hello @sanette !

I have similar needs and for now I’ve been using a script to generate the dune file, but indeed it is far from ideal. I don’t recall the exact situation w.r.t. globs , but for directories you can check the status at https://github.com/ocaml/dune/issues/1868 , https://github.com/ocaml/dune/issues/1377 , and https://github.com/ocaml/dune/issues/256

Maybe with a glob https://dune.readthedocs.io/en/latest/dune-files.html#glob
something like (files mydir/*)
I don’t know if install supports globs though

Gaëtan Gilbert

Hi @SkySkimmer, it doesn’t seem to work.

$ dune build
File "lib/dune", line 9, characters 8-15:
9 |  (files share/*))
            ^^^^^^^
Error: No rule found for lib/share/*

Hi @ejgallego, thanks for the links. So obviously we are several of us with the same problem. I think that, at least until things evolve, I will also generate the dune file with a script.

Shouldn’t it be

(files (glob mydir/*))

Glob section for references

Hi @vrotaru, doesn’t seem to work either (at least with me)

File "lib/dune", line 9, characters 8-22:
9 |  (files (glob share/*)))
            ^^^^^^^^^^^^^^
Error: invalid format, <name> or (<name> as <install-as>) expected
Hint: dune files require fewer parentheses than jbuild files.
If you just converted this file from a jbuild file, try removing these parentheses.

My bad. I used glob in a similar context so I thought it may work here. It doesn’t.

I am positive a solution will arrive soon!