Add `cabal get --only-package-description` (#8263)
[cabal.git] / doc / cabal-package.rst
blobe6a9e3e1d6fedaa37158417bd284c9490edc7a1d
1 Package Description
2 ===================
4 The Cabal package is the unit of distribution. When installed, its
5 purpose is to make available:
7 -  One or more Haskell programs.
9 -  At most one library, exposing a number of Haskell modules.
11 However having both a library and executables in a package does not work
12 very well; if the executables depend on the library, they must
13 explicitly list all the modules they directly or indirectly import from
14 that library. Fortunately, starting with Cabal 1.8.0.4, executables can
15 also declare the package that they are in as a dependency, and Cabal
16 will treat them as if they were in another package that depended on the
17 library.
19 Internally, the package may consist of much more than a bunch of Haskell
20 modules: it may also have C source code and header files, source code
21 meant for preprocessing, documentation, test cases, auxiliary tools etc.
23 A package is identified by a globally-unique *package name*, which
24 consists of one or more alphanumeric words separated by hyphens. To
25 avoid ambiguity, each of these words should contain at least one letter.
26 Chaos will result if two distinct packages with the same name are
27 installed on the same system. A particular version of the package is
28 distinguished by a *version number*, consisting of a sequence of one or
29 more integers separated by dots. These can be combined to form a single
30 text string called the *package ID*, using a hyphen to separate the name
31 from the version, e.g. "``HUnit-1.1``".
33 .. Note::
35    Packages are not part of the Haskell language; they simply
36    populate the hierarchical space of module names. In GHC 6.6 and later a
37    program may contain multiple modules with the same name if they come
38    from separate packages; in all other current Haskell systems packages
39    may not overlap in the modules they provide, including hidden modules.
41 Creating a package
42 ------------------
44 Suppose you have a directory hierarchy containing the source files that
45 make up your package. You will need to add two more files to the root
46 directory of the package:
48 :file:`{package-name}.cabal`
49     a Unicode UTF-8 text file containing a package description. For
50     details of the syntax of this file, see the section on
51     `package descriptions`_.
53 :file:`Setup.hs`
54     a single-module Haskell program to perform various setup tasks (with
55     the interface described in the section on :ref:`setup-commands`).
56     This module should import only modules that will be present in all Haskell
57     implementations, including modules of the Cabal library. The content of
58     this file is determined by the :pkg-field:`build-type` setting in the
59     ``.cabal`` file. In most cases it will be trivial, calling on the Cabal
60     library to do most of the work.
62 Once you have these, you can create a source bundle of this directory
63 for distribution. Building of the package is demonstrated in the section
64 :ref:`building-packages`.
66 One of the purposes of Cabal is to make it easier to build a package
67 with different Haskell implementations. So it provides abstractions of
68 features present in different Haskell implementations and wherever
69 possible it is best to take advantage of these to increase portability.
70 Where necessary however it is possible to use specific features of
71 specific implementations. For example one of the pieces of information a
72 package author can put in the package's ``.cabal`` file is what language
73 extensions the code uses. This is far preferable to specifying flags for
74 a specific compiler as it allows Cabal to pick the right flags for the
75 Haskell implementation that the user picks. It also allows Cabal to
76 figure out if the language extension is even supported by the Haskell
77 implementation that the user picks. Where compiler-specific options are
78 needed however, there is an "escape hatch" available. The developer can
79 specify implementation-specific options and more generally there is a
80 configuration mechanism to customise many aspects of how a package is
81 built depending on the Haskell implementation, the Operating system,
82 computer architecture and user-specified configuration flags.
86     name:     Foo
87     version:  1.0
89     library
90       default-language: Haskell2010
91       build-depends:    base >= 4 && < 5
92       exposed-modules:  Foo
93       extensions:       ForeignFunctionInterface
94       ghc-options:      -Wall
95       if os(windows)
96         build-depends: Win32 >= 2.1 && < 2.6
98 Example: A package containing a simple library
99 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101 The HUnit package contains a file ``HUnit.cabal`` containing:
105     cabal-version:  3.0
106     name:           HUnit
107     version:        1.1.1
108     synopsis:       A unit testing framework for Haskell
109     homepage:       http://hunit.sourceforge.net/
110     category:       Testing
111     author:         Dean Herington
112     license:        BSD-3-Clause
113     license-file:   LICENSE
114     build-type:     Simple
116     library
117       build-depends:      base >= 2 && < 4
118       exposed-modules:    Test.HUnit.Base, Test.HUnit.Lang,
119                           Test.HUnit.Terminal, Test.HUnit.Text, Test.HUnit
120       default-extensions: CPP
121       default-language:   Haskell2010
123 and the following ``Setup.hs``:
125 .. code-block:: haskell
127     import Distribution.Simple
128     main = defaultMain
130 Example: A package containing executable programs
131 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135     cabal-version:  3.0
136     name:           TestPackage
137     version:        0.0
138     synopsis:       Small package with two programs
139     author:         Angela Author
140     license:        BSD-3-Clause
141     build-type:     Simple
143     executable program1
144       build-depends:    HUnit >= 1.1.1 && < 1.2
145       main-is:          main.hs
146       hs-source-dirs:   prog1
147       default-language: Haskell2010
149     executable program2
150       -- A different main.hs because of hs-source-dirs.
151       main-is:          main.hs
152       build-depends:    HUnit >= 1.1.1 && < 1.2
153       hs-source-dirs:   prog2
154       other-modules:    Utils
155       default-language: Haskell2010
157 with ``Setup.hs`` the same as above.
159 Example: A package containing a library and executable programs
160 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
164     cabal-version:   3.0
165     name:            TestPackage
166     version:         0.0
167     synopsis:        Package with library and two programs
168     license:         BSD-3-Clause
169     author:          Angela Author
170     build-type:      Simple
172     library
173       build-depends:    HUnit >= 1.1.1 && < 1.2
174       hs-source-dirs:   lib
175       exposed-modules:  A, B, C
176       default-language: Haskell2010
178     executable program1
179       main-is:          main.hs
180       hs-source-dirs:   prog1
181       other-modules:    D, E
182       default-language: Haskell2010
184     executable program2
185       -- A different main.hs because of hs-source-dirs.
186       main-is:          main.hs
187       -- No bound on internal libraries.
188       build-depends:    TestPackage
189       hs-source-dirs:   prog2
190       other-modules:    Utils
191       default-language: Haskell2010
193 with ``Setup.hs`` the same as above. Note that any library modules
194 required (directly or indirectly) by an executable must be listed again.
196 The trivial setup script used in these examples uses the *simple build
197 infrastructure* provided by the Cabal library (see
198 `Distribution.Simple <https://hackage.haskell.org/package/Cabal/docs/Distribution-Simple.html>`__).
199 The simplicity lies in its interface rather that its implementation. It
200 automatically handles preprocessing with standard preprocessors, and
201 builds packages for all the Haskell implementations.
203 The simple build infrastructure can also handle packages where building
204 is governed by system-dependent parameters, if you specify a little more
205 (see the section on `system-dependent parameters`_).
206 A few packages require `more elaborate solutions <more complex packages>`_.
208 .. _pkg-desc:
210 Package descriptions
211 --------------------
213 The package description file must have a name ending in "``.cabal``". It
214 must be a Unicode text file encoded using valid UTF-8. There must be
215 exactly one such file in the directory. The first part of the name is
216 usually the package name, and some of the tools that operate on Cabal
217 packages require this; specifically, Hackage rejects packages which
218 don't follow this rule.
220 In the package description file, lines whose first non-whitespace
221 characters are "``--``" are treated as comments and ignored.
223 This file should contain a number global property descriptions and
224 several sections.
226 -  The `package properties`_ describe the package
227    as a whole, such as name, license, author, etc.
229 -  Optionally, a number of *configuration flags* can be declared. These
230    can be used to enable or disable certain features of a package. (see
231    the section on `configurations`_).
233 -  The (optional) library section specifies the `library`_ properties and
234    relevant `build information`_.
236 -  Following is an arbitrary number of executable sections which describe
237    an executable program and relevant `build information`_.
239 Each section consists of a number of property descriptions in the form
240 of field/value pairs, with a syntax roughly like mail message headers.
242 -  Case is not significant in field names, but is significant in field
243    values.
245 -  To continue a field value, indent the next line relative to the field
246    name.
248 -  Field names may be indented, but all field values in the same section
249    must use the same indentation.
251 -  Tabs are *not* allowed as indentation characters due to a missing
252    standard interpretation of tab width.
254 -  Before Cabal 3.0, to get a blank line in a field value, use an indented "``.``"
256 The syntax of the value depends on the field. Field types include:
258 *token*, *filename*, *directory*
259     Either a sequence of one or more non-space non-comma characters, or
260     a quoted string in Haskell 98 lexical syntax. The latter can be used
261     for escaping whitespace, for example:
262     ``ghc-options: -Wall "-with-rtsopts=-T -I1"``. Unless otherwise
263     stated, relative filenames and directories are interpreted from the
264     package root directory.
265 *freeform*, *URL*, *address*
266     An arbitrary, uninterpreted string.
267 *identifier*
268     A letter followed by zero or more alphanumerics or underscores.
269 *compiler*
270     A compiler flavor (one of: ``GHC``, ``UHC`` or ``LHC``)
271     followed by a version range. For example, ``GHC ==6.10.3``, or
272     ``LHC >=0.6 && <0.8``.
274 Modules and preprocessors
275 ^^^^^^^^^^^^^^^^^^^^^^^^^
277 Haskell module names listed in the :pkg-field:`library:exposed-modules` and
278 :pkg-field:`library:other-modules` fields may correspond to Haskell source
279 files, i.e. with names ending in "``.hs``" or "``.lhs``", or to inputs for
280 various Haskell preprocessors. The simple build infrastructure understands the
281 extensions:
283 -  ``.gc`` (:hackage-pkg:`greencard`)
284 -  ``.chs`` (:hackage-pkg:`c2hs`)
285 -  ``.hsc`` (:hackage-pkg:`hsc2hs`)
286 -  ``.y`` and ``.ly`` (happy_)
287 -  ``.x`` (alex_)
288 -  ``.cpphs`` (cpphs_)
290 When building, Cabal will automatically run the appropriate preprocessor
291 and compile the Haskell module it produces. For the ``c2hs`` and
292 ``hsc2hs`` preprocessors, Cabal will also automatically add, compile and
293 link any C sources generated by the preprocessor (produced by
294 ``hsc2hs``'s ``#def`` feature or ``c2hs``'s auto-generated wrapper
295 functions). Dependencies on pre-processors are specified via the
296 :pkg-field:`build-tools` or :pkg-field:`build-tool-depends` fields.
298 Some fields take lists of values, which are optionally separated by
299 commas, except for the :pkg-field:`build-depends` field, where the commas are
300 mandatory.
302 Some fields are marked as required. All others are optional, and unless
303 otherwise specified have empty default values.
305 Package properties
306 ^^^^^^^^^^^^^^^^^^
308 These fields may occur in the first top-level properties section and
309 describe the package as a whole:
311 .. pkg-field:: name: package-name (required)
313     The unique name of the package, without the version number.
315     As pointed out in the section on `package descriptions`_, some
316     tools require the package-name specified for this field to match
317     the package description's file-name :file:`{package-name}.cabal`.
319     Package names are case-sensitive and must match the regular expression
320     (i.e. alphanumeric "words" separated by dashes; each alphanumeric
321     word must contain at least one letter):
322     ``[[:digit:]]*[[:alpha:]][[:alnum:]]*(-[[:digit:]]*[[:alpha:]][[:alnum:]]*)*``.
324     Or, expressed in ABNF_:
326     .. code-block:: abnf
328         package-name      = package-name-part *("-" package-name-part)
329         package-name-part = *DIGIT UALPHA *UALNUM
331         UALNUM = UALPHA / DIGIT
332         UALPHA = ... ; set of alphabetic Unicode code-points
334     .. note::
336         Hackage restricts package names to the ASCII subset.
338 .. pkg-field:: version: numbers (required)
340     The package version number, usually consisting of a sequence of
341     natural numbers separated by dots, i.e. as the regular
342     expression ``[0-9]+([.][0-9]+)*`` or expressed in ABNF_:
344     .. code-block:: abnf
346         package-version = 1*DIGIT *("." 1*DIGIT)
348 .. pkg-field:: cabal-version: x.y[.z]
350     The version of the Cabal specification that this package
351     description uses. The Cabal specification does slowly evolve (see
352     also :ref:`spec-history`), introducing new features and
353     occasionally changing the meaning of existing features.
354     Specifying which version of the specification you are using
355     enables programs which process the package description to know
356     what syntax to expect and what each part means.
358     The version number you specify will affect both compatibility and
359     behaviour. Most tools (including the Cabal library and the ``cabal``
360     program) understand a range of versions of the Cabal specification.
361     Older tools will of course only work with older versions of the
362     Cabal specification that was known at the time. Most of the time,
363     tools that are too old will recognise this fact and produce a
364     suitable error message. Likewise, ``cabal check`` will tell you
365     whether the version number is sufficiently high for the features
366     you use in the package description.
368     As for behaviour, new versions of the Cabal specification can change the
369     meaning of existing syntax. This means if you want to take advantage
370     of the new meaning or behaviour then you must specify the newer
371     Cabal version. Tools are expected to use the meaning and behaviour
372     appropriate to the version given in the package description.
374     In particular, the syntax of package descriptions changed
375     significantly with Cabal version 1.2 and the :pkg-field:`cabal-version`
376     field is now required. Files written in the old syntax are still
377     recognized, so if you require compatibility with very old Cabal
378     versions then you may write your package description file using the
379     old syntax. Please consult the user's guide of an older Cabal
380     version for a description of that syntax.
382     Starting with ``cabal-version: 2.2`` this field is only valid if
383     fully contained in the very first line of a package description
384     and ought to adhere to the ABNF_ grammar
386     .. code-block:: abnf
388         newstyle-spec-version-decl = "cabal-version" *WS ":" *WS newstyle-spec-version *WS
390         newstyle-spec-version      = NUM "." NUM [ "." NUM ]
392         NUM    = DIGIT0 / DIGITP 1*DIGIT0
393         DIGIT0 = %x30-39
394         DIGITP = %x31-39
395         WS     = %20
398     .. note::
400         For package descriptions using a format prior to
401         ``cabal-version: 1.12`` the legacy syntax resembling a version
402         range syntax
404         .. code-block:: cabal
406             cabal-version: >= 1.10
408         needs to be used.
410         This legacy syntax is supported up until ``cabal-version: >=
411         2.0`` it is however strongly recommended to avoid using the
412         legacy syntax. See also :issue:`4899`.
416 .. pkg-field:: build-type: identifier
418     :default: ``Custom`` or ``Simple``
420     The type of build used by this package. Build types are the
421     constructors of the
422     `BuildType <https://hackage.haskell.org/package/Cabal/docs/Distribution-PackageDescription.html#t:BuildType>`__
423     type. This field is optional and when missing, its default value
424     is inferred according to the following rules:
426      - When :pkg-field:`cabal-version` is set to ``2.2`` or higher,
427        the default is ``Simple`` unless a :pkg-section:`custom-setup`
428        exists, in which case the inferred default is ``Custom``.
430      - For lower :pkg-field:`cabal-version` values, the default is
431        ``Custom`` unconditionally.
433     If the build type is anything other than ``Custom``, then the
434     ``Setup.hs`` file *must* be exactly the standardized content
435     discussed below. This is because in these cases, ``cabal`` will
436     ignore the ``Setup.hs`` file completely, whereas other methods of
437     package management, such as ``runhaskell Setup.hs [CMD]``, still
438     rely on the ``Setup.hs`` file.
440     For build type ``Simple``, the contents of ``Setup.hs`` must be:
442     .. code-block:: haskell
444         import Distribution.Simple
445         main = defaultMain
447     For build type ``Configure`` (see the section on `system-dependent
448     parameters`_ below), the contents of
449     ``Setup.hs`` must be:
451     .. code-block:: haskell
453         import Distribution.Simple
454         main = defaultMainWithHooks autoconfUserHooks
456     For build type ``Make`` (see the section on `more complex packages`_ below),
457     the contents of ``Setup.hs`` must be:
459     .. code-block:: haskell
461         import Distribution.Make
462         main = defaultMain
464     For build type ``Custom``, the file ``Setup.hs`` can be customized,
465     and will be used both by ``cabal`` and other tools.
467     For most packages, the build type ``Simple`` is sufficient.
469 .. pkg-field:: license: SPDX expression
471     :default: ``NONE``
473     The type of license under which this package is distributed.
475     Starting with ``cabal-version: 2.2`` the ``license`` field takes a
476     (case-sensitive) SPDX expression such as
478     .. code-block:: cabal
480         license: Apache-2.0 AND (MIT OR GPL-2.0-or-later)
482     See `SPDX IDs: How to use <https://spdx.org/ids-how>`__ for more
483     examples of SPDX expressions.
485     The version of the
486     `list of SPDX license identifiers <https://spdx.org/licenses/>`__
487     is a function of the :pkg-field:`cabal-version` value as defined
488     in the following table:
490     +--------------------------+--------------------+
491     | Cabal specification      | SPDX license list  |
492     | version                  | version            |
493     |                          |                    |
494     +==========================+====================+
495     | ``cabal-version: 2.2``   | ``3.0 2017-12-28`` |
496     +--------------------------+--------------------+
497     | ``cabal-version: 2.4``   | ``3.2 2018-07-10`` |
498     +--------------------------+--------------------+
500     **Pre-SPDX Legacy Identifiers**
502     The license identifier in the table below are defined for
503     ``cabal-version: 2.0`` and previous versions of the Cabal
504     specification.
506     +--------------------------+-----------------+
507     | :pkg-field:`license`     | Note            |
508     | identifier               |                 |
509     |                          |                 |
510     +==========================+=================+
511     | ``GPL``                  |                 |
512     | ``GPL-2``                |                 |
513     | ``GPL-3``                |                 |
514     +--------------------------+-----------------+
515     | ``LGPL``                 |                 |
516     | ``LGPL-2.1``             |                 |
517     | ``LGPL-3``               |                 |
518     +--------------------------+-----------------+
519     | ``AGPL``                 | since 1.18      |
520     | ``AGPL-3``               |                 |
521     +--------------------------+-----------------+
522     | ``BSD2``                 | since 1.20      |
523     +--------------------------+-----------------+
524     | ``BSD3``                 |                 |
525     +--------------------------+-----------------+
526     | ``MIT``                  |                 |
527     +--------------------------+-----------------+
528     | ``ISC``                  | since 1.22      |
529     +--------------------------+-----------------+
530     | ``MPL-2.0``              | since 1.20      |
531     +--------------------------+-----------------+
532     | ``Apache``               |                 |
533     | ``Apache-2.0``           |                 |
534     +--------------------------+-----------------+
535     | ``PublicDomain``         |                 |
536     +--------------------------+-----------------+
537     | ``AllRightsReserved``    |                 |
538     +--------------------------+-----------------+
539     | ``OtherLicense``         |                 |
540     +--------------------------+-----------------+
543 .. pkg-field:: license-file: filename
545     See :pkg-field:`license-files`.
547 .. pkg-field:: license-files: filename list
548     :since: 1.20
550     The name of a file(s) containing the precise copyright license for
551     this package. The license file(s) will be installed with the
552     package.
554     If you have multiple license files then use the :pkg-field:`license-files`
555     field instead of (or in addition to) the :pkg-field:`license-file` field.
557 .. pkg-field:: copyright: freeform
559     The content of a copyright notice, typically the name of the holder
560     of the copyright on the package and the year(s) from which copyright
561     is claimed. For example::
563       copyright: (c) 2006-2007 Joe Bloggs
565 .. pkg-field:: author: freeform
567     The original author of the package.
569     Remember that ``.cabal`` files are Unicode, using the UTF-8
570     encoding.
572 .. pkg-field:: maintainer: address
574     The current maintainer or maintainers of the package. This is an
575     e-mail address to which users should send bug reports, feature
576     requests and patches.
578 .. pkg-field:: stability: freeform
580     The stability level of the package, e.g. ``alpha``,
581     ``experimental``, ``provisional``, ``stable``.
583 .. pkg-field:: homepage: URL
585     The package homepage.
587 .. pkg-field:: bug-reports: URL
589     The URL where users should direct bug reports. This would normally
590     be either:
592     -  A ``mailto:`` URL, e.g. for a person or a mailing list.
594     -  An ``http:`` (or ``https:``) URL for an online bug tracking
595        system.
597     For example Cabal itself uses a web-based bug tracking system
599     ::
601         bug-reports: https://github.com/haskell/cabal/issues
603 .. pkg-field:: package-url: URL
605     The location of a source bundle for the package. The distribution
606     should be a Cabal package.
608 .. pkg-field:: synopsis: freeform
610     A very short description of the package, for use in a table of
611     packages. This is your headline, so keep it short (one line) but as
612     informative as possible. Save space by not including the package
613     name or saying it's written in Haskell.
615 .. pkg-field:: description: freeform
617     Description of the package. This may be several paragraphs, and
618     should be aimed at a Haskell programmer who has never heard of your
619     package before.
621     For library packages, this field is used as prologue text by
622     :ref:`setup-haddock` and thus may contain the same markup as Haddock_
623     documentation comments.
625 .. pkg-field:: category: freeform
627     A classification category for future use by the package catalogue
628     Hackage_. These categories have not
629     yet been specified, but the upper levels of the module hierarchy
630     make a good start.
632 .. pkg-field:: tested-with: compiler list
634     A list of compilers and versions against which the package has been
635     tested (or at least built). The value of this field is not used by Cabal
636     and is rather intended as extra metadata for use by third party
637     tooling, such as e.g. CI tooling.
639     Here's a typical usage example:
641     ::
643         tested-with: GHC == 9.0.1, GHC == 8.10.4, GHC == 8.8.4,
644                      GHC == 8.6.5, GHC == 8.4.4, GHC == 8.2.2, GHC == 8.0.2,
645                      GHC == 7.10.3, GHC == 7.8.4, GHC == 7.6.3, GHC == 7.4.2
647     The same can be spread over several lines, for instance:
649     ::
651         tested-with: GHC == 9.0.1
652                    , GHC == 8.10.4
653                    , GHC == 8.8.4
654                    , GHC == 8.6.5
655                    , GHC == 8.4.4
656                    , GHC == 8.2.2
657                    , GHC == 8.0.2
658                    , GHC == 7.10.3
659                    , GHC == 7.8.4
660                    , GHC == 7.6.3
661                    , GHC == 7.4.2
663     The separating comma can also be dropped altogether:
665     ::
667         tested-with:
668           GHC == 9.0.1
669           GHC == 8.10.4
670           GHC == 8.8.4
671           GHC == 8.6.5
672           GHC == 8.4.4
673           GHC == 8.2.2
674           GHC == 8.0.2
675           GHC == 7.10.3
676           GHC == 7.8.4
677           GHC == 7.6.3
678           GHC == 7.4.2
680     However, this alternative might
681     `disappear <https://github.com/haskell/cabal/issues/4894#issuecomment-909008657>`__
682     in the future.
684     Starting with :pkg-field:`cabal-version` 3.0,
685     there are further conveniences.
687     1. A preceding ``,`` is allowed, so a bullet-list style
688        is possible (recommended):
690         ::
692             tested-with:
693               , GHC == 9.0.1
694               , GHC == 8.10.4
695               , GHC == 8.8.4
696               , GHC == 8.6.5
697               , GHC == 8.4.4
698               , GHC == 8.2.2
699               , GHC == 8.0.2
700               , GHC == 7.10.3
701               , GHC == 7.8.4
702               , GHC == 7.6.3
703               , GHC == 7.4.2
706     2. A concise set notation syntax is available:
708        ::
710            tested-with: GHC == { 9.0.1, 8.10.4, 8.8.4, 8.6.5, 8.4.4, 8.2.2, 8.0.2, 7.10.3, 7.8.4, 7.6.3, 7.4.2 }
712 .. pkg-field:: data-files: filename list
714     A list of files to be installed for run-time use by the package.
715     This is useful for packages that use a large amount of static data,
716     such as tables of values or code templates. Cabal provides a way to
717     `find these files at run-time <#accessing-data-files-from-package-code>`_.
719     A limited form of ``*`` wildcards in file names, for example
720     ``data-files: images/*.png`` matches all the ``.png`` files in the
721     ``images`` directory. ``data-files: audio/**/*.mp3`` matches all
722     the ``.mp3`` files in the ``audio`` directory, including
723     subdirectories.
725     The specific limitations of this wildcard syntax are
727     - ``*`` wildcards are only allowed in place of the file name, not
728       in the directory name or file extension. It must replace the
729       whole file name (e.g., ``*.html`` is allowed, but
730       ``chapter-*.html`` is not). If a wildcard is used, it must be
731       used with an extension, so ``data-files: data/*`` is not
732       allowed.
734     - Prior to Cabal 2.4, when matching a wildcard plus extension, a
735       file's full extension must match exactly, so ``*.gz`` matches
736       ``foo.gz`` but not ``foo.tar.gz``. This restriction has been
737       lifted when ``cabal-version: 2.4`` or greater so that ``*.gz``
738       does match ``foo.tar.gz``
740     - ``*`` wildcards will not match if the file name is empty (e.g.,
741       ``*.html`` will not match ``foo/.html``).
743     - ``**`` wildcards can only appear as the final path component
744       before the file name (e.g., ``data/**/images/*.jpg`` is not
745       allowed).
747     - Prior to Cabal 3.8, if a ``**`` wildcard is used, then
748       the file name must include a ``*`` wildcard (e.g.,
749       ``data/**/README.rst`` was not allowed). As of ``cabal-version:
750       3.8`` or greater, this restriction is lifted.
752     - A wildcard that does not match any files is an error.
754     The reason for providing only a very limited form of wildcard is to
755     concisely express the common case of a large number of related files
756     of the same file type without making it too easy to accidentally
757     include unwanted files.
759     On efficiency: if you use ``**`` patterns, the directory tree will
760     be walked starting with the parent directory of the ``**``. If
761     that's the root of the project, this might include ``.git/``,
762     ``dist-newstyle/``, or other large directories! To avoid this
763     behaviour, put the files that wildcards will match against in
764     their own folder.
766     ``**`` wildcards are available starting in Cabal 2.4.
768 .. pkg-field:: data-dir: directory
770     The directory where Cabal looks for data files to install, relative
771     to the source directory. By default, Cabal will look in the source
772     directory itself.
774 .. pkg-field:: extra-source-files: filename list
776     A list of additional files to be included in source distributions
777     built with :ref:`setup-sdist`. As with :pkg-field:`data-files` it can use
778     a limited form of ``*`` wildcards in file names.
780 .. pkg-field:: extra-doc-files: filename list
781     :since: 1.18
783     A list of additional files to be included in source distributions,
784     and also copied to the html directory when Haddock documentation is
785     generated. As with :pkg-field:`data-files` it can use a limited form of
786     ``*`` wildcards in file names.
788 .. pkg-field:: extra-tmp-files: filename list
790     A list of additional files or directories to be removed by
791     :ref:`setup-clean`. These  would typically be additional files created by
792     additional hooks, such as the scheme described in the section on
793     `system-dependent parameters`_.
795 Library
796 ^^^^^^^
798 .. pkg-section:: library name
799     :synopsis: Library build information.
801     Build information for libraries.
803     Currently, there can only be one publicly exposed library in a
804     package, and its name is the same as package name set by global
805     :pkg-field:`name` field. In this case, the ``name`` argument to
806     the :pkg-section:`library` section must be omitted.
808     Starting with Cabal 2.0, private internal sub-library components
809     can be defined by setting the ``name`` field to a name
810     different from the current package's name; see section on
811     :ref:`Internal Libraries <sublibs>` for more information.
813 The library section should contain the following fields:
815 .. pkg-field:: exposed-modules: identifier list
817     :required: if this package contains a library
819     A list of modules added by this package.
821 .. pkg-field:: virtual-modules: identifier list
822     :since: 2.2
824     A list of virtual modules provided by this package.  Virtual modules
825     are modules without a source file.  See for example the ``GHC.Prim``
826     module from the ``ghc-prim`` package.  Modules listed here will not be
827     built, but still end up in the list of ``exposed-modules`` in the
828     installed package info when the package is registered in the package
829     database.
831 .. pkg-field:: exposed: boolean
833     :default: ``True``
835     Some Haskell compilers (notably GHC) support the notion of packages
836     being "exposed" or "hidden" which means the modules they provide can
837     be easily imported without always having to specify which package
838     they come from. However this only works effectively if the modules
839     provided by all exposed packages do not overlap (otherwise a module
840     import would be ambiguous).
842     Almost all new libraries use hierarchical module names that do not
843     clash, so it is very uncommon to have to use this field. However it
844     may be necessary to set ``exposed: False`` for some old libraries
845     that use a flat module namespace or where it is known that the
846     exposed modules would clash with other common modules.
848 .. pkg-field:: visibility: visibility specifiers
850     :since: 3.0
852     :default: ``private`` for internal libraries. Cannot be set for public library.
854     Cabal recognizes ``public`` and ``private`` here...
856     Multiple public libraries...
858 .. pkg-field:: reexported-modules: exportlist
859     :since: 1.22
861     Supported only in GHC 7.10 and later. A list of modules to
862     *reexport* from this package. The syntax of this field is
863     ``orig-pkg:Name as NewName`` to reexport module ``Name`` from
864     ``orig-pkg`` with the new name ``NewName``. We also support
865     abbreviated versions of the syntax: if you omit ``as NewName``,
866     we'll reexport without renaming; if you omit ``orig-pkg``, then we
867     will automatically figure out which package to reexport from, if
868     it's unambiguous.
870     Reexported modules are useful for compatibility shims when a package
871     has been split into multiple packages, and they have the useful
872     property that if a package provides a module, and another package
873     reexports it under the same name, these are not considered a
874     conflict (as would be the case with a stub module.) They can also be
875     used to resolve name conflicts.
877 .. pkg-field:: signatures: signature list
878     :since: 2.0
880     Supported only in GHC 8.2 and later. A list of `module signatures <https://downloads.haskell.org/~ghc/master/users-guide/separate_compilation.html#module-signatures>`__ required by this package.
882     Module signatures are part of the Backpack_ extension to
883     the Haskell module system.
885     Packages that do not export any modules and only export required signatures
886     are called "signature-only packages", and their signatures are subjected to
887     `signature thinning
888     <https://wiki.haskell.org/Module_signature#How_to_use_a_signature_package>`__.
892 The library section may also contain build information fields (see the
893 section on `build information`_).
895 .. _sublibs:
897 **Internal Libraries**
899 Cabal 2.0 and later support "internal libraries", which are extra named
900 libraries (as opposed to the usual unnamed library section). For
901 example, suppose that your test suite needs access to some internal
902 modules in your library, which you do not otherwise want to export. You
903 could put these modules in an internal library, which the main library
904 and the test suite :pkg-field:`build-depends` upon. Then your Cabal file might
905 look something like this:
909     cabal-version:  2.0
910     name:           foo
911     version:        0.1.0.0
912     license:        BSD3
913     license-file:   LICENSE
914     build-type:     Simple
916     library foo-internal
917         exposed-modules:  Foo.Internal
918         -- NOTE: no explicit constraints on base needed
919         --       as they're inherited from the 'library' stanza
920         build-depends:    base
921         default-language: Haskell2010
923     library
924         exposed-modules:  Foo.Public
925         build-depends:    foo-internal, base >= 4.3 && < 5
926         default-language: Haskell2010
928     test-suite test-foo
929         main-is:          test-foo.hs
930         -- NOTE: no constraints on 'foo-internal' as same-package
931         --       dependencies implicitly refer to the same package instance
932         build-depends:    foo-internal, base
933         default-language: Haskell2010
935 Internal libraries are also useful for packages that define multiple
936 executables, but do not define a publicly accessible library. Internal
937 libraries are only visible internally in the package (so they can only
938 be added to the :pkg-field:`build-depends` of same-package libraries,
939 executables, test suites, etc.) Internal libraries locally shadow any
940 packages which have the same name; consequently, don't name an internal
941 library with the same name as an external dependency if you need to be
942 able to refer to the external dependency in a
943 :pkg-field:`build-depends` declaration.
945 Shadowing can be used to vendor an external dependency into a package
946 and thus emulate *private dependencies*. Below is an example based on
947 a real-world use case:
951     cabal-version: 3.0
952     name: haddock-library
953     version: 1.6.0
954     license: BSD-3-Clause
956     library
957       build-depends:
958         , base         ^>= 4.11.1.0
959         , bytestring   ^>= 0.10.2.0
960         , containers   ^>= 0.4.2.1 || ^>= 0.5.0.0
961         , transformers ^>= 0.5.0.0
963       hs-source-dirs:       src
965       -- internal sub-lib
966       build-depends:        attoparsec
968       exposed-modules:
969         Documentation.Haddock
971       default-language: Haskell2010
973     library attoparsec
974       build-depends:
975         , base         ^>= 4.11.1.0
976         , bytestring   ^>= 0.10.2.0
977         , deepseq      ^>= 1.4.0.0
979       hs-source-dirs:       vendor/attoparsec-0.13.1.0
981       -- NB: haddock-library needs only small part of lib:attoparsec
982       --     internally, so we only bundle that subset here
983       exposed-modules:
984         Data.Attoparsec.ByteString
985         Data.Attoparsec.Combinator
987       other-modules:
988         Data.Attoparsec.Internal
990       ghc-options: -funbox-strict-fields -Wall -fwarn-tabs -O2
992       default-language: Haskell2010
995 Opening an interpreter session
996 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
998 While developing a package, it is often useful to make its code
999 available inside an interpreter session. This can be done with the
1000 ``repl`` command:
1002 .. code-block:: console
1004     $ cabal repl
1006 The name comes from the acronym
1007 `REPL <http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop>`__,
1008 which stands for "read-eval-print-loop". By default ``cabal repl`` loads
1009 the first component in a package. If the package contains several named
1010 components, the name can be given as an argument to ``repl``. The name
1011 can be also optionally prefixed with the component's type for
1012 disambiguation purposes. Example:
1014 .. code-block:: console
1016     $ cabal repl foo
1017     $ cabal repl exe:foo
1018     $ cabal repl test:bar
1019     $ cabal repl bench:baz
1021 Freezing dependency versions
1022 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1024 If a package is built in several different environments, such as a
1025 development environment, a staging environment and a production
1026 environment, it may be necessary or desirable to ensure that the same
1027 dependency versions are selected in each environment. This can be done
1028 with the ``freeze`` command:
1030 .. code-block:: console
1032     $ cabal freeze
1034 The command writes the selected version for all dependencies to the
1035 ``cabal.config`` file. All environments which share this file will use
1036 the dependency versions specified in it.
1038 Generating dependency version bounds
1039 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1041 Cabal also has the ability to suggest dependency version bounds that
1042 conform to the `Package Versioning Policy`_, which is
1043 a recommended versioning system for publicly released Cabal packages.
1044 This is done by running the ``gen-bounds`` command:
1046 .. code-block:: console
1048     $ cabal gen-bounds
1050 For example, given the following dependencies without bounds specified in
1051 :pkg-field:`build-depends`:
1055     build-depends:
1056       base,
1057       mtl,
1058       transformers,
1060 ``gen-bounds`` might suggest changing them to the following:
1064     build-depends:
1065       base          >= 4.15.0 && < 4.16,
1066       mtl           >= 2.2.2 && < 2.3,
1067       transformers  >= 0.5.6 && < 0.6,
1070 Listing outdated dependency version bounds
1071 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1073 Manually updating dependency version bounds in a ``.cabal`` file or a
1074 freeze file can be tedious, especially when there's a lot of
1075 dependencies. The ``cabal outdated`` command is designed to help with
1076 that. It will print a list of packages for which there is a new
1077 version on Hackage that is outside the version bound specified in the
1078 ``build-depends`` field. The ``outdated`` command can also be
1079 configured to act on the freeze file (both old- and v2-style) and
1080 ignore major (or all) version bumps on Hackage for a subset of
1081 dependencies.
1083 Examples:
1085 .. code-block:: console
1087     $ cd /some/package
1088     $ cabal outdated
1089     Outdated dependencies:
1090     haskell-src-exts <1.17 (latest: 1.19.1)
1091     language-javascript <0.6 (latest: 0.6.0.9)
1092     unix ==2.7.2.0 (latest: 2.7.2.1)
1094     $ cabal outdated --simple-output
1095     haskell-src-exts
1096     language-javascript
1097     unix
1099     $ cabal outdated --ignore=haskell-src-exts
1100     Outdated dependencies:
1101     language-javascript <0.6 (latest: 0.6.0.9)
1102     unix ==2.7.2.0 (latest: 2.7.2.1)
1104     $ cabal outdated --ignore=haskell-src-exts,language-javascript,unix
1105     All dependencies are up to date.
1107     $ cabal outdated --ignore=haskell-src-exts,language-javascript,unix -q
1108     $ echo $?
1109     0
1111     $ cd /some/other/package
1112     $ cabal outdated --freeze-file
1113     Outdated dependencies:
1114     HTTP ==4000.3.3 (latest: 4000.3.4)
1115     HUnit ==1.3.1.1 (latest: 1.5.0.0)
1117     $ cabal outdated --freeze-file --ignore=HTTP --minor=HUnit
1118     Outdated dependencies:
1119     HUnit ==1.3.1.1 (latest: 1.3.1.2)
1121 See `the command documentation <cabal-commands.html#cabal-outdated>`__ for a
1122 list of available flags.
1124 Executables
1125 ^^^^^^^^^^^
1127 .. pkg-section:: executable name
1128     :synopsis: Executable build info section.
1130     Executable sections (if present) describe executable programs contained
1131     in the package and must have an argument after the section label, which
1132     defines the name of the executable. This is a freeform argument but may
1133     not contain spaces.
1135 The executable may be described using the following fields, as well as
1136 build information fields (see the section on `build information`_).
1138 .. pkg-field:: main-is: filename (required)
1140     The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
1141     module. Note that it is the ``.hs`` filename that must be listed,
1142     even if that file is generated using a preprocessor. The source file
1143     must be relative to one of the directories listed in
1144     :pkg-field:`hs-source-dirs`. Further, while the name of the file may
1145     vary, the module itself must be named ``Main``.
1147     Starting with ``cabal-version: 1.18`` this field supports
1148     specifying a C, C++, or objC source file as the main entry point.
1150 .. pkg-field:: scope: token
1151     :since: 2.0
1153     Whether the executable is ``public`` (default) or ``private``, i.e. meant to
1154     be run by other programs rather than the user. Private executables are
1155     installed into `$libexecdir/$libexecsubdir`.
1157 Running executables
1158 """""""""""""""""""
1160 You can have Cabal build and run your executables by using the ``run``
1161 command:
1163 .. code-block:: console
1165     $ cabal run EXECUTABLE [-- EXECUTABLE_FLAGS]
1167 This command will configure, build and run the executable
1168 ``EXECUTABLE``. The double dash separator is required to distinguish
1169 executable flags from ``run``'s own flags. If there is only one
1170 executable defined in the whole package, the executable's name can be
1171 omitted. See the output of ``cabal help run`` for a list of options you
1172 can pass to ``cabal run``.
1174 Test suites
1175 ^^^^^^^^^^^
1177 .. pkg-section:: test-suite name
1178     :synopsis: Test suite build information.
1180     Test suite sections (if present) describe package test suites and must
1181     have an argument after the section label, which defines the name of the
1182     test suite. This is a freeform argument, but may not contain spaces. It
1183     should be unique among the names of the package's other test suites, the
1184     package's executables, and the package itself. Using test suite sections
1185     requires at least Cabal version 1.9.2.
1187 The test suite may be described using the following fields, as well as
1188 build information fields (see the section on `build information`_).
1190 .. pkg-field:: type: interface
1192     The interface type and version of the test suite. Cabal supports two
1193     test suite interfaces, called ``exitcode-stdio-1.0`` (default) and
1194     ``detailed-0.9``. Each of these types may require or disallow other
1195     fields as described below.
1197 Test suites using the ``exitcode-stdio-1.0`` (default) interface are executables
1198 that indicate test failure with a non-zero exit code when run; they may
1199 provide human-readable log information through the standard output and
1200 error channels. The ``exitcode-stdio-1.0`` type requires the ``main-is``
1201 field.
1203 .. pkg-field:: main-is: filename
1204     :synopsis: Module containing tests main function.
1206     :disallowed: ``detailed-0.9``
1208     The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
1209     module. Note that it is the ``.hs`` filename that must be listed,
1210     even if that file is generated using a preprocessor. The source file
1211     must be relative to one of the directories listed in
1212     :pkg-field:`hs-source-dirs`. This field is analogous to the ``main-is`` field
1213     of an executable section.
1215 Test suites using the ``detailed-0.9`` interface are modules exporting
1216 the symbol ``tests :: IO [Test]``. The ``Test`` type is exported by the
1217 module ``Distribution.TestSuite`` provided by Cabal. For more details,
1218 see the example below.
1220 The ``detailed-0.9`` interface allows Cabal and other test agents to
1221 inspect a test suite's results case by case, producing detailed human-
1222 and machine-readable log files. The ``detailed-0.9`` interface requires
1223 the :pkg-field:`test-module` field.
1225 .. pkg-field:: test-module: identifier
1227     :disallowed: ``exitcode-stdio-1.0``
1229     The module exporting the ``tests`` symbol.
1231 Example: Package using ``exitcode-stdio-1.0`` interface
1232 """""""""""""""""""""""""""""""""""""""""""""""""""""""
1234 The example package description and executable source file below
1235 demonstrate the use of the ``exitcode-stdio-1.0`` interface.
1237 .. code-block:: cabal
1238     :caption: foo.cabal
1240     Cabal-Version:  3.0
1241     Name:           foo
1242     Version:        1.0
1243     License:        BSD-3-Clause
1244     Build-Type:     Simple
1246     Test-Suite test-foo
1247         main-is:          test-foo.hs
1248         build-depends:    base >= 4 && < 5
1249         default-language: Haskell2010
1251 .. code-block:: haskell
1252     :caption: test-foo.hs
1254     module Main where
1256     import System.Exit (exitFailure)
1258     main = do
1259         putStrLn "This test always fails!"
1260         exitFailure
1262 Example: Package using ``detailed-0.9`` interface
1263 """""""""""""""""""""""""""""""""""""""""""""""""
1265 The example package description and test module source file below
1266 demonstrate the use of the ``detailed-0.9`` interface. The test module
1267 also develops a simple implementation of the interface set by
1268 ``Distribution.TestSuite``, but in actual usage the implementation would
1269 be provided by the library that provides the testing facility.
1271 .. code-block:: cabal
1272     :caption: bar.cabal
1274     Cabal-Version:  3.0
1275     Name:           bar
1276     Version:        1.0
1277     License:        BSD-3-Clause
1278     Build-Type:     Simple
1280     Test-Suite test-bar
1281         test-module:      Bar
1282         build-depends:    base >= 4 && < 5, Cabal >= 1.9.2 && < 2
1283         default-language: Haskell2010
1286 .. code-block:: haskell
1287     :caption: Bar.hs
1289     module Bar ( tests ) where
1291     import Distribution.TestSuite
1293     tests :: IO [Test]
1294     tests = return [ Test succeeds, Test fails ]
1295       where
1296         succeeds = TestInstance
1297             { run = return $ Finished Pass
1298             , name = "succeeds"
1299             , tags = []
1300             , options = []
1301             , setOption = \_ _ -> Right succeeds
1302             }
1303         fails = TestInstance
1304             { run = return $ Finished $ Fail "Always fails!"
1305             , name = "fails"
1306             , tags = []
1307             , options = []
1308             , setOption = \_ _ -> Right fails
1309             }
1311 Running test suites
1312 """""""""""""""""""
1314 You can have Cabal run your test suites using its built-in test runner:
1318     $ cabal configure --enable-tests
1319     $ cabal build
1320     $ cabal test
1322 See the output of ``cabal help test`` for a list of options you can pass
1323 to ``cabal test``.
1325 Benchmarks
1326 ^^^^^^^^^^
1328 .. pkg-section:: benchmark name
1329     :since: 1.9.2
1330     :synopsis: Benchmark build information.
1332     Benchmark sections (if present) describe benchmarks contained in the
1333     package and must have an argument after the section label, which defines
1334     the name of the benchmark. This is a freeform argument, but may not
1335     contain spaces. It should be unique among the names of the package's
1336     other benchmarks, the package's test suites, the package's executables,
1337     and the package itself. Using benchmark sections requires at least Cabal
1338     version 1.9.2.
1340 The benchmark may be described using the following fields, as well as
1341 build information fields (see the section on `build information`_).
1343 .. pkg-field:: main-is: filename
1345     The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
1346     module. Note that it is the ``.hs`` filename that must be listed,
1347     even if that file is generated using a preprocessor. The source file
1348     must be relative to one of the directories listed in
1349     :pkg-field:`hs-source-dirs`. This field is analogous to the ``main-is``
1350     field of an executable section. Further, while the name of the file may
1351     vary, the module itself must be named ``Main``.
1353 Example:
1354 """""""""""""""""""""""""""""""""""""""""""""""""""""""
1356 .. code-block:: cabal
1357     :caption: foo.cabal
1358     :name: foo-bench.cabal
1360     Cabal-Version:  3.0
1361     Name:           foo
1362     Version:        1.0
1363     License:        BSD-3-Clause
1364     Build-Type:     Simple
1366     Benchmark bench-foo
1367         main-is:          bench-foo.hs
1368         build-depends:    base >= 4 && < 5, time >= 1.1 && < 1.7
1369         default-language: Haskell2010
1371 .. code-block:: haskell
1372     :caption: bench-foo.hs
1374     {-# LANGUAGE BangPatterns #-}
1375     module Main where
1377     import Data.Time.Clock
1379     fib 0 = 1
1380     fib 1 = 1
1381     fib n = fib (n-1) + fib (n-2)
1383     main = do
1384         start <- getCurrentTime
1385         let !r = fib 20
1386         end <- getCurrentTime
1387         putStrLn $ "fib 20 took " ++ show (diffUTCTime end start)
1389 Running benchmarks
1390 """"""""""""""""""
1392 You can have Cabal run your benchmark using its built-in benchmark
1393 runner:
1397     $ cabal configure --enable-benchmarks
1398     $ cabal build
1399     $ cabal bench
1401 See the output of ``cabal help bench`` for a list of options you can
1402 pass to ``cabal bench``.
1404 Foreign libraries
1405 ^^^^^^^^^^^^^^^^^
1407 Foreign libraries are system libraries intended to be linked against
1408 programs written in C or other "foreign" languages. They
1409 come in two primary flavours: dynamic libraries (``.so`` files on Linux,
1410 ``.dylib`` files on OSX, ``.dll`` files on Windows, etc.) are linked against
1411 executables when the executable is run (or even lazily during
1412 execution), while static libraries (``.a`` files on Linux/OSX, ``.lib``
1413 files on Windows) get linked against the executable at compile time.
1415 Foreign libraries only work with GHC 7.8 and later.
1417 A typical stanza for a foreign library looks like
1421     foreign-library myforeignlib
1422       type:                native-shared
1423       lib-version-info:    6:3:2
1425       if os(Windows)
1426         options: standalone
1427         mod-def-file: MyForeignLib.def
1429       other-modules:       MyForeignLib.SomeModule
1430                            MyForeignLib.SomeOtherModule
1431       build-depends:       base >=4.7 && <4.9
1432       hs-source-dirs:      src
1433       c-sources:           csrc/MyForeignLibWrapper.c
1434       default-language:    Haskell2010
1437 .. pkg-section:: foreign-library name
1438     :since: 2.0
1439     :synopsis: Foreign library build information.
1441     Build information for `foreign libraries`_.
1443 .. pkg-field:: type: foreign library type
1445    Cabal recognizes ``native-static`` and ``native-shared`` here, although
1446    we currently only support building `native-shared` libraries.
1448 .. pkg-field:: options: foreign library option list
1450    Options for building the foreign library, typically specific to the
1451    specified type of foreign library. Currently we only support
1452    ``standalone`` here. A standalone dynamic library is one that does not
1453    have any dependencies on other (Haskell) shared libraries; without
1454    the ``standalone`` option the generated library would have dependencies
1455    on the Haskell runtime library (``libHSrts``), the base library
1456    (``libHSbase``), etc. Currently, ``standalone`` *must* be used on Windows
1457    and *must not* be used on any other platform.
1459 .. pkg-field:: mod-def-file: filename
1461    This option can only be used when creating dynamic Windows libraries
1462    (that is, when using ``native-shared`` and the ``os`` is ``Windows``). If
1463    used, it must be a path to a *module definition file*. The details of
1464    module definition files are beyond the scope of this document; see the
1465    `GHC <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/win32-dlls.html>`_
1466    manual for some details and some further pointers.
1468 .. pkg-field:: lib-version-info: current:revision:age
1470    This field is currently only used on Linux.
1472    This field specifies a Libtool-style version-info field that sets
1473    an appropriate ABI version for the foreign library. Note that the
1474    three numbers specified in this field do not directly specify the
1475    actual ABI version: ``6:3:2`` results in library version ``4.2.3``.
1477    With this field set, the SONAME of the library is set, and symlinks
1478    are installed.
1480    How you should bump this field on an ABI change depends on the
1481    breakage you introduce:
1483    -  Programs using the previous version may use the new version as
1484       drop-in replacement, and programs using the new version can also
1485       work with the previous one. In other words, no recompiling nor
1486       relinking is needed. In this case, bump ``revision`` only, don't
1487       touch current nor age.
1488    -  Programs using the previous version may use the new version as
1489       drop-in replacement, but programs using the new version may use
1490       APIs not present in the previous one. In other words, a program
1491       linking against the new version may fail with "unresolved
1492       symbols" if linking against the old version at runtime: set
1493       revision to 0, bump current and age.
1494    -  Programs may need to be changed, recompiled, and relinked in
1495       order to use the new version. Bump current, set revision and age
1496       to 0.
1498    Also refer to the Libtool documentation on the version-info field.
1500 .. pkg-field:: lib-version-linux: version
1502    This field is only used on Linux.
1504    Specifies the library ABI version directly for foreign libraries
1505    built on Linux: so specifying ``4.2.3`` causes a library
1506    ``libfoo.so.4.2.3`` to be built with SONAME ``libfoo.so.4``, and
1507    appropriate symlinks ``libfoo.so.4`` and ``libfoo.so`` to be
1508    installed.
1510 Note that typically foreign libraries should export a way to initialize
1511 and shutdown the Haskell runtime. In the example above, this is done by
1512 the ``csrc/MyForeignLibWrapper.c`` file, which might look something like
1514 .. code-block:: c
1516     #include <stdlib.h>
1517     #include "HsFFI.h"
1519     HsBool myForeignLibInit(void){
1520       int argc = 2;
1521       char *argv[] = { "+RTS", "-A32m", NULL };
1522       char **pargv = argv;
1524       // Initialize Haskell runtime
1525       hs_init(&argc, &pargv);
1527       // do any other initialization here and
1528       // return false if there was a problem
1529       return HS_BOOL_TRUE;
1530     }
1532     void myForeignLibExit(void){
1533       hs_exit();
1534     }
1536 With modern ghc regular libraries are installed in directories that contain
1537 package keys. This isn't usually a problem because the package gets registered
1538 in ghc's package DB and so we can figure out what the location of the library
1539 is. Foreign libraries however don't get registered, which means that we'd have
1540 to have a way of finding out where a platform library got installed (other than by
1541 searching the ``lib/`` directory). Instead, we install foreign libraries in
1542 ``~/.cabal/lib``, much like we install executables in ``~/.cabal/bin``.
1544 Build information
1545 ^^^^^^^^^^^^^^^^^
1546 .. pkg-section:: None
1548 The following fields may be optionally present in a library, executable,
1549 test suite or benchmark section, and give information for the building
1550 of the corresponding library or executable. See also the sections on
1551 `system-dependent parameters`_ and `configurations`_ for a way to supply
1552 system-dependent values for these fields.
1554 .. pkg-field:: build-depends: library list
1556     Declares the *library* dependencies required to build the current
1557     package component; see :pkg-field:`build-tool-depends` for
1558     declaring build-time *tool* dependencies. External library
1559     dependencies should be annotated with a version constraint.
1561     **Library Names**
1563     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).
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.
1575     **Version Constraints**
1577     Version constraints use the operators ``==, >=, >, <, <=`` and a
1578     version number. Multiple constraints can be combined using ``&&`` or
1579     ``||``. If no version constraint is specified, any version is
1580     assumed to be acceptable. For example:
1582     ::
1584         library
1585           build-depends:
1586             base >= 2,
1587             foo >= 1.2.3 && < 1.3,
1588             bar
1590     Dependencies like ``foo >= 1.2.3 && < 1.3`` turn out to be very
1591     common because it is recommended practice for package versions to
1592     correspond to API versions (see PVP_).
1594     Since Cabal 1.6, there is a special wildcard syntax to help with
1595     such ranges
1597     ::
1599         build-depends: foo ==1.2.*
1601     It is only syntactic sugar. It is exactly equivalent to
1602     ``foo >= 1.2 && < 1.3``.
1604     .. Warning::
1606        A potential pitfall of the wildcard syntax is that the
1607        constraint ``nats == 1.0.*`` doesn't match the release
1608        ``nats-1`` because the version ``1`` is lexicographically less
1609        than ``1.0``. This is not an issue with the caret-operator
1610        ``^>=`` described below.
1612     Starting with Cabal 2.0, there's a new version operator to express
1613     PVP_-style major upper bounds conveniently, and is inspired by similar
1614     syntactic sugar found in other language ecosystems where it's often
1615     called the "Caret" operator:
1617     ::
1619         build-depends:
1620           foo ^>= 1.2.3.4,
1621           bar ^>= 1
1623     This allows to assert the positive knowledge that this package is
1624     *known* to be semantically compatible with the releases
1625     ``foo-1.2.3.4`` and ``bar-1`` respectively. The information
1626     encoded via such ``^>=``-assertions is used by the cabal solver to
1627     infer version constraints describing semantically compatible
1628     version ranges according to the PVP_ contract (see below).
1630     Another way to say this is that ``foo < 1.3`` expresses *negative*
1631     information, i.e. "``foo-1.3`` or ``foo-1.4.2`` will *not* be
1632     compatible"; whereas ``foo ^>= 1.2.3.4`` asserts the *positive*
1633     information that "``foo-1.2.3.4`` is *known* to be compatible" and (in
1634     the absence of additional information) according to the PVP_
1635     contract we can (positively) infer right away that all versions
1636     satisfying ``foo >= 1.2.3.4 && < 1.3`` will be compatible as well.
1638     .. Note::
1640        More generally, the PVP_ contract implies that we can safely
1641        relax the lower bound to ``>= 1.2``, because if we know that
1642        ``foo-1.2.3.4`` is semantically compatible, then so is
1643        ``foo-1.2`` (if it typechecks). But we'd need to perform
1644        additional static analysis (i.e. perform typechecking) in order
1645        to know if our package in the role of an API consumer will
1646        successfully typecheck against the dependency ``foo-1.2``.  But
1647        since we cannot do this analysis during constraint solving and
1648        to keep things simple, we pragmatically use ``foo >= 1.2.3.4``
1649        as the initially inferred approximation for the lower bound
1650        resulting from the assertion ``foo ^>= 1.2.3.4``. If further
1651        evidence becomes available that e.g. ``foo-1.2`` typechecks,
1652        one can simply revise the dependency specification to include
1653        the assertion ``foo ^>= 1.2``.
1655     The subtle but important difference in signaling allows tooling to
1656     treat explicitly expressed ``<``-style constraints and inferred
1657     (``^>=``-style) upper bounds differently.  For instance,
1658     :cfg-field:`allow-newer`'s ``^``-modifier allows to relax only
1659     ``^>=``-style bounds while leaving explicitly stated
1660     ``<``-constraints unaffected.
1662     Ignoring the signaling intent, the default syntactic desugaring rules are
1664     - ``^>= x`` == ``>= x && < x.1``
1665     - ``^>= x.y`` == ``>= x.y && < x.(y+1)``
1666     - ``^>= x.y.z`` == ``>= x.y.z && < x.(y+1)``
1667     - ``^>= x.y.z.u`` == ``>= x.y.z.u && < x.(y+1)``
1668     - etc.
1670     .. Note::
1672        One might expect the desugaring to truncate all version
1673        components below (and including) the patch-level, i.e.
1674        ``^>= x.y.z.u`` == ``>= x.y.z && < x.(y+1)``,
1675        as the major and minor version components alone are supposed to
1676        uniquely identify the API according to the PVP_.  However, by
1677        designing ``^>=`` to be closer to the ``>=`` operator, we avoid
1678        the potentially confusing effect of ``^>=`` being more liberal
1679        than ``>=`` in the presence of patch-level versions.
1681     Consequently, the example declaration above is equivalent to
1683     ::
1685         build-depends:
1686           foo >= 1.2.3.4 && < 1.3,
1687           bar >= 1 && < 1.1
1689     .. Note::
1691        Prior to Cabal 1.8, ``build-depends`` specified in each
1692        section were global to all sections. This was unintentional, but
1693        some packages were written to depend on it, so if you need your
1694        :pkg-field:`build-depends` to be local to each section, you must specify
1695        at least ``Cabal-Version: >= 1.8`` in your ``.cabal`` file.
1697     .. Note::
1699        Cabal 1.20 experimentally supported module thinning and
1700        renaming in ``build-depends``; however, this support has since been
1701        removed and should not be used.
1703     Starting with Cabal 3.0, a set notation for the ``==`` and ``^>=`` operator
1704     is available. For instance,
1706     ::
1708         tested-with: GHC == 8.6.3, GHC == 8.4.4, GHC == 8.2.2, GHC == 8.0.2,
1709                      GHC == 7.10.3, GHC == 7.8.4, GHC == 7.6.3, GHC == 7.4.2
1711         build-depends: network ^>= 2.6.3.6 || ^>= 2.7.0.2 || ^>= 2.8.0.0 || ^>= 3.0.1.0
1713     can be then written in a more convenient and concise form
1715     ::
1717         tested-with: GHC == { 8.6.3, 8.4.4, 8.2.2, 8.0.2, 7.10.3, 7.8.4, 7.6.3, 7.4.2 }
1719         build-depends: network ^>= { 2.6.3.6, 2.7.0.2, 2.8.0.0, 3.0.1.0 }
1722 .. pkg-field:: other-modules: identifier list
1724     A list of modules used by the component but not exposed to users.
1725     For a library component, these would be hidden modules of the
1726     library. For an executable, these would be auxiliary modules to be
1727     linked with the file named in the ``main-is`` field.
1729     .. Note::
1731        Every module in the package *must* be listed in one of
1732        :pkg-field:`other-modules`, :pkg-field:`library:exposed-modules` or
1733        :pkg-field:`executable:main-is` fields.
1735 .. pkg-field:: hs-source-dir: directory list
1736     :deprecated: 2.0
1737     :removed: 3.0
1739     :default: ``.``
1741     Root directories for the module hierarchy.
1743     Deprecated in favor of :pkg-field:`hs-source-dirs`.
1745 .. pkg-field:: hs-source-dirs: directory list
1747     :default: ``.``
1749     Root directories for the module hierarchy.
1751     .. note::
1753       Components can share source directories but modules found there will be
1754       recompiled even if other components already built them, i.e., if a
1755       library and an executable share a source directory and the executable
1756       depends on the library and imports its ``Foo`` module, ``Foo`` will be
1757       compiled twice, once as part of the library and again for the executable.
1759 .. pkg-field:: default-extensions: identifier list
1760    :since: 1.12
1762     A list of Haskell extensions used by every module. These determine
1763     corresponding compiler options enabled for all files. Extension
1764     names are the constructors of the
1765     `Extension <https://hackage.haskell.org/package/Cabal/docs/Language-Haskell-Extension.html#t:Extension>`__
1766     type. For example, ``CPP`` specifies that Haskell source files are
1767     to be preprocessed with a C preprocessor.
1769 .. pkg-field:: other-extensions: identifier list
1770    :since: 1.12
1772     A list of Haskell extensions used by some (but not necessarily all)
1773     modules. From GHC version 6.6 onward, these may be specified by
1774     placing a ``LANGUAGE`` pragma in the source files affected e.g.
1776     .. code-block:: haskell
1778         {-# LANGUAGE CPP, MultiParamTypeClasses #-}
1780     In Cabal-1.24 the dependency solver will use this and
1781     :pkg-field:`default-extensions` information. Cabal prior to 1.24 will abort
1782     compilation if the current compiler doesn't provide the extensions.
1784     If you use some extensions conditionally, using CPP or conditional
1785     module lists, it is good to replicate the condition in
1786     :pkg-field:`other-extensions` declarations:
1788     ::
1790         other-extensions: CPP
1791         if impl(ghc >= 7.5)
1792           other-extensions: PolyKinds
1794     You could also omit the conditionally used extensions, as they are
1795     for information only, but it is recommended to replicate them in
1796     :pkg-field:`other-extensions` declarations.
1798 .. pkg-field:: default-language: identifier
1799    :since: 1.12
1801    TBW
1803 .. pkg-field:: other-languages: identifier
1804    :since: 1.12
1806    TBW
1808 .. pkg-field:: extensions: identifier list
1809    :deprecated: 1.12
1810    :removed: 3.0
1812    Deprecated in favor of :pkg-field:`default-extensions`.
1814 .. pkg-field:: build-tool-depends: package:executable list
1815     :since: 2.0
1817     A list of Haskell executables needed to build this component. Executables are provided
1818     during the whole duration of the component, so this field can be used for executables
1819     needed during :pkg-section:`test-suite` as well.
1821     Each is specified by the package containing the executable and the name of the
1822     executable itself, separated by a colon, and optionally followed by a version bound.
1824     All executables defined in the given Cabal file are termed as *internal* dependencies
1825     as opposed to the rest which are *external* dependencies.
1827     Each of the two is handled differently:
1829     1. External dependencies can (and should) contain a version bound like conventional
1830        :pkg-field:`build-depends` dependencies.
1831     2. Internal dependencies should not contain a version bound, as they will be always
1832        resolved within the same configuration of the package in the build plan.
1833        Specifically, version bounds that include the package's version will be warned for
1834        being extraneous, and version bounds that exclude the package's version will raise
1835        an error for being impossible to follow.
1837     For example (1) using a test-suite to make sure README.md Haskell snippets are tested using
1838     `markdown-unlit <http://hackage.haskell.org/package/markdown-unlit>`__:
1840     ::
1842         build-tool-depends: markdown-unlit:markdown-unlit >= 0.5.0 && < 0.6
1844     For example (2) using a test-suite to test executable behaviour in the same package:
1846     ::
1848         build-tool-depends: mypackage:executable
1850     Cabal tries to make sure that all specified programs are atomically built and prepended
1851     on the ``PATH`` shell variable before building the component in question, but can only do
1852     so for Nix-style builds. Specifically:
1854     a) For Nix-style local builds, both internal and external dependencies.
1855     b) For old-style builds, only for internal dependencies [#old-style-build-tool-depends]_.
1856        It's up to the user to provide needed executables in this case under ``PATH``.
1859     .. note::
1861       :pkg-field:`build-tool-depends` was added in Cabal 2.0, and it will
1862       be ignored (with a warning) with old versions of Cabal.  See
1863       :pkg-field:`build-tools` for more information about backwards
1864       compatibility.
1866 .. pkg-field:: build-tools: program list
1867     :deprecated: 2.0
1868     :removed: 3.0
1870     Deprecated in favor of :pkg-field:`build-tool-depends`, but :ref:`see below for backwards compatibility information <buildtoolsbc>`.
1872     A list of Haskell programs needed to build this component.
1873     Each may be followed by an optional version bound.
1874     Confusingly, each program in the list either refer to one of three things:
1876       1. Another executables in the same package (supported since Cabal 1.12)
1878       2. Tool name contained in Cabal's :ref:`hard-coded set of common tools <buildtoolsmap>`
1880       3. A pre-built executable that should already be on the ``PATH``
1881          (supported since Cabal 2.0)
1883     These cases are listed in order of priority:
1884     an executable in the package will override any of the hard-coded packages with the same name,
1885     and a hard-coded package will override any executable on the ``PATH``.
1887     In the first two cases, the list entry is desugared into a :pkg-field:`build-tool-depends` entry.
1888     In the first case, the entry is desugared into a :pkg-field:`build-tool-depends` entry by prefixing with ``$pkg:``.
1889     In the second case, it is desugared by looking up the package and executable name in a hard-coded table.
1890     In either case, the optional version bound is passed through unchanged.
1891     Refer to the documentation for :pkg-field:`build-tool-depends` to understand the desugared field's meaning, along with restrictions on version bounds.
1893     .. _buildtoolsbc:
1895     **Backward Compatibility**
1897     Although this field is deprecated in favor of :pkg-field:`build-tool-depends`, there are some situations where you may prefer to use :pkg-field:`build-tools` in cases (1) and (2), as it is supported by more versions of Cabal.
1898     In case (3), :pkg-field:`build-tool-depends` is better for backwards-compatibility, as it will be ignored by old versions of Cabal; if you add the executable to :pkg-field:`build-tools`, a setup script built against old Cabal will choke.
1899     If an old version of Cabal is used, an end-user will have to manually arrange for the requested executable to be in your ``PATH``.
1901     .. _buildtoolsmap:
1903     **Set of Known Tool Names**
1905     Identifiers specified in :pkg-field:`build-tools` are desugared into their respective equivalent :pkg-field:`build-tool-depends` form according to the table below. Consequently, a legacy specification such as::
1907         build-tools: alex >= 3.2.1 && < 3.3, happy >= 1.19.5 && < 1.20
1909     is simply desugared into the equivalent specification::
1911         build-tool-depends: alex:alex >= 3.2.1 && < 3.3, happy:happy >= 1.19.5 && < 1.20
1913     +--------------------------+-----------------------------------+-----------------+
1914     | :pkg-field:`build-tools` | desugared                         | Note            |
1915     | identifier               | :pkg-field:`build-tool-depends`   |                 |
1916     |                          | identifier                        |                 |
1917     +==========================+===================================+=================+
1918     | ``alex``                 | ``alex:alex``                     |                 |
1919     +--------------------------+-----------------------------------+-----------------+
1920     | ``c2hs``                 | ``c2hs:c2hs``                     |                 |
1921     +--------------------------+-----------------------------------+-----------------+
1922     | ``cpphs``                | ``cpphs:cpphs``                   |                 |
1923     +--------------------------+-----------------------------------+-----------------+
1924     | ``greencard``            | ``greencard:greencard``           |                 |
1925     +--------------------------+-----------------------------------+-----------------+
1926     | ``haddock``              | ``haddock:haddock``               |                 |
1927     +--------------------------+-----------------------------------+-----------------+
1928     | ``happy``                | ``happy:happy``                   |                 |
1929     +--------------------------+-----------------------------------+-----------------+
1930     | ``hsc2hs``               | ``hsc2hs:hsc2hs``                 |                 |
1931     +--------------------------+-----------------------------------+-----------------+
1932     | ``hscolour``             | ``hscolour:hscolour``             |                 |
1933     +--------------------------+-----------------------------------+-----------------+
1934     | ``hspec-discover``       | ``hspec-discover:hspec-discover`` | since Cabal 2.0 |
1935     +--------------------------+-----------------------------------+-----------------+
1937     This built-in set can be programmatically extended via ``Custom`` setup scripts; this, however, is of limited use since the Cabal solver cannot access information injected by ``Custom`` setup scripts.
1939 .. pkg-field:: buildable: boolean
1941     :default: ``True``
1943     Is the component buildable? Like some of the other fields below,
1944     this field is more useful with the slightly more elaborate form of
1945     the simple build infrastructure described in the section on
1946     `system-dependent parameters`_.
1948 .. pkg-field:: ghc-options: token list
1950     Additional options for GHC. You can often achieve the same effect
1951     using the :pkg-field:`default-extensions` field, which is preferred.
1953     Options required only by one module may be specified by placing an
1954     ``OPTIONS_GHC`` pragma in the source file affected.
1956     As with many other fields, whitespace can be escaped by using
1957     Haskell string syntax. Example:
1958     ``ghc-options: -Wcompat "-with-rtsopts=-T -I1" -Wall``.
1960 .. pkg-field:: ghc-prof-options: token list
1962     Additional options for GHC when the package is built with profiling
1963     enabled.
1965     Note that as of Cabal-1.24, the default profiling detail level
1966     defaults to ``exported-functions`` for libraries and
1967     ``toplevel-functions`` for executables. For GHC these correspond to
1968     the flags ``-fprof-auto-exported`` and ``-fprof-auto-top``. Prior to
1969     Cabal-1.24 the level defaulted to ``none``. These levels can be
1970     adjusted by the person building the package with the
1971     ``--profiling-detail`` and ``--library-profiling-detail`` flags.
1973     It is typically better for the person building the package to pick
1974     the profiling detail level rather than for the package author. So
1975     unless you have special needs it is probably better not to specify
1976     any of the GHC ``-fprof-auto*`` flags here. However if you wish to
1977     override the profiling detail level, you can do so using the
1978     :pkg-field:`ghc-prof-options` field: use ``-fno-prof-auto`` or one of the
1979     other ``-fprof-auto*`` flags.
1981 .. pkg-field:: ghc-shared-options: token list
1983     Additional options for GHC when the package is built as shared
1984     library. The options specified via this field are combined with the
1985     ones specified via :pkg-field:`ghc-options`, and are passed to GHC during
1986     both the compile and link phases.
1988 .. pkg-field:: ghcjs-options: token list
1990    Like :pkg-field:`ghc-options` but applies to GHCJS
1992 .. pkg-field:: ghcjs-prof-options: token list
1994    Like :pkg-field:`ghc-prof-options` but applies to GHCJS
1996 .. pkg-field:: ghcjs-shared-options: token list
1998    Like :pkg-field:`ghc-shared-options` but applies to GHCJS
2000 .. pkg-field:: includes: filename list
2002     A list of header files to be included in any compilations via C.
2003     This field applies to both header files that are already installed
2004     on the system and to those coming with the package to be installed.
2005     The former files should be found in absolute paths, while the latter
2006     files should be found in paths relative to the top of the source
2007     tree or relative to one of the directories listed in
2008     :pkg-field:`include-dirs`.
2010     These files typically contain function prototypes for foreign
2011     imports used by the package. This is in contrast to
2012     :pkg-field:`install-includes`, which lists header files that are intended
2013     to be exposed to other packages that transitively depend on this
2014     library.
2016 .. pkg-field:: install-includes: filename list
2018     A list of header files from this package to be installed into
2019     ``$libdir/includes`` when the package is installed. Files listed in
2020     :pkg-field:`install-includes` should be found in relative to the top of the
2021     source tree or relative to one of the directories listed in
2022     :pkg-field:`include-dirs`.
2024     :pkg-field:`install-includes` is typically used to name header files that
2025     contain prototypes for foreign imports used in Haskell code in this
2026     package, for which the C implementations are also provided with the
2027     package. For example, here is a ``.cabal`` file for a hypothetical
2028     ``bindings-clib`` package that bundles the C source code for ``clib``::
2030         include-dirs:     cbits
2031         c-sources:        clib.c
2032         install-includes: clib.h
2034     Now any package that depends (directly or transitively) on the
2035     ``bindings-clib`` library can use ``clib.h``.
2037     Note that in order for files listed in :pkg-field:`install-includes` to be
2038     usable when compiling the package itself, they need to be listed in
2039     the :pkg-field:`includes` field as well.
2041 .. pkg-field:: include-dirs: directory list
2043     A list of directories to search for header files, when preprocessing
2044     with ``c2hs``, ``hsc2hs``, ``cpphs`` or the C preprocessor, and also
2045     when compiling via C. Directories can be absolute paths (e.g., for
2046     system directories) or paths that are relative to the top of the
2047     source tree. Cabal looks in these directories when attempting to
2048     locate files listed in :pkg-field:`includes` and
2049     :pkg-field:`install-includes`.
2051 .. pkg-field:: c-sources: filename list
2053     A list of C source files to be compiled and linked with the Haskell
2054     files.
2056 .. pkg-field:: cxx-sources: filename list
2057     :since: 2.2
2059     A list of C++ source files to be compiled and linked with the Haskell
2060     files. Useful for segregating C and C++ sources when supplying different
2061     command-line arguments to the compiler via the :pkg-field:`cc-options`
2062     and the :pkg-field:`cxx-options` fields. The files listed in the
2063     :pkg-field:`cxx-sources` can reference files listed in the
2064     :pkg-field:`c-sources` field and vice-versa. The object files will be linked
2065     appropriately.
2067 .. pkg-field:: asm-sources: filename list
2068     :since: 3.0
2070     A list of assembly source files to be compiled and linked with the
2071     Haskell files.
2073 .. pkg-field:: cmm-sources: filename list
2074     :since: 3.0
2076     A list of C-- source files to be compiled and linked with the Haskell
2077     files.
2079 .. pkg-field:: js-sources: filename list
2081     A list of JavaScript source files to be linked with the Haskell
2082     files (only for JavaScript targets).
2084 .. pkg-field:: extra-libraries: token list
2086     A list of extra libraries to link with (when not linking fully static
2087     executables).
2089 .. pkg-field:: extra-libraries-static: token list
2091     A list of extra libraries to link with (when linking fully static
2092     executables).
2094 .. pkg-field:: extra-ghci-libraries: token list
2096     A list of extra libraries to be used instead of 'extra-libraries'
2097     when the package is loaded with GHCi.
2099 .. pkg-field:: extra-bundled-libraries: token list
2100    :since: 2.2
2102    A list of libraries that are supposed to be copied from the build
2103    directory alongside the produced Haskell libraries.  Note that you
2104    are under the obligation to produce those libraries in the build
2105    directory (e.g. via a custom setup).  Libraries listed here will
2106    be included when ``copy``-ing packages and be listed in the
2107    ``hs-libraries`` of the package configuration in the package database.
2108    Library names must either be prefixed with "HS" or "C" and corresponding
2109    library file names must match:
2111       - Libraries with name "HS<library-name>":
2112          - `libHS<library-name>.a`
2113          - `libHS<library-name>-ghc<ghc-flavour><ghc-version>.<dyn-library-extension>*`
2114       - Libraries with name "C<library-name>":
2115          - `libC<library-name>.a`
2116          - `lib<library-name>.<dyn-library-extension>*`
2118 .. pkg-field:: extra-lib-dirs: directory list
2120     A list of directories to search for libraries (when not linking fully static
2121     executables).
2123 .. pkg-field:: extra-lib-dirs-static: directory list
2125     A list of directories to search for libraries (when linking fully static
2126     executables).
2128 .. pkg-field:: extra-library-flavours: notsure
2130     TBW
2132 .. pkg-field:: extra-dynamic-library-flavours: notsure
2134     TBW
2136 .. pkg-field:: cc-options: token list
2138     Command-line arguments to be passed to the C compiler. Since the
2139     arguments are compiler-dependent, this field is more useful with the
2140     setup described in the section on `system-dependent parameters`_.
2142 .. pkg-field:: cpp-options: token list
2144     Command-line arguments for pre-processing Haskell code. Applies to
2145     Haskell source and other pre-processed Haskell source like .hsc
2146     .chs. Does not apply to C code, that's what cc-options is for.
2148 .. pkg-field:: cxx-options: token list
2149     :since: 2.2
2151     Command-line arguments to be passed to the compiler when compiling
2152     C++ code. The C++ sources to which these command-line arguments
2153     should be applied can be specified with the :pkg-field:`cxx-sources`
2154     field. Command-line options for C and C++ can be passed separately to
2155     the compiler when compiling both C and C++ sources by segregating the C
2156     and C++ sources with the :pkg-field:`c-sources` and
2157     :pkg-field:`cxx-sources` fields respectively, and providing different
2158     command-line arguments with the :pkg-field:`cc-options` and the
2159     :pkg-field:`cxx-options` fields.
2161 .. pkg-field:: cmm-options: token list
2162     :since: 3.0
2164     Command-line arguments to be passed to the compiler when compiling
2165     C-- code. See also :pkg-field:`cmm-sources`.
2167 .. pkg-field:: asm-options: token list
2168     :since: 3.0
2170     Command-line arguments to be passed to the assembler when compiling
2171     assembler code. See also :pkg-field:`asm-sources`.
2173 .. pkg-field:: ld-options: token list
2175     Command-line arguments to be passed to the linker. Since the
2176     arguments are compiler-dependent, this field is more useful with the
2177     setup described in the section on `system-dependent parameters`_.
2179 .. pkg-field:: hsc2hs-options: token list
2180     :since: 3.6
2182     Command-line arguments to be passed to ``hsc2hs``.
2184 .. pkg-field:: pkgconfig-depends: package list
2186     A list of
2187     `pkg-config <http://www.freedesktop.org/wiki/Software/pkg-config/>`__
2188     packages, needed to build this package. They can be annotated with
2189     versions, e.g. ``gtk+-2.0 >= 2.10, cairo >= 1.0``. If no version
2190     constraint is specified, any version is assumed to be acceptable.
2191     Cabal uses ``pkg-config`` to find if the packages are available on
2192     the system and to find the extra compilation and linker options
2193     needed to use the packages.
2195     If you need to bind to a C library that supports ``pkg-config`` then
2196     it is much preferable to use this field rather than hard code options
2197     into the other fields. ``pkg-config --list-all`` will show you all
2198     supported libraries. Depending on your system you may need to adjust
2199     ``PKG_CONFIG_PATH``.
2201 .. pkg-field:: frameworks: token list
2203     On Darwin/MacOS X, a list of frameworks to link to. See Apple's
2204     developer documentation for more details on frameworks. This entry
2205     is ignored on all other platforms.
2207 .. pkg-field:: extra-framework-dirs: directory list
2208     :since: 1.24
2210     On Darwin/MacOS X, a list of directories to search for frameworks.
2211     This entry is ignored on all other platforms.
2213 .. pkg-field:: mixins: mixin list
2214     :since: 2.0
2216     Supported only in GHC 8.2 and later. A list of packages mentioned in the
2217     :pkg-field:`build-depends` field, each optionally accompanied by a list of
2218     module and module signature renamings.  A valid mixin obeys the
2219     following syntax:
2221     ::
2223         Mixin ::= PackageName IncludeRenaming
2224         IncludeRenaming ::= ModuleRenaming { "requires" ModuleRenaming }
2225         ModuleRenaming ::=
2226             {- empty -}
2227           | "(" Renaming "," ... "," Renaming ")"
2228           | "hiding" "(" ModuleName "," ... "," ModuleName ")"
2229         Renaming ::=
2230             ModuleName
2231           | ModuleName "as" ModuleName
2233     The simplest mixin syntax is simply the name of a package mentioned in the
2234     :pkg-field:`build-depends` field. For example:
2236     ::
2238         library
2239           build-depends:
2240             foo ^>= 1.2.3
2241           mixins:
2242             foo
2244     But this doesn't have any effect. More interesting is to use the mixin
2245     entry to rename one or more modules from the package, like this:
2247     ::
2249         library
2250           mixins:
2251             foo (Foo.Bar as AnotherFoo.Bar, Foo.Baz as AnotherFoo.Baz)
2253     Note that renaming a module like this will hide all the modules
2254     that are not explicitly named.
2256     Modules can also be hidden:
2258     ::
2260         library:
2261           mixins:
2262             foo hiding (Foo.Bar)
2264     Hiding modules exposes everything that is not explicitly hidden.
2266     .. Note::
2268        Cabal files with :pkg-field:`cabal-version` < 3.0 suffer from an
2269        infelicity in how the entries of :pkg-field:`mixins` are parsed: an
2270        entry will fail to parse if the provided renaming clause has whitespace
2271        after the opening parenthesis.
2273        See issues :issue:`5150`, :issue:`4864`, and :issue:`5293`.
2275     There can be multiple mixin entries for a given package, in effect creating
2276     multiple copies of the dependency:
2278     ::
2280         library
2281           mixins:
2282             foo (Foo.Bar as AnotherFoo.Bar, Foo.Baz as AnotherFoo.Baz),
2283             foo (Foo.Bar as YetAnotherFoo.Bar)
2285     The ``requires`` clause is used to rename the module signatures required by
2286     a package:
2288     ::
2290         library
2291           mixins:
2292             foo (Foo.Bar as AnotherFoo.Bar) requires (Foo.SomeSig as AnotherFoo.SomeSig)
2294     Signature-only packages don't have any modules, so only the signatures can
2295     be renamed, with the following syntax:
2297     ::
2299         library
2300           mixins:
2301             sigonly requires (SigOnly.SomeSig as AnotherSigOnly.SomeSig)
2303     See the :pkg-field:`library:signatures` field for more details.
2305     Mixin packages are part of the Backpack_ extension to the
2306     Haskell module system.
2308     The matching of the module signatures required by a
2309     :pkg-field:`build-depends` dependency with the implementation modules
2310     present in another dependency is triggered by a coincidence of names. When
2311     the names of the signature and of the implementation are already the same,
2312     the matching is automatic. But when the names don't coincide, or we want to
2313     instantiate a signature in two different ways, adding mixin entries that
2314     perform renamings becomes necessary.
2316     .. Warning::
2318        Backpack_ has the limitation that implementation modules that instantiate
2319        signatures required by a :pkg-field:`build-depends` dependency can't
2320        reside in the same component that has the dependency. They must reside
2321        in a different package dependency, or at least in a separate internal
2322        library.
2324 Configurations
2325 ^^^^^^^^^^^^^^
2327 Library and executable sections may include conditional blocks, which
2328 test for various system parameters and configuration flags. The flags
2329 mechanism is rather generic, but most of the time a flag represents
2330 certain feature, that can be switched on or off by the package user.
2331 Here is an example package description file using configurations:
2333 Example: A package containing a library and executable programs
2334 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2338     Cabal-Version: 3.0
2339     Name: Test1
2340     Version: 0.0.1
2341     License: BSD-3-Clause
2342     Author:  Jane Doe
2343     Synopsis: Test package to test configurations
2344     Category: Example
2345     Build-Type: Simple
2347     Flag Debug
2348       Description: Enable debug support
2349       Default:     False
2350       Manual:      True
2352     Flag WebFrontend
2353       Description: Include API for web frontend.
2354       Default:     False
2355       Manual:      True
2357     Flag NewDirectory
2358       description: Whether to build against @directory >= 1.2@
2359       -- This is an automatic flag which the solver will
2360       -- assign automatically while searching for a solution
2362     Library
2363       Build-Depends:      base >= 4.2 && < 4.9
2364       Exposed-Modules:    Testing.Test1
2365       Default-Extensions: CPP
2366       Default-Language:   Haskell2010
2368       GHC-Options: -Wall
2369       if flag(Debug)
2370         CPP-Options: -DDEBUG
2371         if !os(windows)
2372           CC-Options: "-DDEBUG"
2373         else
2374           CC-Options: "-DNDEBUG"
2376       if flag(WebFrontend)
2377         Build-Depends: cgi >= 0.42 && < 0.44
2378         Other-Modules: Testing.WebStuff
2379         CPP-Options: -DWEBFRONTEND
2381         if flag(NewDirectory)
2382             build-depends: directory >= 1.2 && < 1.4
2383             Build-Depends: time >= 1.0 && < 1.9
2384         else
2385             build-depends: directory == 1.1.*
2386             Build-Depends: old-time >= 1.0 && < 1.2
2388     Executable test1
2389       Main-is:          T1.hs
2390       Other-Modules:    Testing.Test1
2391       Build-Depends:    base >= 4.2 && < 4.9
2392       Default-Language: Haskell2010
2394       if flag(debug)
2395         CC-Options: "-DDEBUG"
2396         CPP-Options: -DDEBUG
2398 Layout
2399 """"""
2401 Flags, conditionals, library and executable sections use layout to
2402 indicate structure. This is very similar to the Haskell layout rule.
2403 Entries in a section have to all be indented to the same level which
2404 must be more than the section header. Tabs are not allowed to be used
2405 for indentation.
2407 As an alternative to using layout you can also use explicit braces
2408 ``{}``. In this case the indentation of entries in a section does not
2409 matter, though different fields within a block must be on different
2410 lines. Here is a bit of the above example again, using braces:
2412 Example: Using explicit braces rather than indentation for layout
2413 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2417     Cabal-Version: 3.0
2418     Name: Test1
2419     Version: 0.0.1
2420     License: BSD-3-Clause
2421     Author:  Jane Doe
2422     Synopsis: Test package to test configurations
2423     Category: Example
2424     Build-Type: Simple
2426     Flag Debug {
2427       Description: Enable debug support
2428       Default:     False
2429       Manual:      True
2430     }
2432     Library {
2433       Build-Depends:       base >= 4.2 && < 4.9
2434       Exposed-Modules:     Testing.Test1
2435       Default-Extensions:  CPP
2436       Default-language:    Haskell2010
2437       if flag(debug) {
2438         CPP-Options: -DDEBUG
2439         if !os(windows) {
2440           CC-Options: "-DDEBUG"
2441         } else {
2442           CC-Options: "-DNDEBUG"
2443         }
2444       }
2445     }
2447 Configuration Flags
2448 """""""""""""""""""
2450 .. pkg-section:: flag name
2451     :synopsis: Flag declaration.
2453     Flag section declares a flag which can be used in `conditional blocks`_.
2455     Flag names are case-insensitive and must match ``[[:alnum:]_][[:alnum:]_-]*``
2456     regular expression, or expressed as ABNF_:
2458     .. code-block:: abnf
2460        flag-name = (UALNUM / "_") *(UALNUM / "_" / "-")
2462        UALNUM = UALPHA / DIGIT
2463        UALPHA = ... ; set of alphabetic Unicode code-points
2465     .. note::
2467         Hackage accepts ASCII-only flags, ``[a-zA-Z0-9_][a-zA-Z0-9_-]*`` regexp.
2469 .. pkg-field:: description: freeform
2471     The description of this flag.
2473 .. pkg-field:: default: boolean
2475     :default: ``True``
2477     The default value of this flag.
2479     .. note::
2481       This value may be :ref:`overridden in several
2482       ways <controlling flag assignments>`. The
2483       rationale for having flags default to True is that users usually
2484       want new features as soon as they are available. Flags representing
2485       features that are not (yet) recommended for most users (such as
2486       experimental features or debugging support) should therefore
2487       explicitly override the default to False.
2489 .. pkg-field:: manual: boolean
2491     :default: ``False``
2492     :since: 1.6
2494     By default, Cabal will first try to satisfy dependencies with the
2495     default flag value and then, if that is not possible, with the
2496     negated value. However, if the flag is manual, then the default
2497     value (which can be overridden by commandline flags) will be used.
2499 Conditional Blocks
2500 ^^^^^^^^^^^^^^^^^^
2502 Conditional blocks may appear anywhere inside a library or executable
2503 section. They have to follow rather strict formatting rules. Conditional
2504 blocks must always be of the shape
2508       if condition
2509          property-descriptions-or-conditionals
2515       if condition
2516            property-descriptions-or-conditionals
2517       else
2518            property-descriptions-or-conditionals
2520 Note that the ``if`` and the condition have to be all on the same line.
2522 Since Cabal 2.2 conditional blocks support ``elif`` construct.
2526       if condition1
2527            property-descriptions-or-conditionals
2528       elif condition2
2529            property-descriptions-or-conditionals
2530       else
2531            property-descriptions-or-conditionals
2533 .. _conditions:
2535 Conditions
2536 """"""""""
2538 Conditions can be formed using boolean tests and the boolean operators
2539 ``||`` (disjunction / logical "or"), ``&&`` (conjunction / logical
2540 "and"), or ``!`` (negation / logical "not"). The unary ``!`` takes
2541 highest precedence, ``||`` takes lowest. Precedence levels may be
2542 overridden through the use of parentheses. For example,
2543 ``os(darwin) && !arch(i386) || os(freebsd)`` is equivalent to
2544 ``(os(darwin) && !(arch(i386))) || os(freebsd)``.
2546 The following tests are currently supported.
2548 :samp:`os({name})`
2549     Tests if the current operating system is *name*. The argument is
2550     tested against ``System.Info.os`` on the target system. There is
2551     unfortunately some disagreement between Haskell implementations
2552     about the standard values of ``System.Info.os``. Cabal canonicalises
2553     it so that in particular ``os(windows)`` works on all
2554     implementations. If the canonicalised os names match, this test
2555     evaluates to true, otherwise false. The match is case-insensitive.
2556 :samp:`arch({name})`
2557     Tests if the current architecture is *name*. The argument is matched
2558     against ``System.Info.arch`` on the target system. If the arch names
2559     match, this test evaluates to true, otherwise false. The match is
2560     case-insensitive.
2561 :samp:`impl({compiler})`
2562     Tests for the configured Haskell implementation. An optional version
2563     constraint may be specified (for example ``impl(ghc >= 6.6.1)``). If
2564     the configured implementation is of the right type and matches the
2565     version constraint, then this evaluates to true, otherwise false.
2566     The match is case-insensitive.
2568     Note that including a version constraint in an ``impl`` test causes
2569     it to check for two properties:
2571     -  The current compiler has the specified name, and
2573     -  The compiler's version satisfied the specified version constraint
2575     As a result, ``!impl(ghc >= x.y.z)`` is not entirely equivalent to
2576     ``impl(ghc < x.y.z)``. The test ``!impl(ghc >= x.y.z)`` checks that:
2578     -  The current compiler is not GHC, or
2580     -  The version of GHC is earlier than version x.y.z.
2582 :samp:`flag({name})`
2583     Evaluates to the current assignment of the flag of the given name.
2584     Flag names are case insensitive. Testing for flags that have not
2585     been introduced with a flag section is an error.
2586 ``true``
2587     Constant value true.
2588 ``false``
2589     Constant value false.
2591 .. _resolution-of-conditions-and-flags:
2593 Resolution of Conditions and Flags
2594 """"""""""""""""""""""""""""""""""
2596 If a package descriptions specifies configuration flags the package user
2597 can :ref:`control these in several ways <controlling flag assignments>`. If the
2598 user does not fix the value of a flag, Cabal will try to find a flag
2599 assignment in the following way.
2601 -  For each flag specified, it will assign its default value, evaluate
2602    all conditions with this flag assignment, and check if all
2603    dependencies can be satisfied. If this check succeeded, the package
2604    will be configured with those flag assignments.
2606 -  If dependencies were missing, the last flag (as by the order in which
2607    the flags were introduced in the package description) is tried with
2608    its alternative value and so on. This continues until either an
2609    assignment is found where all dependencies can be satisfied, or all
2610    possible flag assignments have been tried.
2612 To put it another way, Cabal does a complete backtracking search to find
2613 a satisfiable package configuration. It is only the dependencies
2614 specified in the :pkg-field:`build-depends` field in conditional blocks that
2615 determine if a particular flag assignment is satisfiable
2616 (:pkg-field:`build-tools` are not considered). The order of the declaration and
2617 the default value of the flags determines the search order. Flags
2618 overridden on the command line fix the assignment of that flag, so no
2619 backtracking will be tried for that flag.
2621 If no suitable flag assignment could be found, the configuration phase
2622 will fail and a list of missing dependencies will be printed. Note that
2623 this resolution process is exponential in the worst case (i.e., in the
2624 case where dependencies cannot be satisfied). There are some
2625 optimizations applied internally, but the overall complexity remains
2626 unchanged.
2628 Meaning of field values when using conditionals
2629 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2631 During the configuration phase, a flag assignment is chosen, all
2632 conditionals are evaluated, and the package description is combined into
2633 a flat package descriptions. If the same field is declared both inside
2634 a conditional and outside then they are combined using the following rules.
2636 -  Boolean fields are combined using conjunction (logical "and").
2638 -  List fields are combined by appending the inner items to the outer
2639    items, for example
2641    ::
2643        other-extensions: CPP
2644        if impl(ghc)
2645          other-extensions: MultiParamTypeClasses
2647    when compiled using GHC will be combined to
2649    ::
2651        other-extensions: CPP, MultiParamTypeClasses
2653    Similarly, if two conditional sections appear at the same nesting
2654    level, properties specified in the latter will come after properties
2655    specified in the former.
2657 -  All other fields must not be specified in ambiguous ways. For example
2659    ::
2661        Main-is: Main.hs
2662        if flag(useothermain)
2663          Main-is: OtherMain.hs
2665    will lead to an error. Instead use
2667    ::
2669        if flag(useothermain)
2670          Main-is: OtherMain.hs
2671        else
2672          Main-is: Main.hs
2674 .. _common-stanzas:
2676 Common stanzas
2677 ^^^^^^^^^^^^^^
2679 .. pkg-section:: common name
2680     :since: 2.2
2681     :synopsis: Common build info section
2683 Starting with Cabal-2.2 it's possible to use common build info stanzas.
2687       common deps
2688         build-depends: base ^>= 4.11
2689         ghc-options: -Wall
2691       common test-deps
2692         build-depends: tasty ^>= 0.12.0.1
2694       library
2695         import:           deps
2696         exposed-modules:  Foo
2697         default-language: Haskell2010
2699       test-suite tests
2700         import:           deps, test-deps
2701         main-is:          Tests.hs
2702         build-depends:    foo
2703         default-language: Haskell2010
2705 -  You can use `build information`_ fields in common stanzas.
2707 -  Common stanzas must be defined before use.
2709 -  Common stanzas can import other common stanzas.
2711 -  You can import multiple stanzas at once. Stanza names must be separated by commas.
2713 -  ``import`` must be the first field in a section. Since Cabal 3.0 imports
2714    are also allowed inside conditionals.
2716 .. Note::
2718     The name `import` was chosen, because there is ``includes`` field.
2720 .. pkg-section:: None
2722 .. pkg-field:: import: token-list
2724     TBW
2726 Source Repositories
2727 ^^^^^^^^^^^^^^^^^^^
2729 .. pkg-section:: source-repository
2730     :since: 1.6
2732 It is often useful to be able to specify a source revision control
2733 repository for a package. Cabal lets you specify this information in
2734 a relatively structured form which enables other tools to interpret and
2735 make effective use of the information. For example the information
2736 should be sufficient for an automatic tool to checkout the sources.
2738 Cabal supports specifying different information for various common
2739 source control systems. Obviously not all automated tools will support
2740 all source control systems.
2742 Cabal supports specifying repositories for different use cases. By
2743 declaring which case we mean automated tools can be more useful. There
2744 are currently two kinds defined:
2746 -  The ``head`` kind refers to the latest development branch of the
2747    package. This may be used for example to track activity of a project
2748    or as an indication to outside developers what sources to get for
2749    making new contributions.
2751 -  The ``this`` kind refers to the branch and tag of a repository that
2752    contains the sources for this version or release of a package. For
2753    most source control systems this involves specifying a tag, id or
2754    hash of some form and perhaps a branch. The purpose is to be able to
2755    reconstruct the sources corresponding to a particular package
2756    version. This might be used to indicate what sources to get if
2757    someone needs to fix a bug in an older branch that is no longer an
2758    active head branch.
2760 You can specify one kind or the other or both. As an example here are
2761 the repositories for the Cabal library. Note that the ``this`` kind of
2762 repository specifies a tag.
2766     source-repository head
2767       type:     git
2768       location: https://github.com/haskell/cabal
2770     source-repository this
2771       type:     git
2772       location: https://github.com/haskell/cabal
2773       tag:      1.6.1
2775 The exact fields are as follows:
2777 .. pkg-field:: type: token
2779     The name of the source control system used for this repository. The
2780     currently recognised types are:
2782     -  ``darcs``
2783     -  ``git``
2784     -  ``svn``
2785     -  ``cvs``
2786     -  ``mercurial`` (or alias ``hg``)
2787     -  ``bazaar`` (or alias ``bzr``)
2788     -  ``arch``
2789     -  ``monotone``
2791     This field is required.
2793 .. pkg-field:: location: URL
2795     The location of the repository. The exact form of this field depends
2796     on the repository type. For example:
2798     -  for darcs: ``http://code.haskell.org/foo/``
2799     -  for git: ``git://github.com/foo/bar.git``
2800     -  for CVS: ``anoncvs@cvs.foo.org:/cvs``
2802     This field is required.
2804 .. pkg-field:: module: token
2806     CVS requires a named module, as each CVS server can host multiple
2807     named repositories.
2809     This field is required for the CVS repository type and should not be
2810     used otherwise.
2812 .. pkg-field:: branch: token
2814     Many source control systems support the notion of a branch, as a
2815     distinct concept from having repositories in separate locations. For
2816     example CVS, SVN and git use branches while darcs uses different
2817     locations for different branches. If you need to specify a branch to
2818     identify a your repository then specify it in this field.
2820     This field is optional.
2822 .. pkg-field:: tag: token
2824     A tag identifies a particular state of a source repository. The tag
2825     can be used with a ``this`` repository kind to identify the state of
2826     a repository corresponding to a particular package version or
2827     release. The exact form of the tag depends on the repository type.
2829     This field is required for the ``this`` repository kind.
2831 .. pkg-field:: subdir: directory
2833     Some projects put the sources for multiple packages under a single
2834     source repository. This field lets you specify the relative path
2835     from the root of the repository to the top directory for the
2836     package, i.e. the directory containing the package's ``.cabal``
2837     file.
2839     This field is optional. It defaults to empty which corresponds to the
2840     root directory of the repository.
2842 Downloading a package's source
2843 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2845 The ``cabal get`` command allows to access a package's source code -
2846 either by unpacking a tarball downloaded from Hackage (the default) or
2847 by checking out a working copy from the package's source repository.
2851     $ cabal get [FLAGS] PACKAGES
2853 The ``get`` command supports the following options:
2855 ``-d --destdir`` *PATH*
2856     Where to place the package source, defaults to (a subdirectory of)
2857     the current directory.
2858 ``-s --source-repository`` *[head\|this\|...]*
2859     Clone the package's source repository using the appropriate version
2860     control system. The optional argument allows to choose a specific
2861     repository kind.
2862 ``--index-state`` *[HEAD\|@<unix-timestamp>\|<iso8601-utc-timestamp>]*
2863     Use source package index state as it existed at a previous time. Accepts
2864     unix-timestamps (e.g. ``@1474732068``), ISO8601 UTC timestamps (e.g.
2865     ``2016-09-24T17:47:48Z``), or ``HEAD`` (default).
2866     This determines which package versions are available as well as which
2867     ``.cabal`` file revision is selected (unless ``--pristine`` is used).
2868 ``--only-package-description``
2869     Unpack only the package description file. A synonym,
2870     ``--package-description-only``, is provided for convenience.
2871 ``--pristine``
2872     Unpack the original pristine tarball, rather than updating the
2873     ``.cabal`` file with the latest revision from the package archive.
2875 Custom setup scripts
2876 --------------------
2878 Since Cabal 1.24, custom ``Setup.hs`` are required to accurately track
2879 their dependencies by declaring them in the ``.cabal`` file rather than
2880 rely on dependencies being implicitly in scope.  Please refer to
2881 `this article <https://www.well-typed.com/blog/2015/07/cabal-setup-deps/>`__
2882 for more details.
2884 As of Cabal library version 3.0, ``defaultMain*`` variants implement support
2885 for response files. Custom ``Setup.hs`` files that do not use one of these
2886 main functions are required to implement their own support, such as by using
2887 ``GHC.ResponseFile.getArgsWithResponseFiles``.
2889 Declaring a ``custom-setup`` stanza also enables the generation of
2890 ``MIN_VERSION_package_(A,B,C)`` CPP macros for the Setup component.
2892 .. pkg-section:: custom-setup
2893    :synopsis: Custom Setup.hs build information.
2894    :since: 1.24
2896    The optional :pkg-section:`custom-setup` stanza contains information needed
2897    for the compilation of custom ``Setup.hs`` scripts,
2901     custom-setup
2902       setup-depends:
2903         base  >= 4.5 && < 4.11,
2904         Cabal >= 1.14 && < 1.25
2906 .. pkg-field:: setup-depends: package list
2907     :since: 1.24
2909     The dependencies needed to compile ``Setup.hs``. See the
2910     :pkg-field:`build-depends` field for a description of the syntax expected by
2911     this field.
2913     If the field is not specified the implicit package set will be used.
2914     The package set contains packages bundled with GHC (i.e. ``base``,
2915     ``bytestring``) and specifically ``Cabal``.
2916     The specific bounds are put on ``Cabal`` dependency:
2917     lower-bound is inferred from :pkg-field:`cabal-version`,
2918     and the upper-bound is ``< 1.25``.
2920     ``Cabal`` version is additionally restricted by GHC,
2921     with absolute minimum being ``1.20``, and for example ``Custom``
2922     builds with GHC-8.10 require at least ``Cabal-3.2``.
2925 Backward compatibility and ``custom-setup``
2926 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2928 Versions prior to Cabal 1.24 don't recognise ``custom-setup`` stanzas,
2929 and will behave agnostic to them (except for warning about an unknown
2930 section). Consequently, versions prior to Cabal 1.24 can't ensure the
2931 declared dependencies ``setup-depends`` are in scope, and instead
2932 whatever is registered in the current package database environment
2933 will become eligible (and resolved by the compiler) for the
2934 ``Setup.hs`` module.
2936 The availability of the
2937 ``MIN_VERSION_package_(A,B,C)`` CPP macros
2938 inside ``Setup.hs`` scripts depends on the condition that either
2940 - a ``custom-setup`` section has been declared (or ``cabal build`` is being
2941   used which injects an implicit hard-coded ``custom-setup`` stanza if it's missing), or
2942 - GHC 8.0 or later is used (which natively injects package version CPP macros)
2944 Consequently, if you need to write backward compatible ``Setup.hs``
2945 scripts using CPP, you should declare a ``custom-setup`` stanza and
2946 use the pattern below:
2948 .. code-block:: haskell
2950     {-# LANGUAGE CPP #-}
2951     import Distribution.Simple
2953     #if defined(MIN_VERSION_Cabal)
2954     -- version macros are available and can be used as usual
2955     # if MIN_VERSION_Cabal(a,b,c)
2956     -- code specific to lib:Cabal >= a.b.c
2957     # else
2958     -- code specific to lib:Cabal < a.b.c
2959     # endif
2960     #else
2961     # warning Enabling heuristic fall-back. Please upgrade cabal-install to 1.24 or later if Setup.hs fails to compile.
2963     -- package version macros not available; except for exotic environments,
2964     -- you can heuristically assume that lib:Cabal's version is correlated
2965     -- with __GLASGOW_HASKELL__, and specifically since we can assume that
2966     -- GHC < 8.0, we can assume that lib:Cabal is version 1.22 or older.
2967     #endif
2969     main = ...
2971 The simplified (heuristic) CPP pattern shown below is useful if all you need
2972 is to distinguish ``Cabal < 2.0`` from ``Cabal >= 2.0``.
2974 .. code-block:: haskell
2976     {-# LANGUAGE CPP #-}
2977     import Distribution.Simple
2979     #if !defined(MIN_VERSION_Cabal)
2980     # define MIN_VERSION_Cabal(a,b,c) 0
2981     #endif
2983     #if MIN_VERSION_Cabal(2,0,0)
2984     -- code for lib:Cabal >= 2.0
2985     #else
2986     -- code for lib:Cabal < 2.0
2987     #endif
2989     main = ...
2993 Autogenerated modules and includes
2994 ----------------------------------
2996 .. pkg-section:: None
2998 Modules that are built automatically at setup, created with a custom
2999 setup script, must appear on :pkg-field:`other-modules` for the library,
3000 executable, test-suite or benchmark stanzas or also on
3001 :pkg-field:`library:exposed-modules` for libraries to be used, but are not
3002 really on the package when distributed. This makes commands like sdist fail
3003 because the file is not found.
3005 These special modules must appear again on the :pkg-field:`autogen-modules`
3006 field of the stanza that is using them, besides :pkg-field:`other-modules` or
3007 :pkg-field:`library:exposed-modules`. With this there is no need to create
3008 complex build hooks for this poweruser case.
3010 .. pkg-field:: autogen-modules: module list
3011    :since: 2.0
3013    .. todo:: document autogen-modules field
3015 Right now :pkg-field:`executable:main-is` modules are not supported on
3016 :pkg-field:`autogen-modules`.
3020     Library
3021         default-language: Haskell2010
3022         build-depends: base
3023         exposed-modules:
3024             MyLibrary
3025             MyLibHelperModule
3026         other-modules:
3027             MyLibModule
3028         autogen-modules:
3029             MyLibHelperModule
3031     Executable Exe
3032         default-language: Haskell2010
3033         main-is: Dummy.hs
3034         build-depends: base
3035         other-modules:
3036             MyExeModule
3037             MyExeHelperModule
3038         autogen-modules:
3039             MyExeHelperModule
3041 .. pkg-field:: autogen-includes: filename list
3042    :since: 3.0
3044    A list of header files from this package which are autogenerated
3045    (e.g. by a ``configure`` script). Autogenerated header files are not
3046    packaged by ``sdist`` command.
3048 Virtual modules
3049 ---------------
3053 .. pkg-field:: virtual-modules: module list
3054    :since: 2.2
3056    TBW
3059 .. _accessing-data-files:
3061 Accessing data files from package code
3062 --------------------------------------
3064 The placement on the target system of files listed in
3065 the :pkg-field:`data-files` field varies between systems, and in some cases
3066 one can even move packages around after installation
3067 (see :ref:`prefix independence`). To
3068 enable packages to find these files in a portable way, Cabal generates a
3069 module called :file:`Paths_{pkgname}` (with any hyphens in *pkgname*
3070 replaced by underscores) during building, so that it may be imported by
3071 modules of the package. This module defines a function
3073 .. code-block:: haskell
3075     getDataFileName :: FilePath -> IO FilePath
3077 If the argument is a filename listed in the :pkg-field:`data-files` field, the
3078 result is the name of the corresponding file on the system on which the
3079 program is running.
3081 .. Note::
3083    If you decide to import the :file:`Paths_{pkgname}` module then it
3084    *must* be listed in the :pkg-field:`other-modules` field just like any other
3085    module in your package and on :pkg-field:`autogen-modules` as the file is
3086    autogenerated.
3088 The :file:`Paths_{pkgname}` module is not platform independent, as any
3089 other autogenerated module, so it does not get included in the source
3090 tarballs generated by ``sdist``.
3092 The :file:`Paths_{pkgname}` module also includes some other useful
3093 functions and values, which record the version of the package and some
3094 other directories which the package has been configured to be installed
3095 into (e.g. data files live in ``getDataDir``):
3097 .. code-block:: haskell
3099     version :: Version
3101     getBinDir :: IO FilePath
3102     getLibDir :: IO FilePath
3103     getDynLibDir :: IO FilePath
3104     getDataDir :: IO FilePath
3105     getLibexecDir :: IO FilePath
3106     getSysconfDir :: IO FilePath
3108 The actual location of all these directories can be individually
3109 overridden at runtime using environment variables of the form
3110 ``pkg_name_var``, where ``pkg_name`` is the name of the package with all
3111 hyphens converted into underscores, and ``var`` is either ``bindir``,
3112 ``libdir``, ``dynlibdir``, ``datadir``, ``libexedir`` or ``sysconfdir``. For example,
3113 the configured data directory for ``pretty-show`` is controlled with the
3114 ``pretty_show_datadir`` environment variable.
3116 Accessing the package version
3117 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3119 The aforementioned auto generated :file:`Paths_{pkgname}` module also
3120 exports the constant ``version ::``
3121 `Version <http://hackage.haskell.org/package/base/docs/Data-Version.html>`__
3122 which is defined as the version of your package as specified in the
3123 ``version`` field.
3125 .. _system-dependent parameters:
3127 System-dependent parameters
3128 ---------------------------
3130 For some packages, especially those interfacing with C libraries,
3131 implementation details and the build procedure depend on the build
3132 environment. The ``build-type`` ``Configure`` can be used to handle many
3133 such situations. In this case, ``Setup.hs`` should be:
3135 .. code-block:: haskell
3137     import Distribution.Simple
3138     main = defaultMainWithHooks autoconfUserHooks
3140 Most packages, however, would probably do better using the ``Simple``
3141 build type and `configurations`_.
3143 The :pkg-field:`build-type` ``Configure`` differs from ``Simple`` in two ways:
3145 -  The package root directory must contain a shell script called
3146    ``configure``. The configure step will run the script. This
3147    ``configure`` script may be produced by
3148    `autoconf <http://www.gnu.org/software/autoconf/>`__ or may be
3149    hand-written. The ``configure`` script typically discovers
3150    information about the system and records it for later steps, e.g. by
3151    generating system-dependent header files for inclusion in C source
3152    files and preprocessed Haskell source files. (Clearly this won't work
3153    for Windows without MSYS or Cygwin: other ideas are needed.)
3155 -  If the package root directory contains a file called
3156    *package*\ ``.buildinfo`` after the configuration step, subsequent
3157    steps will read it to obtain additional settings for `build
3158    information`_ fields,to be merged with the ones
3159    given in the ``.cabal`` file. In particular, this file may be
3160    generated by the ``configure`` script mentioned above, allowing these
3161    settings to vary depending on the build environment.
3163 The build information file should have the following structure:
3165     *buildinfo*
3167     ``executable:`` *name* *buildinfo*
3169     ``executable:`` *name* *buildinfo* ...
3171 where each *buildinfo* consists of settings of fields listed in the
3172 section on `build information`_. The first one (if
3173 present) relates to the library, while each of the others relate to the
3174 named executable. (The names must match the package description, but you
3175 don't have to have entries for all of them.)
3177 Neither of these files is required. If they are absent, this setup
3178 script is equivalent to ``defaultMain``.
3180 Example: Using autoconf
3181 ^^^^^^^^^^^^^^^^^^^^^^^
3183 This example is for people familiar with the
3184 `autoconf <http://www.gnu.org/software/autoconf/>`__ tools.
3186 In the X11 package, the file ``configure.ac`` contains:
3188 .. code-block:: shell
3190     AC_INIT([Haskell X11 package], [1.1], [libraries@haskell.org], [X11])
3192     # Safety check: Ensure that we are in the correct source directory.
3193     AC_CONFIG_SRCDIR([X11.cabal])
3195     # Header file to place defines in
3196     AC_CONFIG_HEADERS([include/HsX11Config.h])
3198     # Check for X11 include paths and libraries
3199     AC_PATH_XTRA
3200     AC_TRY_CPP([#include <X11/Xlib.h>],,[no_x=yes])
3202     # Build the package if we found X11 stuff
3203     if test "$no_x" = yes
3204     then BUILD_PACKAGE_BOOL=False
3205     else BUILD_PACKAGE_BOOL=True
3206     fi
3207     AC_SUBST([BUILD_PACKAGE_BOOL])
3209     AC_CONFIG_FILES([X11.buildinfo])
3210     AC_OUTPUT
3212 Then the setup script will run the ``configure`` script, which checks
3213 for the presence of the X11 libraries and substitutes for variables in
3214 the file ``X11.buildinfo.in``:
3218     buildable: @BUILD_PACKAGE_BOOL@
3219     cc-options: @X_CFLAGS@
3220     ld-options: @X_LIBS@
3222 This generates a file ``X11.buildinfo`` supplying the parameters needed
3223 by later stages:
3227     buildable: True
3228     cc-options:  -I/usr/X11R6/include
3229     ld-options:  -L/usr/X11R6/lib
3231 The ``configure`` script also generates a header file
3232 ``include/HsX11Config.h`` containing C preprocessor defines recording
3233 the results of various tests. This file may be included by C source
3234 files and preprocessed Haskell source files in the package.
3236 .. Note::
3238    Packages using these features will also need to list additional
3239    files such as ``configure``, templates for ``.buildinfo`` files, files
3240    named only in ``.buildinfo`` files, header files and so on in the
3241    :pkg-field:`extra-source-files` field to ensure that they are included in
3242    source distributions. They should also list files and directories generated
3243    by ``configure`` in the :pkg-field:`extra-tmp-files` field to ensure that
3244    they are removed by ``setup clean``.
3246 Quite often the files generated by ``configure`` need to be listed
3247 somewhere in the package description (for example, in the
3248 :pkg-field:`install-includes` field). However, we usually don't want generated
3249 files to be included in the source tarball. The solution is again
3250 provided by the ``.buildinfo`` file. In the above example, the following
3251 line should be added to ``X11.buildinfo``:
3255     install-includes: HsX11Config.h
3257 In this way, the generated ``HsX11Config.h`` file won't be included in
3258 the source tarball in addition to ``HsX11Config.h.in``, but it will be
3259 copied to the right location during the install process. Packages that
3260 use custom ``Setup.hs`` scripts can update the necessary fields
3261 programmatically instead of using the ``.buildinfo`` file.
3263 Conditional compilation
3264 -----------------------
3266 Sometimes you want to write code that works with more than one version
3267 of a dependency. You can specify a range of versions for the dependency
3268 in the :pkg-field:`build-depends`, but how do you then write the code that can
3269 use different versions of the API?
3271 Haskell lets you preprocess your code using the C preprocessor (either
3272 the real C preprocessor, or ``cpphs``). To enable this, add
3273 ``extensions: CPP`` to your package description. When using CPP, Cabal
3274 provides some pre-defined macros to let you test the version of
3275 dependent packages; for example, suppose your package works with either
3276 version 3 or version 4 of the ``base`` package, you could select the
3277 available version in your Haskell modules like this:
3279 .. code-block:: cpp
3281     #if MIN_VERSION_base(4,0,0)
3282     ... code that works with base-4 ...
3283     #else
3284     ... code that works with base-3 ...
3285     #endif
3287 In general, Cabal supplies a macro
3288 ``MIN_VERSION_``\ *``package``*\ ``_(A,B,C)`` for each package depended
3289 on via :pkg-field:`build-depends`. This macro is true if the actual version of
3290 the package in use is greater than or equal to ``A.B.C`` (using the
3291 conventional ordering on version numbers, which is lexicographic on the
3292 sequence, but numeric on each component, so for example 1.2.0 is greater
3293 than 1.0.3).
3295 Since version 1.20, the ``MIN_TOOL_VERSION_``\ *``tool``*
3296 family of macros lets you condition on the version of build tools used to
3297 build the program (e.g. ``hsc2hs``).
3299 Since version 1.24, the macro ``CURRENT_COMPONENT_ID``, which
3300 expands to the string of the component identifier that uniquely
3301 identifies this component.  Furthermore, if the package is a library,
3302 the macro ``CURRENT_PACKAGE_KEY`` records the identifier that was passed
3303 to GHC for use in symbols and for type equality.
3305 Since version 2.0, the macro ``CURRENT_PACKAGE_VERSION`` expands
3306 to the string version number of the current package.
3308 Cabal places the definitions of these macros into an
3309 automatically-generated header file, which is included when
3310 preprocessing Haskell source code by passing options to the C
3311 preprocessor.
3313 Cabal also allows to detect when the source code is being used for
3314 generating documentation. The ``__HADDOCK_VERSION__`` macro is defined
3315 only when compiling via Haddock_
3316 instead of a normal Haskell compiler. The value of the
3317 ``__HADDOCK_VERSION__`` macro is defined as ``A*1000 + B*10 + C``, where
3318 ``A.B.C`` is the Haddock version. This can be useful for working around
3319 bugs in Haddock or generating prettier documentation in some special
3320 cases.
3322 .. _more-complex-packages:
3324 More complex packages
3325 ---------------------
3327 For packages that don't fit the simple schemes described above, you have
3328 a few options:
3330 -  By using the :pkg-field:`build-type` ``Custom``, you can supply your own
3331    ``Setup.hs`` file, and customize the simple build infrastructure
3332    using *hooks*. These allow you to perform additional actions before
3333    and after each command is run, and also to specify additional
3334    preprocessors. A typical ``Setup.hs`` may look like this:
3336    .. code-block:: haskell
3338        import Distribution.Simple
3339        main = defaultMainWithHooks simpleUserHooks { postHaddock = posthaddock }
3341        posthaddock args flags desc info = ....
3343    See ``UserHooks`` in
3344    `Distribution.Simple <https://hackage.haskell.org/package/Cabal/docs/Distribution-Simple.html>`__
3345    for the details, but note that this interface is experimental, and
3346    likely to change in future releases.
3348    If you use a custom ``Setup.hs`` file you should strongly consider
3349    adding a :pkg-section:`custom-setup` stanza with a
3350    :pkg-field:`custom-setup:setup-depends` field to ensure that your setup
3351    script does not break with future dependency versions.
3353 -  You could delegate all the work to ``make``, though this is unlikely
3354    to be very portable. Cabal supports this with the :pkg-field:`build-type`
3355    ``Make`` and a trivial setup library
3356    `Distribution.Make <https://hackage.haskell.org/package/Cabal/docs/Distribution-Make.html>`__,
3357    which simply parses the command line arguments and invokes ``make``.
3358    Here ``Setup.hs`` should look like this:
3360    .. code-block:: haskell
3362        import Distribution.Make
3363        main = defaultMain
3365    The root directory of the package should contain a ``configure``
3366    script, and, after that has run, a ``Makefile`` with a default target
3367    that builds the package, plus targets ``install``, ``register``,
3368    ``unregister``, ``clean``, ``dist`` and ``docs``. Some options to
3369    commands are passed through as follows:
3371    -  The ``--with-hc-pkg``, ``--prefix``, ``--bindir``, ``--libdir``,
3372       ``--dynlibdir``, ``--datadir``, ``--libexecdir`` and ``--sysconfdir`` options to
3373       the ``configure`` command are passed on to the ``configure``
3374       script. In addition the value of the ``--with-compiler`` option is
3375       passed in a ``--with-hc`` option and all options specified with
3376       ``--configure-option=`` are passed on.
3378    -  The ``--destdir`` option to the ``copy`` command becomes a setting
3379       of a ``destdir`` variable on the invocation of ``make copy``. The
3380       supplied ``Makefile`` should provide a ``copy`` target, which will
3381       probably look like this:
3383       .. code-block:: make
3385           copy :
3386                   $(MAKE) install prefix=$(destdir)/$(prefix) \
3387                                   bindir=$(destdir)/$(bindir) \
3388                                   libdir=$(destdir)/$(libdir) \
3389                                   dynlibdir=$(destdir)/$(dynlibdir) \
3390                                   datadir=$(destdir)/$(datadir) \
3391                                   libexecdir=$(destdir)/$(libexecdir) \
3392                                   sysconfdir=$(destdir)/$(sysconfdir) \
3394 -  Finally, with the :pkg-field:`build-type` ``Custom``, you can also write your
3395    own setup script from scratch, and you may use the Cabal
3396    library for all or part of the work. One option is to copy the source
3397    of ``Distribution.Simple``, and alter it for your needs. Good luck.
3399 .. _Backpack:
3401 Backpack
3402 --------
3404 Cabal and GHC jointly support Backpack, an extension to Haskell's module
3405 system which makes it possible to parametrize a package over some
3406 modules, which can be instantiated later arbitrarily by a user.  This
3407 means you can write a library to be agnostic over some data
3408 representation, and then instantiate it several times with different
3409 data representations.  Like C++ templates, instantiated packages are
3410 recompiled for each instantiation, which means you do not pay any
3411 runtime cost for parametrizing packages in this way.  Backpack modules
3412 are somewhat experimental; while fully supported by cabal-install, they are currently
3413 `not supported by Stack <https://github.com/commercialhaskell/stack/issues/2540>`__.
3415 A Backpack package is defined by use of the
3416 :pkg-field:`library:signatures` field, or by (transitive) dependency on
3417 a package that defines some requirements.  To define a parametrized
3418 package, define a signature file (file extension ``hsig``) that
3419 specifies the signature of the module you want to parametrize over, and
3420 add it to your Cabal file in the :pkg-field:`library:signatures` field.
3422 .. code-block:: haskell
3423     :caption: .hsig
3425     signature Str where
3427     data Str
3429     concat :: [Str] -> Str
3431 .. code-block:: cabal
3432     :caption: parametrized.cabal
3434     cabal-version: 2.2
3435     name: parametrized
3437     library
3438       build-depends: base
3439       signatures: Str
3440       exposed-modules: MyModule
3442 You can define any number of regular modules (e.g., ``MyModule``) that
3443 import signatures and use them as regular modules.
3445 If you are familiar with ML modules, you might now expect there to be
3446 some way to apply the parametrized package with an implementation of
3447 the ``Str`` module to get a concrete instantiation of the package.
3448 Backpack operates slightly differently with a concept of *mix-in
3449 linking*, where you provide an implementation of ``Str`` simply by
3450 bringing another module into scope with the same name as the
3451 requirement.  For example, if you had a package ``str-impl`` that provided a
3452 module named ``Str``, instantiating ``parametrized`` is as simple as
3453 just depending on both ``str-impl`` and ``parametrized``:
3455 .. code-block:: cabal
3456     :caption: combined.cabal
3458     cabal-version: 2.2
3459     name: combined
3461     library
3462       build-depends: base, str-impl, parametrized
3464 Note that due to technical limitations, you cannot directly define
3465 ``Str`` in the ``combined`` library; it must be placed in its own
3466 library (you can use :ref:`Internal Libraries <sublibs>` to conveniently
3467 define a sub-library).
3469 However, a more common situation is that your names don't match up
3470 exactly.  The :pkg-field:`library:mixins` field can be used to rename
3471 signatures and modules to line up names as necessary.  If you have
3472 a requirement ``Str`` and an implementation ``Data.Text``, you can
3473 line up the names in one of two ways:
3475 * Rename the requirement to match the implementation:
3476   ``mixins: parametrized requires (Str as Data.Text)``
3477 * Rename the implementation to match the requirement:
3478   ``mixins: text (Data.Text as Str)``
3480 The :pkg-field:`library:mixins` field can also be used to disambiguate
3481 between multiple instantiations of the same package; for each
3482 instantiation of the package, give it a separate entry in mixins with
3483 the requirements and provided modules renamed to be distinct.
3485 .. code-block:: cabal
3486     :caption: .cabal
3488     cabal-version: 2.2
3489     name: double-combined
3491     library
3492       build-depends: base, text, bytestring, parametrized
3493       mixins:
3494         parametrized (MyModule as MyModule.Text) requires (Str as Data.Text),
3495         parametrized (MyModule as MyModule.BS) requires (Str as Data.ByteString)
3497 Intensive use of Backpack sometimes involves creating lots of small
3498 parametrized libraries; :ref:`Internal Libraries <sublibs>` can be used
3499 to define all of these libraries in a single package without having to
3500 create many separate Cabal packages.  You may also find it useful to use
3501 :pkg-field:`library:reexported-modules` to reexport instantiated
3502 libraries to Backpack-unware users (e.g., Backpack can be used entirely
3503 as an implementation detail.)
3505 Backpack imposes a limitation on Template Haskell that goes beyond the usual TH
3506 stage restriction: it's not possible to splice TH code imported from a
3507 compilation unit that is still "indefinite", that is, a unit for which some
3508 module signatures still haven't been matched with implementations. The reason
3509 is that indefinite units are typechecked, but not compiled, so there's no
3510 actual TH code to run while splicing. Splicing TH code from a definite
3511 compilation unit into an indefinite one works normally.
3513 For more information about Backpack, check out the
3514 `GHC wiki page <https://gitlab.haskell.org/ghc/ghc/-/wikis/backpack>`__.
3516 .. include:: references.inc
3518 .. rubric:: Footnotes
3520 .. [#old-style-build-tool-depends]
3522   Some packages (ab)use :pkg-field:`build-depends` on old-style builds, but this has a few major drawbacks:
3524     - using Nix-style builds it's considered an error if you depend on a exe-only package via build-depends: the solver will refuse it.
3525     - it may or may not place the executable on ``PATH``.
3526     - it does not ensure the correct version of the package is installed, so you might end up overwriting versions with each other.