Make a binary depend on non-code files in Dune

I have an OCaml binary that I’m building and installing through Dune. The binary depends on non-code files that are also being generated and installed by dune. Currently I’m using the sites mechanism for this, but I’m also open to other options.

The problem now is that when I run dune exec my-binary, the dependencies of the binary are not propagated to the _build/install folder, and can therefore not be found by the sites mechanism. I’m aware of this (hacky) solution, but I cannot get it to work in my situation because my dependencies are within the same project as the binary.

This is how far I came:

(install
 (files dependency.txt) ; the non-code dependency of my binary
 (section (site (my-package data)))
 (package my-package)
)
(executable
 (names my_binary)
 (modules ("my_binary"))
)
(install
 (section bin)
 (package my-package)
 (files (my-binary-copy.exe as my-binary)))
(rule
  (target my-binary-copy.exe)
; Here I want to express a dependency on the installation file of dependency.txt.
; Instead I get a dependency on the source file
  (deps dependency.txt) 
  (action (copy my-binary.exe my-binary-copy.exe)))

I experimented with using something like (deps %{lib:my-package:dependency.txt}), but that also does not work, because dependency.txt does not seem to be part of a library.

Any solutions are welcome!

2 Likes

I’m no expert or even an enthusiast, but it came to mind that you might be able to find something useful in the Hacklang dune files.

Here’s one: hhvm/dune at 241af124dea209c62c08bd34fad26fe02dc59ff6 · facebook/hhvm · GitHub

They don’t deal with packages, but you can see they’re using some hacks to locate the files they’re interested in.

Thanks @2BitSalute, I’ll take a look if I can adapt this. Still, a more principled solution would be nice. This looks like a horrible hack to me.