I’m using ocaml-protoc
, and set up a dune rule that works fine, except it reliably fails the first clean build (subsequent builds are OK). Error is Could not find the .cmi file for interface primitives/src/proto.mli
; the rule is:
(rule
(target proto.ml)
(action
(run bash -c "ocaml-protoc --binary --ml_out ./ %{dep:./proto.proto}")))
Thoughts?
I am not very confident, but a reason might be that the file proto.mli
is generated by the action as well, without dune being aware explicitly about it (via the targets defined in the rule).
I’ve had success with a similar use case, by including the mli as well in the targets, such as here.
I would recommend you to try that to see if this improves things. Good luck!
1 Like
I think you need both ml/mli files listed as targets. This is what I have in one of my projects:
(rule
(targets profile.ml profile.mli)
(deps
(:proto profile.proto))
(action
(run ocaml-protoc %{proto} --binary --ml_out .)))
@mbarbin, @lambda_foo, you got it. Thank you!
It’s odd though, as I’ve used this kind of pattern for hooking in file-generation tools of all sorts (ocaml-crunch, and a handful of custom code-generation programs), but have never needed to list an .mli
as a target once… 
1 Like