How to Build Optional Modules with Dune
- Added on 2026-06-08
- Page: https://www.liquidsoap.info/blog/2026-05-30-how-to-build-optional-modules-with-dune/
- See on Internet Archive
- #ocaml
Many dune-based projects have optional dependencies: a library that is only built when a particular system package is present, a set of executables that only make sense when an optional backend is available, etc.. In such situtions, how do you structure the build so that those components are silently skipped during normal development, while still failing loudly when someone explicitly tries to install a package that cannot be satisfied? Dune makes many things easy, but optional dependencies driving the availability of libraries and executables at build time have historically been one of its rougher edges. Dune 3.15 introduced support for %{read:file} inside (enabled_if ...) expressions on (library ...) stanzas, which finally made it possible to gate entire library stanzas on the result of a configure-time check. However, using this feature on libraries that belong to a named package triggered a spurious dependency cycle until dune 3.23, where PR #13833 fixed...