It is planned that at some point dune will natively support library variants. However, at this point they are not yet supported.
This repository provides a simple workaround to allow porting code relying on library variants to Dune. The repository is organized as follow:
foo/
contains a libraryfoo
defining a moduleFoo
without implementationfoo.impl/
contains a libraryfoo.impl
that provides an implementation forFoo
bar/
contains a librarybar
depending only onfoo
test/
contains an executable depending onfoo
andbar
andfoo.impl
This is a typical example of usage of library variants. To make this work it is important to follow these rules:
foo/jbuild
must declare that modulefoo
has no implementation using a field(modules_without_implementation (foo))
- both
foo/jbuild
andfoo.impl/jbuild
must have(wrapped false)
to ensure the name of the object files match betweenfoo
andfoo.impl
- both
foo/jbuild
andfoo.impl/jbuild
must have(flags (:standard -no-keep-locs))
to make sure the cmi files are not sensible to the filename foo.impl/foo.mli
must be a copy offoo/foo.mli
to make sure the cmi files match. This should be ensured via a copy rule