How to do a "release build" with dune or ocamlopt

Hello!

Please see this terminal session demonstrating a simple project setup:

demo


I adapted my dune file according to the dune documentation here.

I don’t see any difference in the final output executable. Mainly, debug_info still remains + the output size does not change when applying the release profile, which looks wrong.

Essentially, I understand that dune delegates to ocamlopt, but it’s unclear to me what the best practices are related to building a binary for production usage.

I did manage to remove the debug info + reduce the overall size by applying strip manually, like such:

$ ocamlopt -O3 ./main.ml -o main && strip ./main && file ./main && du -sh ./main
./main: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=1d8adb88a132aace87d4f6ca0091e4f198c4ac60, for GNU/Linux 3.2.0, stripped
356K    ./main

Is this advisable? How do you build your binaries for production? Can I make it a one-step process via dune?

By default, the only real difference between dev and release profiles is that the former disables cross-module inlining (-opaque), which makes compilation faster (and decreases code size somewhat). It is often desirable to have debug information in release binaries (helps debugging), so Dune includes debug information even in the release profile.

Cheers,
Nicolas

2 Likes

Got it, I assumed too much. Thanks!