Example of how to use depopts with dune


I’m trying to learn how to use the depopts stanza in dune. I haven’t been able to find any examples of that.

One such example I did find was for the logs package. I don’t know if dune offers a similar way of doing it.

Thanks :slight_smile:

1 Like

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

Basically the library stanzas in the dune files accept (optional). As stated in the docs: https://dune.readthedocs.io/en/stable/dune-files.html#dune

(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

I don’t think that is really possible in current OPAM. In fact, OPAM is been moving mostly away from optional dependencies, instead moving towards split packages which then state the dependencies. This simplifies the dependency situation since a consumer can then depend on x_lwt instead of depending on x and lwt and hoping the versions will match up and it will build x_lwt.

Ah that’s really good info.

Yeah this does make a lot of sense :smile:


1 Like