Package version: source vs. binary

Building a Deb/RPM package is happening in a buildroot which is different from the final destination in the file system. I haven’ tried recently but does this work for opam/dune? Right now I’m hacking around the problem but it is not satisfying.