Post-processing an executable with dune

Is there any way to post-process an executable with dune?

My main goal is to patch a Windows PE executable with mt.exe after it’s compiled, but I can’t seem to find the best way to do it with pure dune file rules.

I.e. if I have an executable declaration and a rule with the target being the name of the executable, I get an error saying there are multiple rules generated for the same target:

(executable
 (name Foo)
 ...)

(rule
 (target Foo.exe)
 ...)

This makes sense because it’s essentially generating cyclic dependencies, but I’m not sure the best way to go about achieving my goal.

Thanks in advance!

Have you tried declaring Foo.exe to be a dependency, instead of a rule target?

EDIT:

psuedo code

(rule
  (target Foo.patched.exe)
  (deps Foo.exe)
  (action (run PatchFoo.exe -i ${deps} -o ${target})))