File: packages.rst

package info (click to toggle)
ocaml-dune 3.20.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,564 kB
  • sloc: ml: 175,178; asm: 28,570; ansic: 5,251; sh: 1,096; lisp: 625; makefile: 148; python: 125; cpp: 48; javascript: 10
file content (57 lines) | stat: -rw-r--r-- 2,329 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Packages
========

:term:`Packages <package>` are the units that are made installable. Executables
and libraries that have a ``(public_name)`` are installable, and need to be
attached to a package.

How Dune Knows About Packages
-----------------------------

Packages can be defined in two ways:

- If a ``pkg.opam`` file is found, it signals the existence of the ``pkg``
  package to Dune. The contents of the opam file are not interpreted by Dune.
- In ``dune-project``, a ``(package)`` stanza with ``(name pkg)`` defines the
  ``pkg`` package.

.. note::

   If you want to define public elements but are not interested in publishing
   to opam, it is not necessary to write empty ``*.opam`` files. Instead,
   prefer declaring it in ``dune-project`` as a ``(package)`` with just a
   ``(name)``.

Generating Opam Files
---------------------

In the latter case, if ``(generate_opam_files)`` is present in
``(dune-project)``, Dune will generate ``pkg.opam`` using the metadata in found in ``(package)`` stanzas and global fields such as ``(source)``.

.. seealso:: :doc:`../howto/opam-file-generation`

If a ``pkg.opam.template`` file is found, the fields found in this opam file
are added to the generated file, overriding the generated ones in case of
collision. This can be used as an escape hatch to add arbitrary opam fields.

What Dune Installs
------------------

Dune will install the following files:

- ``(library)`` stanzas which have a ``(public_name)``. The package name is the
  first component of the dot-separated public name: ``(public_name pkg)`` and
  ``(public_name pkg.sub)`` will look for a package named ``pkg`` to install
  their contents.
- ``(executable)`` and ``(test)`` stanzas with a ``(public_name)``. The package
  to install the files in is determined by the ``(package)`` field, which can
  be omitted if there is only one package.
- ``(install)`` stanzas provide a low-level mechanism to install arbitrary
  files.
- Following the conventions of `odig`_, files named ``README*``, ``CHANGE*``,
  ``HISTORY*`` and ``LICENSE*`` are installed in the packages defined by opam
  files in the same directory. These files can be generated by user rules, So
  for instance, a changelog generated by a user rule will be automatically
  installed as well.

.. _odig: https://erratique.ch/software/odig