OCaml and dune : Integrate small libraries in a larger library

339 views Asked by At

I am developing a big library with dune. Let us call this library L.

To avoid creating a big mess, the dune project has many smaller libraries : A, B, C, ... These libraries depend on each other.

I would like the users to be able to opam install L, and then access to the different smaller libraries as L.A, L.B, etc.

What is the proper way to do this?

Edit following the comment of @glennsl:

Here is the filesystem tree:

l/
l/dune-project
l/a            <- This directory contains library A
l/a/dune
l/b            <- This directory contains library B
l/b/dune

in l/a/dune :

(library
 (name a)
 (public_name l.a))

in l/b/dune :

(library
 (name b)
 (public_name l.b)
 (libraries a)) 

in l/a/dune-project :

(name l)

I can't find how to expose A and B as modules of L.

1

There are 1 answers

2
glennsl On BEST ANSWER

Unless there's some configuration setting that interferes, this should just be a matter of exporting the modules of the other libraries as module aliases:

(* L.ml (and L.mli) *)

module A = A
module B = B
module C = C

(* ... *)

This is in fact what dune does automatically to namespace library modules. And if you don't already have an explicit main module for L, you will have to manually add the module aliases that would have been automatically generated as well.