Skip to content

Commit 5092b8b

Browse files
fgazmergify[bot]
authored andcommitted
Document multiple public libraries (#8364)
(cherry picked from commit f4270fc)
1 parent 3e2889e commit 5092b8b

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-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: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -849,11 +849,18 @@ 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:
853+
``private`` for internal libraries. Cannot be set for main
854+
(unnamed) library, which is always public.
853855

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

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

858865
.. pkg-field:: reexported-modules: exportlist
859866
:since: 1.22
@@ -991,6 +998,18 @@ a real-world use case:
991998

992999
default-language: Haskell2010
9931000

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

9951014
Opening an interpreter session
9961015
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1561,16 +1580,16 @@ system-dependent values for these fields.
15611580
**Library Names**
15621581

15631582
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.
1583+
provided by, optionally followed by a colon and the library name
1584+
(available from ``cabal-version: 3.0``).
1585+
If the library name is absent, the main (unnamed) library will be used.
1586+
To refer to the main (unnamed) library explicitly, use the name of the
1587+
package (``foo:foo``).
1588+
Multiple libraries from the same package can be specified with the shorthand
1589+
syntax ``pkg:{lib1,lib2}```.
1590+
1591+
See section on :ref:`Internal Libraries <sublibs>` for examples and more
1592+
information.
15741593

15751594
**Version Constraints**
15761595

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:`library: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)