2

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.

Anthony Scemama
  • 1,563
  • 12
  • 19

1 Answers1

2

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.

glennsl
  • 28,186
  • 12
  • 57
  • 75
  • It works! I was looking in the stanzas... Did not see this obvious solution. Thanks! – Anthony Scemama Oct 09 '20 at 12:00
  • 1
    Unless you're aware that `dune` works like this it's definitely not obvious, no. There are a few hints in the documentation though, mainly in the introductory description of the [`library`](https://dune.readthedocs.io/en/stable/dune-files.html#library) stanza and its `wrapped` field. – glennsl Oct 09 '20 at 12:11