Example of how to use depopts with dune

I think I answered my own question. I uploaded a dumb example here: GitHub - carlosdagos/dune-optional-libs-example

Basically the library stanzas in the dune files accept (optional). As stated in the docs: Stanza Reference — Dune documentation

(optional) , if present it indicates that the library should only be built and installed if all the dependencies are available, either in the workspace or in the installed world. You can use this to provide extra features without adding hard dependencies to your project

In the dumb example I linked above, I got the desired result by installing or removing lwt and doing the same with async.

One thing I’m still not getting is getting the library reinstalled automatically once the depopts I’ve listed in the opam files become available. I don’t know if that’s due to the local opam pin or what.

1 Like