1

Background

I'm trying to expose two dune libraries from the same directory - one for some interfaces, and the other for their implementations.

For example, let's say I have the following sources:

foo_api.ml
module type Foo = sig
  val foo: string
end
foo.ml
module FooImpl: Foo =
  let foo = "foo"
end

In my dune file, I want to expose these as separate libraries - an API and an implementation. I'd really like to be able to use globs here to specify the modules, as I'm planning on using this pattern for other modules, eg. Bar.ml and Bar_api.ml.

Question

Does dune support some way of globbing (or regex'ing) for modules?

(library
 (name foo_lib_api)
 (modules (glob_files "./*_api.ml")))

(library
 (name foo_lib_implementation)
 (modules (:standard \ (glob_files "./*_api.ml"))))

The above syntax does not work, and I haven't found anything that does work. Perhaps I'm trying to use dune like I would use bazel, which would let me use glob or filegroup.

Trent Small
  • 1,213
  • 8
  • 12

1 Answers1

1

Dune does not support glob patterns in the modules stanza.

A more idiomatic alternative would be to have one directory, which has the advantages of allowing to decouple the module and library names.

octachron
  • 17,178
  • 2
  • 16
  • 23
  • Interesting - I suppose that would mean creating a `foo/` directory, with `foo/api/dune` for the API, and `foo/dune` or `foo/implementation/dune` for the implementation. Yes, I suppose that 's one way to do it, and it's fairly clean. Good idea! – Trent Small Sep 09 '22 at 14:04