Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document multiple public libraries #8364

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/buildinfo-fields-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,17 @@ virtual-modules
\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)
Library fields
--------------

visibility
* Optional field
* Documentation of :pkg-field:`library:visibility`

.. math::
\left\{ \mathop{\mathord{``}\mathtt{public}\mathord{"}}\mid\mathop{\mathord{``}\mathtt{private}\mathord{"}} \right\}
Package description fields
--------------------------

Expand Down
45 changes: 32 additions & 13 deletions doc/cabal-package.rst
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,18 @@ The library section should contain the following fields:

:since: 3.0

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

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

Multiple public libraries...
See section on :ref:`Internal Libraries <sublibs>` for examples and more
information.

.. pkg-field:: reexported-modules: exportlist
:since: 1.22
Expand Down Expand Up @@ -991,6 +998,18 @@ a real-world use case:

default-language: Haskell2010

**Multiple public libraries**

Cabal 3.0 and later support exposing multiple libraries from a single package
through the field :pkg-field:`library:visibility`.
Having multiple public libraries is useful for separating the unit of
distribution (package) from the unit of buildable code (library).
For more information about the rationale and some examples, see
`this blog post <https://fgaz.me/posts/2019-11-14-cabal-multiple-libraries/>`__.

..
TODO inline the blog post

Opening an interpreter session
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -1561,16 +1580,16 @@ system-dependent values for these fields.
**Library Names**

External libraries are identified by the package's name they're
provided by (currently a package can only publicly expose its
main library component; in future, packages with multiple exposed
public library components will be supported and a syntax for
referring to public sub-libraries will be provided).

In order to specify an intra-package dependency on an internal
library component you can use the unqualified name of the
library component. Note that locally defined sub-library
names shadow external package names of the same name. See section on
:ref:`Internal Libraries <sublibs>` for examples and more information.
provided by, optionally followed by a colon and the library name
jneira marked this conversation as resolved.
Show resolved Hide resolved
(available from ``cabal-version: 3.0``).
If the library name is absent, the main (unnamed) library will be used.
To refer to the main (unnamed) library explicitly, use the name of the
package (``foo:foo``).
Multiple libraries from the same package can be specified with the shorthand
syntax ``pkg:{lib1,lib2}```.

See section on :ref:`Internal Libraries <sublibs>` for examples and more
information.

**Version Constraints**

Expand Down
5 changes: 5 additions & 0 deletions doc/file-format-changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ relative to the respective preceding *published* version.
``cabal-version: 3.0``
----------------------

* New :pkg-field:`library:visibility` for exposing sublibraries.

* New ``pkg:lib`` and ``pkg:{lib1,lib2}`` syntax in :pkg-field:`build-depends`
for depending on public sublibraries from other packages.

* Added the :pkg-field:`extra-dynamic-library-flavours` field to specify non-trivial
variants of dynamic flavours. It is :pkg-field:`extra-library-flavours` but for
shared libraries. Mainly useful for GHC's RTS library.
Expand Down