Quantcast
Channel: OCaml - Topics tagged dune
Viewing all articles
Browse latest Browse all 521

How do dune libraries and library dependencies work?

$
0
0

It took me a while to learn this, but I now understand that “library” is an ocaml term, not just a dune term, and that dune turns a library stanza into a library file, also called an archive file, which according to the ocaml compiler man page ends with the extension .cmxa.

I’d like to understand a few things about library depndencies “below” the level of dune itself, i.e. without the abstraction dune provides letting libraries use external libraries. I can’t tell how much is dune and it’s just a thin dune layer on top of plain opam/ocaml/ocamlopt stuff.

  1. Is the name of the archive file relevant to ocaml code at all in terms of modules? i.e does the archive file itself implicitly define the top-level module that dune makes available? Or is the top-level module in the archive file? I imagine it’s the latter.

  2. When dune turns a library stanza into a top-level module in an opam package it builds, that top-level module is then available in a consuming dune project’s library or executable whose libraries clause specifies the consumed library’s public_name, which must begin with its opam package name. Is this public_name lookup specific to using modules from dune-built projects? Or could I specify a non-dune opam package’s module in public_name to use it in a dune project? If not, how does one use a non-dune package’s modules in a dune project?

  3. I imagine dune uses a dune-built opam package’s dune-package file to resolve what modules are available and how to make them available in compiled ocaml code. Is there a lower-level way to inspect what top-level modules are available in an installed opam package? ocamlobjinfo looks promising but it’s not clear to me how to interpret its output in terms of how to use a library file’s modules.

Thanks for any help.

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 521

Trending Articles