Skip to content

Commit 35daa84

Browse files
committed
Document multiple public libraries
1 parent 131d672 commit 35daa84

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

doc/buildinfo-fields-reference.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,17 @@ virtual-modules
510510
\mathrm{commalist}\left({\left(\mathop{\mathit{upper}}{\left\{ \mathop{\mathit{alpha\text{-}num}}\mid[\mathop{\mathord{``}\mathtt{\text{'}}\mathord{"}}\mathop{\mathord{``}\mathtt{\text{_}}\mathord{"}}] \right\}}^\ast_{}\right)}^+_{\mathop{\mathord{``}\mathtt{\text{.}}\mathord{"}}}\right)
511511
512512
513+
Library fields
514+
--------------
515+
516+
visibility
517+
* Optional field
518+
* Documentation of :pkg-field:`library:visibility`
519+
520+
.. math::
521+
\left\{ \mathop{\mathord{``}\mathtt{public}\mathord{"}}\mid\mathop{\mathord{``}\mathtt{private}\mathord{"}} \right\}
522+
523+
513524
Package description fields
514525
--------------------------
515526

doc/cabal-package.rst

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -849,11 +849,17 @@ The library section should contain the following fields:
849849

850850
:since: 3.0
851851

852-
:default: ``private`` for internal libraries. Cannot be set for public library.
852+
:default: ``private`` for internal libraries. Cannot be set for main
853+
(unnamed) library, which is always public.
853854

854-
Cabal recognizes ``public`` and ``private`` here...
855+
Can be ``public`` or ``private``.
856+
Makes it possible to have multiple public libraries in a single package.
857+
If set to ``public``, depending on this library from another package is
858+
allowed. If set to ``private``, depending on this library is allowed only
859+
from the same package.
855860

856-
Multiple public libraries...
861+
See section on :ref:`Internal Libraries <sublibs>` for examples and more
862+
information.
857863

858864
.. pkg-field:: reexported-modules: exportlist
859865
:since: 1.22
@@ -991,6 +997,18 @@ a real-world use case:
991997

992998
default-language: Haskell2010
993999

1000+
**Multiple public libraries**
1001+
1002+
Cabal 3.0 and later support exposing multiple libraries from a single package
1003+
through the field :pkg-field:`visibility`.
1004+
Having multiple public libraries is useful for separating the unit of
1005+
distribition (package) from the unit of buildable code (library).
1006+
For more information about the rationale and some examples, see
1007+
`this blog post <https://fgaz.me/posts/2019-11-14-cabal-multiple-libraries/>`__.
1008+
1009+
..
1010+
TODO inline the blog post
1011+
9941012

9951013
Opening an interpreter session
9961014
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1561,16 +1579,16 @@ system-dependent values for these fields.
15611579
**Library Names**
15621580

15631581
External libraries are identified by the package's name they're
1564-
provided by (currently a package can only publicly expose its
1565-
main library component; in future, packages with multiple exposed
1566-
public library components will be supported and a syntax for
1567-
referring to public sub-libraries will be provided).
1568-
1569-
In order to specify an intra-package dependency on an internal
1570-
library component you can use the unqualified name of the
1571-
library component. Note that locally defined sub-library
1572-
names shadow external package names of the same name. See section on
1573-
:ref:`Internal Libraries <sublibs>` for examples and more information.
1582+
provided by, optionally followed by a colon and the library name
1583+
(available from ``cabal-version: 3.0``).
1584+
If the library name is absent, the main (unnamed) library will be used.
1585+
To refer to the main (unnamed) library explicitly, use the name of the
1586+
package (``foo:foo``).
1587+
Multiple libraries from the same package can be specified with the shorthand
1588+
syntax ``pkg:{lib1,lib2}```.
1589+
1590+
See section on :ref:`Internal Libraries <sublibs>` for examples and more
1591+
information.
15741592

15751593
**Version Constraints**
15761594

doc/file-format-changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ relative to the respective preceding *published* version.
8686
``cabal-version: 3.0``
8787
----------------------
8888

89+
* New :pkg-field:`visibility` for exposing sublibraries.
90+
91+
* New ``pkg:lib`` and ``pkg:{lib1,lib2}`` syntax in :pkg-field:`build-depends`
92+
for depending on public sublibraries from other packages.
93+
8994
* Added the :pkg-field:`extra-dynamic-library-flavours` field to specify non-trivial
9095
variants of dynamic flavours. It is :pkg-field:`extra-library-flavours` but for
9196
shared libraries. Mainly useful for GHC's RTS library.

0 commit comments

Comments
 (0)