Document internal library syntax changes
[cabal.git] / doc / cabal-package.rst
blob2bbc8cce215d40351ca024593e4264f8164c9a26
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:
853         ``private`` for internal libraries. Cannot be set for main
854         (unnamed) library, which is always public.
856     Can be ``public`` or ``private``.
857     Makes it possible to have multiple public libraries in a single package.
858     If set to ``public``, depending on this library from another package is
859     allowed. If set to ``private``, depending on this library is allowed only
860     from the same package.
862     See section on :ref:`Internal Libraries <sublibs>` for examples and more
863     information.
865 .. pkg-field:: reexported-modules: exportlist
866     :since: 1.22
868     Supported only in GHC 7.10 and later. A list of modules to
869     *reexport* from this package. The syntax of this field is
870     ``orig-pkg:Name as NewName`` to reexport module ``Name`` from
871     ``orig-pkg`` with the new name ``NewName``. We also support
872     abbreviated versions of the syntax: if you omit ``as NewName``,
873     we'll reexport without renaming; if you omit ``orig-pkg``, then we
874     will automatically figure out which package to reexport from, if
875     it's unambiguous.
877     Reexported modules are useful for compatibility shims when a package
878     has been split into multiple packages, and they have the useful
879     property that if a package provides a module, and another package
880     reexports it under the same name, these are not considered a
881     conflict (as would be the case with a stub module.) They can also be
882     used to resolve name conflicts.
884 .. pkg-field:: signatures: signature list
885     :since: 2.0
887     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.
889     Module signatures are part of the Backpack_ extension to
890     the Haskell module system.
892     Packages that do not export any modules and only export required signatures
893     are called "signature-only packages", and their signatures are subjected to
894     `signature thinning
895     <https://wiki.haskell.org/Module_signature#How_to_use_a_signature_package>`__.
899 The library section may also contain build information fields (see the
900 section on `build information`_).
902 .. _sublibs:
904 **Internal Libraries**
906 Cabal 2.0 and later support "internal libraries", which are extra named
907 libraries (as opposed to the usual unnamed library section). For
908 example, suppose that your test suite needs access to some internal
909 modules in your library, which you do not otherwise want to export. You
910 could put these modules in an internal library, which the main library
911 and the test suite :pkg-field:`build-depends` upon. Then your Cabal file might
912 look something like this:
916     cabal-version:  2.0
917     name:           foo
918     version:        0.1.0.0
919     license:        BSD3
920     license-file:   LICENSE
921     build-type:     Simple
923     library foo-internal
924         exposed-modules:  Foo.Internal
925         -- NOTE: no explicit constraints on base needed
926         --       as they're inherited from the 'library' stanza
927         build-depends:    base
928         default-language: Haskell2010
930     library
931         exposed-modules:  Foo.Public
932         build-depends:    foo-internal, base >= 4.3 && < 5
933         default-language: Haskell2010
935     test-suite test-foo
936         type:             exitcode-stdio-1.0
937         main-is:          test-foo.hs
938         -- NOTE: no constraints on 'foo-internal' as same-package
939         --       dependencies implicitly refer to the same package instance
940         build-depends:    foo-internal, base
941         default-language: Haskell2010
943 Internal libraries are also useful for packages that define multiple
944 executables, but do not define a publicly accessible library. Internal
945 libraries are only visible internally in the package (so they can only
946 be added to the :pkg-field:`build-depends` of same-package libraries,
947 executables, test suites, etc.) Internal libraries locally shadow any
948 packages which have the same name; consequently, don't name an internal
949 library with the same name as an external dependency if you need to be
950 able to refer to the external dependency in a
951 :pkg-field:`build-depends` declaration.
953 Shadowing can be used to vendor an external dependency into a package
954 and thus emulate *private dependencies*. Below is an example based on
955 a real-world use case:
959     cabal-version: 3.0
960     name: haddock-library
961     version: 1.6.0
962     license: BSD-3-Clause
964     library
965       build-depends:
966         , base         ^>= 4.11.1.0
967         , bytestring   ^>= 0.10.2.0
968         , containers   ^>= 0.4.2.1 || ^>= 0.5.0.0
969         , transformers ^>= 0.5.0.0
971       hs-source-dirs:       src
973       -- internal sub-lib
974       build-depends:        attoparsec
976       exposed-modules:
977         Documentation.Haddock
979       default-language: Haskell2010
981     library attoparsec
982       build-depends:
983         , base         ^>= 4.11.1.0
984         , bytestring   ^>= 0.10.2.0
985         , deepseq      ^>= 1.4.0.0
987       hs-source-dirs:       vendor/attoparsec-0.13.1.0
989       -- NB: haddock-library needs only small part of lib:attoparsec
990       --     internally, so we only bundle that subset here
991       exposed-modules:
992         Data.Attoparsec.ByteString
993         Data.Attoparsec.Combinator
995       other-modules:
996         Data.Attoparsec.Internal
998       ghc-options: -funbox-strict-fields -Wall -fwarn-tabs -O2
1000       default-language: Haskell2010
1002 .. note::
1003     For packages using ``cabal-version: 3.4`` or higher, the syntax to
1004     specify an internal library in a ``build-depends:`` section is
1005     ``package-name:internal-library-name``.
1007 **Multiple public libraries**
1009 Cabal 3.0 and later support exposing multiple libraries from a single package
1010 through the field :pkg-field:`library:visibility`.
1011 Having multiple public libraries is useful for separating the unit of
1012 distribution (package) from the unit of buildable code (library).
1013 For more information about the rationale and some examples, see
1014 `this blog post <https://fgaz.me/posts/2019-11-14-cabal-multiple-libraries/>`__.
1017     TODO inline the blog post
1020 Opening an interpreter session
1021 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1023 While developing a package, it is often useful to make its code
1024 available inside an interpreter session. This can be done with the
1025 ``repl`` command:
1027 .. code-block:: console
1029     $ cabal repl
1031 The name comes from the acronym
1032 `REPL <http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop>`__,
1033 which stands for "read-eval-print-loop". By default ``cabal repl`` loads
1034 the first component in a package. If the package contains several named
1035 components, the name can be given as an argument to ``repl``. The name
1036 can be also optionally prefixed with the component's type for
1037 disambiguation purposes. Example:
1039 .. code-block:: console
1041     $ cabal repl foo
1042     $ cabal repl exe:foo
1043     $ cabal repl test:bar
1044     $ cabal repl bench:baz
1046 Freezing dependency versions
1047 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1049 If a package is built in several different environments, such as a
1050 development environment, a staging environment and a production
1051 environment, it may be necessary or desirable to ensure that the same
1052 dependency versions are selected in each environment. This can be done
1053 with the ``freeze`` command:
1055 .. code-block:: console
1057     $ cabal freeze
1059 The command writes the selected version for all dependencies to the
1060 ``cabal.config`` file. All environments which share this file will use
1061 the dependency versions specified in it.
1063 Generating dependency version bounds
1064 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1066 Cabal also has the ability to suggest dependency version bounds that
1067 conform to the `Package Versioning Policy`_, which is
1068 a recommended versioning system for publicly released Cabal packages.
1069 This is done by running the ``gen-bounds`` command:
1071 .. code-block:: console
1073     $ cabal gen-bounds
1075 For example, given the following dependencies without bounds specified in
1076 :pkg-field:`build-depends`:
1080     build-depends:
1081       base,
1082       mtl,
1083       transformers,
1085 ``gen-bounds`` might suggest changing them to the following:
1089     build-depends:
1090       base          >= 4.15.0 && < 4.16,
1091       mtl           >= 2.2.2 && < 2.3,
1092       transformers  >= 0.5.6 && < 0.6,
1095 Listing outdated dependency version bounds
1096 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1098 Manually updating dependency version bounds in a ``.cabal`` file or a
1099 freeze file can be tedious, especially when there's a lot of
1100 dependencies. The ``cabal outdated`` command is designed to help with
1101 that. It will print a list of packages for which there is a new
1102 version on Hackage that is outside the version bound specified in the
1103 ``build-depends`` field. The ``outdated`` command can also be
1104 configured to act on the freeze file (both old- and v2-style) and
1105 ignore major (or all) version bumps on Hackage for a subset of
1106 dependencies.
1108 Examples:
1110 .. code-block:: console
1112     $ cd /some/package
1113     $ cabal outdated
1114     Outdated dependencies:
1115     haskell-src-exts <1.17 (latest: 1.19.1)
1116     language-javascript <0.6 (latest: 0.6.0.9)
1117     unix ==2.7.2.0 (latest: 2.7.2.1)
1119     $ cabal outdated --simple-output
1120     haskell-src-exts
1121     language-javascript
1122     unix
1124     $ cabal outdated --ignore=haskell-src-exts
1125     Outdated dependencies:
1126     language-javascript <0.6 (latest: 0.6.0.9)
1127     unix ==2.7.2.0 (latest: 2.7.2.1)
1129     $ cabal outdated --ignore=haskell-src-exts,language-javascript,unix
1130     All dependencies are up to date.
1132     $ cabal outdated --ignore=haskell-src-exts,language-javascript,unix -q
1133     $ echo $?
1134     0
1136     $ cd /some/other/package
1137     $ cabal outdated --freeze-file
1138     Outdated dependencies:
1139     HTTP ==4000.3.3 (latest: 4000.3.4)
1140     HUnit ==1.3.1.1 (latest: 1.5.0.0)
1142     $ cabal outdated --freeze-file --ignore=HTTP --minor=HUnit
1143     Outdated dependencies:
1144     HUnit ==1.3.1.1 (latest: 1.3.1.2)
1146 See `the command documentation <cabal-commands.html#cabal-outdated>`__ for a
1147 list of available flags.
1149 Executables
1150 ^^^^^^^^^^^
1152 .. pkg-section:: executable name
1153     :synopsis: Executable build info section.
1155     Executable sections (if present) describe executable programs contained
1156     in the package and must have an argument after the section label, which
1157     defines the name of the executable. This is a freeform argument but may
1158     not contain spaces.
1160 The executable may be described using the following fields, as well as
1161 build information fields (see the section on `build information`_).
1163 .. pkg-field:: main-is: filename (required)
1165     The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
1166     module. Note that it is the ``.hs`` filename that must be listed,
1167     even if that file is generated using a preprocessor. The source file
1168     must be relative to one of the directories listed in
1169     :pkg-field:`hs-source-dirs`. Further, while the name of the file may
1170     vary, the module itself must be named ``Main``.
1172     Starting with ``cabal-version: 1.18`` this field supports
1173     specifying a C, C++, or objC source file as the main entry point.
1175 .. pkg-field:: scope: token
1176     :since: 2.0
1178     Whether the executable is ``public`` (default) or ``private``, i.e. meant to
1179     be run by other programs rather than the user. Private executables are
1180     installed into `$libexecdir/$libexecsubdir`.
1182 Running executables
1183 """""""""""""""""""
1185 You can have Cabal build and run your executables by using the ``run``
1186 command:
1188 .. code-block:: console
1190     $ cabal run EXECUTABLE [-- EXECUTABLE_FLAGS]
1192 This command will configure, build and run the executable
1193 ``EXECUTABLE``. The double dash separator is required to distinguish
1194 executable flags from ``run``'s own flags. If there is only one
1195 executable defined in the whole package, the executable's name can be
1196 omitted. See the output of ``cabal help run`` for a list of options you
1197 can pass to ``cabal run``.
1199 Test suites
1200 ^^^^^^^^^^^
1202 .. pkg-section:: test-suite name
1203     :synopsis: Test suite build information.
1205     Test suite sections (if present) describe package test suites and must
1206     have an argument after the section label, which defines the name of the
1207     test suite. This is a freeform argument, but may not contain spaces. It
1208     should be unique among the names of the package's other test suites, the
1209     package's executables, and the package itself. Using test suite sections
1210     requires at least Cabal version 1.9.2.
1212 The test suite may be described using the following fields, as well as
1213 build information fields (see the section on `build information`_).
1215 .. pkg-field:: type: interface (required until ``cabal-version`` 3.8)
1217     The interface type and version of the test suite. Cabal supports two
1218     test suite interfaces, called ``exitcode-stdio-1.0`` (default since ``cabal-version`` 3.8) and
1219     ``detailed-0.9``. Each of these types may require or disallow other
1220     fields as described below.
1222 Test suites using the ``exitcode-stdio-1.0`` (default since ``cabal-version`` 3.8) interface are executables
1223 that indicate test failure with a non-zero exit code when run; they may
1224 provide human-readable log information through the standard output and
1225 error channels. The ``exitcode-stdio-1.0`` type requires the ``main-is``
1226 field.
1228 .. pkg-field:: main-is: filename
1229     :synopsis: Module containing tests main function.
1231     :required: ``exitcode-stdio-1.0``
1232     :disallowed: ``detailed-0.9``
1234     The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
1235     module. Note that it is the ``.hs`` filename that must be listed,
1236     even if that file is generated using a preprocessor. The source file
1237     must be relative to one of the directories listed in
1238     :pkg-field:`hs-source-dirs`. This field is analogous to the ``main-is`` field
1239     of an executable section.
1241 Test suites using the ``detailed-0.9`` interface are modules exporting
1242 the symbol ``tests :: IO [Test]``. The ``Test`` type is exported by the
1243 module ``Distribution.TestSuite`` provided by Cabal. For more details,
1244 see the example below.
1246 The ``detailed-0.9`` interface allows Cabal and other test agents to
1247 inspect a test suite's results case by case, producing detailed human-
1248 and machine-readable log files. The ``detailed-0.9`` interface requires
1249 the :pkg-field:`test-module` field.
1251 .. pkg-field:: test-module: identifier
1253     :required: ``detailed-0.9``
1254     :disallowed: ``exitcode-stdio-1.0``
1256     The module exporting the ``tests`` symbol.
1258 Example: Package using ``exitcode-stdio-1.0`` interface
1259 """""""""""""""""""""""""""""""""""""""""""""""""""""""
1261 The example package description and executable source file below
1262 demonstrate the use of the ``exitcode-stdio-1.0`` interface.
1264 .. code-block:: cabal
1265     :caption: foo.cabal
1267     Cabal-Version:  3.0
1268     Name:           foo
1269     Version:        1.0
1270     License:        BSD-3-Clause
1271     Build-Type:     Simple
1273     Test-Suite test-foo
1274         type:             exitcode-stdio-1.0
1275         main-is:          test-foo.hs
1276         build-depends:    base >= 4 && < 5
1277         default-language: Haskell2010
1279 .. code-block:: haskell
1280     :caption: test-foo.hs
1282     module Main where
1284     import System.Exit (exitFailure)
1286     main = do
1287         putStrLn "This test always fails!"
1288         exitFailure
1290 Example: Package using ``detailed-0.9`` interface
1291 """""""""""""""""""""""""""""""""""""""""""""""""
1293 The example package description and test module source file below
1294 demonstrate the use of the ``detailed-0.9`` interface. The test module
1295 also develops a simple implementation of the interface set by
1296 ``Distribution.TestSuite``, but in actual usage the implementation would
1297 be provided by the library that provides the testing facility.
1299 .. code-block:: cabal
1300     :caption: bar.cabal
1302     Cabal-Version:  3.0
1303     Name:           bar
1304     Version:        1.0
1305     License:        BSD-3-Clause
1306     Build-Type:     Simple
1308     Test-Suite test-bar
1309         type:             detailed-0.9
1310         test-module:      Bar
1311         build-depends:    base >= 4 && < 5, Cabal >= 1.9.2 && < 2
1312         default-language: Haskell2010
1315 .. code-block:: haskell
1316     :caption: Bar.hs
1318     module Bar ( tests ) where
1320     import Distribution.TestSuite
1322     tests :: IO [Test]
1323     tests = return [ Test succeeds, Test fails ]
1324       where
1325         succeeds = TestInstance
1326             { run = return $ Finished Pass
1327             , name = "succeeds"
1328             , tags = []
1329             , options = []
1330             , setOption = \_ _ -> Right succeeds
1331             }
1332         fails = TestInstance
1333             { run = return $ Finished $ Fail "Always fails!"
1334             , name = "fails"
1335             , tags = []
1336             , options = []
1337             , setOption = \_ _ -> Right fails
1338             }
1340 Running test suites
1341 """""""""""""""""""
1343 You can have Cabal run your test suites using its built-in test runner:
1347     $ cabal configure --enable-tests
1348     $ cabal build
1349     $ cabal test
1351 See the output of ``cabal help test`` for a list of options you can pass
1352 to ``cabal test``.
1354 Benchmarks
1355 ^^^^^^^^^^
1357 .. pkg-section:: benchmark name
1358     :since: 1.9.2
1359     :synopsis: Benchmark build information.
1361     Benchmark sections (if present) describe benchmarks contained in the
1362     package and must have an argument after the section label, which defines
1363     the name of the benchmark. This is a freeform argument, but may not
1364     contain spaces. It should be unique among the names of the package's
1365     other benchmarks, the package's test suites, the package's executables,
1366     and the package itself. Using benchmark sections requires at least Cabal
1367     version 1.9.2.
1369 The benchmark may be described using the following fields, as well as
1370 build information fields (see the section on `build information`_).
1372 .. pkg-field:: type: interface (required until ``cabal-version`` 3.8)
1374     The interface type and version of the benchmark. At the moment Cabal
1375     only support one benchmark interface, called ``exitcode-stdio-1.0``.
1377 Benchmarks using the ``exitcode-stdio-1.0`` (default since ``cabal-version`` 3.8) interface are executables
1378 that indicate failure to run the benchmark with a non-zero exit code
1379 when run; they may provide human-readable information through the
1380 standard output and error channels.
1382 .. pkg-field:: main-is: filename
1384     The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
1385     module. Note that it is the ``.hs`` filename that must be listed,
1386     even if that file is generated using a preprocessor. The source file
1387     must be relative to one of the directories listed in
1388     :pkg-field:`hs-source-dirs`. This field is analogous to the ``main-is``
1389     field of an executable section. Further, while the name of the file may
1390     vary, the module itself must be named ``Main``.
1392 Example:
1393 """""""""""""""""""""""""""""""""""""""""""""""""""""""
1395 .. code-block:: cabal
1396     :caption: foo.cabal
1397     :name: foo-bench.cabal
1399     Cabal-Version:  3.0
1400     Name:           foo
1401     Version:        1.0
1402     License:        BSD-3-Clause
1403     Build-Type:     Simple
1405     Benchmark bench-foo
1406         type:             exitcode-stdio-1.0
1407         main-is:          bench-foo.hs
1408         build-depends:    base >= 4 && < 5, time >= 1.1 && < 1.7
1409         default-language: Haskell2010
1411 .. code-block:: haskell
1412     :caption: bench-foo.hs
1414     {-# LANGUAGE BangPatterns #-}
1415     module Main where
1417     import Data.Time.Clock
1419     fib 0 = 1
1420     fib 1 = 1
1421     fib n = fib (n-1) + fib (n-2)
1423     main = do
1424         start <- getCurrentTime
1425         let !r = fib 20
1426         end <- getCurrentTime
1427         putStrLn $ "fib 20 took " ++ show (diffUTCTime end start)
1429 Running benchmarks
1430 """"""""""""""""""
1432 You can have Cabal run your benchmark using its built-in benchmark
1433 runner:
1437     $ cabal configure --enable-benchmarks
1438     $ cabal build
1439     $ cabal bench
1441 See the output of ``cabal help bench`` for a list of options you can
1442 pass to ``cabal bench``.
1444 Foreign libraries
1445 ^^^^^^^^^^^^^^^^^
1447 Foreign libraries are system libraries intended to be linked against
1448 programs written in C or other "foreign" languages. They
1449 come in two primary flavours: dynamic libraries (``.so`` files on Linux,
1450 ``.dylib`` files on OSX, ``.dll`` files on Windows, etc.) are linked against
1451 executables when the executable is run (or even lazily during
1452 execution), while static libraries (``.a`` files on Linux/OSX, ``.lib``
1453 files on Windows) get linked against the executable at compile time.
1455 Foreign libraries only work with GHC 7.8 and later.
1457 A typical stanza for a foreign library looks like
1461     foreign-library myforeignlib
1462       type:                native-shared
1463       lib-version-info:    6:3:2
1465       if os(Windows)
1466         options: standalone
1467         mod-def-file: MyForeignLib.def
1469       other-modules:       MyForeignLib.SomeModule
1470                            MyForeignLib.SomeOtherModule
1471       build-depends:       base >=4.7 && <4.9
1472       hs-source-dirs:      src
1473       c-sources:           csrc/MyForeignLibWrapper.c
1474       default-language:    Haskell2010
1477 .. pkg-section:: foreign-library name
1478     :since: 2.0
1479     :synopsis: Foreign library build information.
1481     Build information for `foreign libraries`_.
1483 .. pkg-field:: type: foreign library type
1485    Cabal recognizes ``native-static`` and ``native-shared`` here, although
1486    we currently only support building `native-shared` libraries.
1488 .. pkg-field:: options: foreign library option list
1490    Options for building the foreign library, typically specific to the
1491    specified type of foreign library. Currently we only support
1492    ``standalone`` here. A standalone dynamic library is one that does not
1493    have any dependencies on other (Haskell) shared libraries; without
1494    the ``standalone`` option the generated library would have dependencies
1495    on the Haskell runtime library (``libHSrts``), the base library
1496    (``libHSbase``), etc. Currently, ``standalone`` *must* be used on Windows
1497    and *must not* be used on any other platform.
1499 .. pkg-field:: mod-def-file: filename
1501    This option can only be used when creating dynamic Windows libraries
1502    (that is, when using ``native-shared`` and the ``os`` is ``Windows``). If
1503    used, it must be a path to a *module definition file*. The details of
1504    module definition files are beyond the scope of this document; see the
1505    `GHC <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/win32-dlls.html>`_
1506    manual for some details and some further pointers.
1508 .. pkg-field:: lib-version-info: current:revision:age
1510    This field is currently only used on Linux.
1512    This field specifies a Libtool-style version-info field that sets
1513    an appropriate ABI version for the foreign library. Note that the
1514    three numbers specified in this field do not directly specify the
1515    actual ABI version: ``6:3:2`` results in library version ``4.2.3``.
1517    With this field set, the SONAME of the library is set, and symlinks
1518    are installed.
1520    How you should bump this field on an ABI change depends on the
1521    breakage you introduce:
1523    -  Programs using the previous version may use the new version as
1524       drop-in replacement, and programs using the new version can also
1525       work with the previous one. In other words, no recompiling nor
1526       relinking is needed. In this case, bump ``revision`` only, don't
1527       touch current nor age.
1528    -  Programs using the previous version may use the new version as
1529       drop-in replacement, but programs using the new version may use
1530       APIs not present in the previous one. In other words, a program
1531       linking against the new version may fail with "unresolved
1532       symbols" if linking against the old version at runtime: set
1533       revision to 0, bump current and age.
1534    -  Programs may need to be changed, recompiled, and relinked in
1535       order to use the new version. Bump current, set revision and age
1536       to 0.
1538    Also refer to the Libtool documentation on the version-info field.
1540 .. pkg-field:: lib-version-linux: version
1542    This field is only used on Linux.
1544    Specifies the library ABI version directly for foreign libraries
1545    built on Linux: so specifying ``4.2.3`` causes a library
1546    ``libfoo.so.4.2.3`` to be built with SONAME ``libfoo.so.4``, and
1547    appropriate symlinks ``libfoo.so.4`` and ``libfoo.so`` to be
1548    installed.
1550 Note that typically foreign libraries should export a way to initialize
1551 and shutdown the Haskell runtime. In the example above, this is done by
1552 the ``csrc/MyForeignLibWrapper.c`` file, which might look something like
1554 .. code-block:: c
1556     #include <stdlib.h>
1557     #include "HsFFI.h"
1559     HsBool myForeignLibInit(void){
1560       int argc = 2;
1561       char *argv[] = { "+RTS", "-A32m", NULL };
1562       char **pargv = argv;
1564       // Initialize Haskell runtime
1565       hs_init(&argc, &pargv);
1567       // do any other initialization here and
1568       // return false if there was a problem
1569       return HS_BOOL_TRUE;
1570     }
1572     void myForeignLibExit(void){
1573       hs_exit();
1574     }
1576 With modern ghc regular libraries are installed in directories that contain
1577 package keys. This isn't usually a problem because the package gets registered
1578 in ghc's package DB and so we can figure out what the location of the library
1579 is. Foreign libraries however don't get registered, which means that we'd have
1580 to have a way of finding out where a platform library got installed (other than by
1581 searching the ``lib/`` directory). Instead, we install foreign libraries in
1582 ``~/.local/lib``.
1584 Build information
1585 ^^^^^^^^^^^^^^^^^
1586 .. pkg-section:: None
1588 The following fields may be optionally present in a library, executable,
1589 test suite or benchmark section, and give information for the building
1590 of the corresponding library or executable. See also the sections on
1591 `system-dependent parameters`_ and `configurations`_ for a way to supply
1592 system-dependent values for these fields.
1594 .. pkg-field:: build-depends: library list
1596     Declares the *library* dependencies required to build the current
1597     package component; see :pkg-field:`build-tool-depends` for
1598     declaring build-time *tool* dependencies. External library
1599     dependencies should be annotated with a version constraint.
1601     **Library Names**
1603     External libraries are identified by the package's name they're
1604     provided by, optionally followed by a colon and the library name
1605     (available from ``cabal-version: 3.0``).
1606     If the library name is absent, the main (unnamed) library will be used.
1607     To refer to the main (unnamed) library explicitly, use the name of the
1608     package (``foo:foo``).
1609     Multiple libraries from the same package can be specified with the shorthand
1610     syntax ``pkg:{lib1,lib2}```.
1612     See section on :ref:`Internal Libraries <sublibs>` for examples and more
1613     information.
1615     **Version Constraints**
1617     Version constraints use the operators ``==, >=, >, <, <=`` and a
1618     version number. Multiple constraints can be combined using ``&&`` or
1619     ``||``. If no version constraint is specified, any version is
1620     assumed to be acceptable. For example:
1622     ::
1624         library
1625           build-depends:
1626             base >= 2,
1627             foo >= 1.2.3 && < 1.3,
1628             bar
1630     Dependencies like ``foo >= 1.2.3 && < 1.3`` turn out to be very
1631     common because it is recommended practice for package versions to
1632     correspond to API versions (see PVP_).
1634     Since Cabal 1.6, there is a special wildcard syntax to help with
1635     such ranges
1637     ::
1639         build-depends: foo ==1.2.*
1641     It is only syntactic sugar. It is exactly equivalent to
1642     ``foo >= 1.2 && < 1.3``.
1644     .. Warning::
1646        A potential pitfall of the wildcard syntax is that the
1647        constraint ``nats == 1.0.*`` doesn't match the release
1648        ``nats-1`` because the version ``1`` is lexicographically less
1649        than ``1.0``. This is not an issue with the caret-operator
1650        ``^>=`` described below.
1652     Starting with Cabal 2.0, there's a new version operator to express
1653     PVP_-style major upper bounds conveniently, and is inspired by similar
1654     syntactic sugar found in other language ecosystems where it's often
1655     called the "Caret" operator:
1657     ::
1659         build-depends:
1660           foo ^>= 1.2.3.4,
1661           bar ^>= 1
1663     This allows to assert the positive knowledge that this package is
1664     *known* to be semantically compatible with the releases
1665     ``foo-1.2.3.4`` and ``bar-1`` respectively. The information
1666     encoded via such ``^>=``-assertions is used by the cabal solver to
1667     infer version constraints describing semantically compatible
1668     version ranges according to the PVP_ contract (see below).
1670     Another way to say this is that ``foo < 1.3`` expresses *negative*
1671     information, i.e. "``foo-1.3`` or ``foo-1.4.2`` will *not* be
1672     compatible"; whereas ``foo ^>= 1.2.3.4`` asserts the *positive*
1673     information that "``foo-1.2.3.4`` is *known* to be compatible" and (in
1674     the absence of additional information) according to the PVP_
1675     contract we can (positively) infer right away that all versions
1676     satisfying ``foo >= 1.2.3.4 && < 1.3`` will be compatible as well.
1678     .. Note::
1680        More generally, the PVP_ contract implies that we can safely
1681        relax the lower bound to ``>= 1.2``, because if we know that
1682        ``foo-1.2.3.4`` is semantically compatible, then so is
1683        ``foo-1.2`` (if it typechecks). But we'd need to perform
1684        additional static analysis (i.e. perform typechecking) in order
1685        to know if our package in the role of an API consumer will
1686        successfully typecheck against the dependency ``foo-1.2``.  But
1687        since we cannot do this analysis during constraint solving and
1688        to keep things simple, we pragmatically use ``foo >= 1.2.3.4``
1689        as the initially inferred approximation for the lower bound
1690        resulting from the assertion ``foo ^>= 1.2.3.4``. If further
1691        evidence becomes available that e.g. ``foo-1.2`` typechecks,
1692        one can simply revise the dependency specification to include
1693        the assertion ``foo ^>= 1.2``.
1695     The subtle but important difference in signaling allows tooling to
1696     treat explicitly expressed ``<``-style constraints and inferred
1697     (``^>=``-style) upper bounds differently.  For instance,
1698     :cfg-field:`allow-newer`'s ``^``-modifier allows to relax only
1699     ``^>=``-style bounds while leaving explicitly stated
1700     ``<``-constraints unaffected.
1702     Ignoring the signaling intent, the default syntactic desugaring rules are
1704     - ``^>= x`` == ``>= x && < x.1``
1705     - ``^>= x.y`` == ``>= x.y && < x.(y+1)``
1706     - ``^>= x.y.z`` == ``>= x.y.z && < x.(y+1)``
1707     - ``^>= x.y.z.u`` == ``>= x.y.z.u && < x.(y+1)``
1708     - etc.
1710     .. Note::
1712        One might expect the desugaring to truncate all version
1713        components below (and including) the patch-level, i.e.
1714        ``^>= x.y.z.u`` == ``>= x.y.z && < x.(y+1)``,
1715        as the major and minor version components alone are supposed to
1716        uniquely identify the API according to the PVP_.  However, by
1717        designing ``^>=`` to be closer to the ``>=`` operator, we avoid
1718        the potentially confusing effect of ``^>=`` being more liberal
1719        than ``>=`` in the presence of patch-level versions.
1721     Consequently, the example declaration above is equivalent to
1723     ::
1725         build-depends:
1726           foo >= 1.2.3.4 && < 1.3,
1727           bar >= 1 && < 1.1
1729     .. Note::
1731        Prior to Cabal 1.8, ``build-depends`` specified in each
1732        section were global to all sections. This was unintentional, but
1733        some packages were written to depend on it, so if you need your
1734        :pkg-field:`build-depends` to be local to each section, you must specify
1735        at least ``Cabal-Version: >= 1.8`` in your ``.cabal`` file.
1737     .. Note::
1739        Cabal 1.20 experimentally supported module thinning and
1740        renaming in ``build-depends``; however, this support has since been
1741        removed and should not be used.
1743     Starting with Cabal 3.0, a set notation for the ``==`` and ``^>=`` operator
1744     is available. For instance,
1746     ::
1748         tested-with: GHC == 8.6.3, GHC == 8.4.4, GHC == 8.2.2, GHC == 8.0.2,
1749                      GHC == 7.10.3, GHC == 7.8.4, GHC == 7.6.3, GHC == 7.4.2
1751         build-depends: network ^>= 2.6.3.6 || ^>= 2.7.0.2 || ^>= 2.8.0.0 || ^>= 3.0.1.0
1753     can be then written in a more convenient and concise form
1755     ::
1757         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 }
1759         build-depends: network ^>= { 2.6.3.6, 2.7.0.2, 2.8.0.0, 3.0.1.0 }
1762 .. pkg-field:: other-modules: identifier list
1764     A list of modules used by the component but not exposed to users.
1765     For a library component, these would be hidden modules of the
1766     library. For an executable, these would be auxiliary modules to be
1767     linked with the file named in the ``main-is`` field.
1769     .. Note::
1771        Every module in the package *must* be listed in one of
1772        :pkg-field:`other-modules`, :pkg-field:`library:exposed-modules` or
1773        :pkg-field:`executable:main-is` fields.
1775 .. pkg-field:: hs-source-dir: directory list
1776     :deprecated: 2.0
1777     :removed: 3.0
1779     :default: ``.``
1781     Root directories for the module hierarchy.
1783     Deprecated in favor of :pkg-field:`hs-source-dirs`.
1785 .. pkg-field:: hs-source-dirs: directory list
1787     :default: ``.``
1789     Root directories for the module hierarchy.
1791     .. note::
1793       Components can share source directories but modules found there will be
1794       recompiled even if other components already built them, i.e., if a
1795       library and an executable share a source directory and the executable
1796       depends on the library and imports its ``Foo`` module, ``Foo`` will be
1797       compiled twice, once as part of the library and again for the executable.
1799 .. pkg-field:: default-extensions: identifier list
1800    :since: 1.12
1802     A list of Haskell extensions used by every module. These determine
1803     corresponding compiler options enabled for all files. Extension
1804     names are the constructors of the
1805     `Extension <https://hackage.haskell.org/package/Cabal/docs/Language-Haskell-Extension.html#t:Extension>`__
1806     type. For example, ``CPP`` specifies that Haskell source files are
1807     to be preprocessed with a C preprocessor.
1809 .. pkg-field:: other-extensions: identifier list
1810    :since: 1.12
1812     A list of Haskell extensions used by some (but not necessarily all)
1813     modules. From GHC version 6.6 onward, these may be specified by
1814     placing a ``LANGUAGE`` pragma in the source files affected e.g.
1816     .. code-block:: haskell
1818         {-# LANGUAGE CPP, MultiParamTypeClasses #-}
1820     In Cabal-1.24 the dependency solver will use this and
1821     :pkg-field:`default-extensions` information. Cabal prior to 1.24 will abort
1822     compilation if the current compiler doesn't provide the extensions.
1824     If you use some extensions conditionally, using CPP or conditional
1825     module lists, it is good to replicate the condition in
1826     :pkg-field:`other-extensions` declarations:
1828     ::
1830         other-extensions: CPP
1831         if impl(ghc >= 7.5)
1832           other-extensions: PolyKinds
1834     You could also omit the conditionally used extensions, as they are
1835     for information only, but it is recommended to replicate them in
1836     :pkg-field:`other-extensions` declarations.
1838 .. pkg-field:: default-language: identifier
1839    :since: 1.12
1841    TBW
1843 .. pkg-field:: other-languages: identifier
1844    :since: 1.12
1846    TBW
1848 .. pkg-field:: extensions: identifier list
1849    :deprecated: 1.12
1850    :removed: 3.0
1852    Deprecated in favor of :pkg-field:`default-extensions`.
1854 .. pkg-field:: build-tool-depends: package:executable list
1855     :since: 2.0
1857     A list of Haskell executables needed to build this component. Executables are provided
1858     during the whole duration of the component, so this field can be used for executables
1859     needed during :pkg-section:`test-suite` as well.
1861     Each is specified by the package containing the executable and the name of the
1862     executable itself, separated by a colon, and optionally followed by a version bound.
1864     All executables defined in the given Cabal file are termed as *internal* dependencies
1865     as opposed to the rest which are *external* dependencies.
1867     Each of the two is handled differently:
1869     1. External dependencies can (and should) contain a version bound like conventional
1870        :pkg-field:`build-depends` dependencies.
1871     2. Internal dependencies should not contain a version bound, as they will be always
1872        resolved within the same configuration of the package in the build plan.
1873        Specifically, version bounds that include the package's version will be warned for
1874        being extraneous, and version bounds that exclude the package's version will raise
1875        an error for being impossible to follow.
1877     For example (1) using a test-suite to make sure README.md Haskell snippets are tested using
1878     `markdown-unlit <http://hackage.haskell.org/package/markdown-unlit>`__:
1880     ::
1882         build-tool-depends: markdown-unlit:markdown-unlit >= 0.5.0 && < 0.6
1884     For example (2) using a test-suite to test executable behaviour in the same package:
1886     ::
1888         build-tool-depends: mypackage:executable
1890     Cabal tries to make sure that all specified programs are atomically built and prepended
1891     on the ``PATH`` shell variable before building the component in question, but can only do
1892     so for Nix-style builds. Specifically:
1894     a) For Nix-style local builds, both internal and external dependencies.
1895     b) For old-style builds, only for internal dependencies [#old-style-build-tool-depends]_.
1896        It's up to the user to provide needed executables in this case under ``PATH``.
1899     .. note::
1901       :pkg-field:`build-tool-depends` was added in Cabal 2.0, and it will
1902       be ignored (with a warning) with old versions of Cabal.  See
1903       :pkg-field:`build-tools` for more information about backwards
1904       compatibility.
1906 .. pkg-field:: build-tools: program list
1907     :deprecated: 2.0
1908     :removed: 3.0
1910     Deprecated in favor of :pkg-field:`build-tool-depends`, but :ref:`see below for backwards compatibility information <buildtoolsbc>`.
1912     A list of Haskell programs needed to build this component.
1913     Each may be followed by an optional version bound.
1914     Confusingly, each program in the list either refer to one of three things:
1916       1. Another executables in the same package (supported since Cabal 1.12)
1918       2. Tool name contained in Cabal's :ref:`hard-coded set of common tools <buildtoolsmap>`
1920       3. A pre-built executable that should already be on the ``PATH``
1921          (supported since Cabal 2.0)
1923     These cases are listed in order of priority:
1924     an executable in the package will override any of the hard-coded packages with the same name,
1925     and a hard-coded package will override any executable on the ``PATH``.
1927     In the first two cases, the list entry is desugared into a :pkg-field:`build-tool-depends` entry.
1928     In the first case, the entry is desugared into a :pkg-field:`build-tool-depends` entry by prefixing with ``$pkg:``.
1929     In the second case, it is desugared by looking up the package and executable name in a hard-coded table.
1930     In either case, the optional version bound is passed through unchanged.
1931     Refer to the documentation for :pkg-field:`build-tool-depends` to understand the desugared field's meaning, along with restrictions on version bounds.
1933     .. _buildtoolsbc:
1935     **Backward Compatibility**
1937     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.
1938     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.
1939     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``.
1941     .. _buildtoolsmap:
1943     **Set of Known Tool Names**
1945     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::
1947         build-tools: alex >= 3.2.1 && < 3.3, happy >= 1.19.5 && < 1.20
1949     is simply desugared into the equivalent specification::
1951         build-tool-depends: alex:alex >= 3.2.1 && < 3.3, happy:happy >= 1.19.5 && < 1.20
1953     +--------------------------+-----------------------------------+-----------------+
1954     | :pkg-field:`build-tools` | desugared                         | Note            |
1955     | identifier               | :pkg-field:`build-tool-depends`   |                 |
1956     |                          | identifier                        |                 |
1957     +==========================+===================================+=================+
1958     | ``alex``                 | ``alex:alex``                     |                 |
1959     +--------------------------+-----------------------------------+-----------------+
1960     | ``c2hs``                 | ``c2hs:c2hs``                     |                 |
1961     +--------------------------+-----------------------------------+-----------------+
1962     | ``cpphs``                | ``cpphs:cpphs``                   |                 |
1963     +--------------------------+-----------------------------------+-----------------+
1964     | ``greencard``            | ``greencard:greencard``           |                 |
1965     +--------------------------+-----------------------------------+-----------------+
1966     | ``haddock``              | ``haddock:haddock``               |                 |
1967     +--------------------------+-----------------------------------+-----------------+
1968     | ``happy``                | ``happy:happy``                   |                 |
1969     +--------------------------+-----------------------------------+-----------------+
1970     | ``hsc2hs``               | ``hsc2hs:hsc2hs``                 |                 |
1971     +--------------------------+-----------------------------------+-----------------+
1972     | ``hscolour``             | ``hscolour:hscolour``             |                 |
1973     +--------------------------+-----------------------------------+-----------------+
1974     | ``hspec-discover``       | ``hspec-discover:hspec-discover`` | since Cabal 2.0 |
1975     +--------------------------+-----------------------------------+-----------------+
1977     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.
1979 .. pkg-field:: buildable: boolean
1981     :default: ``True``
1983     Is the component buildable? Like some of the other fields below,
1984     this field is more useful with the slightly more elaborate form of
1985     the simple build infrastructure described in the section on
1986     `system-dependent parameters`_.
1988 .. pkg-field:: ghc-options: token list
1990     Additional options for GHC. You can often achieve the same effect
1991     using the :pkg-field:`default-extensions` field, which is preferred.
1993     Options required only by one module may be specified by placing an
1994     ``OPTIONS_GHC`` pragma in the source file affected.
1996     As with many other fields, whitespace can be escaped by using
1997     Haskell string syntax. Example:
1998     ``ghc-options: -Wcompat "-with-rtsopts=-T -I1" -Wall``.
2000 .. pkg-field:: ghc-prof-options: token list
2002     Additional options for GHC when the package is built with profiling
2003     enabled.
2005     Note that as of Cabal-1.24, the default profiling detail level
2006     defaults to ``exported-functions`` for libraries and
2007     ``toplevel-functions`` for executables. For GHC these correspond to
2008     the flags ``-fprof-auto-exported`` and ``-fprof-auto-top``. Prior to
2009     Cabal-1.24 the level defaulted to ``none``. These levels can be
2010     adjusted by the person building the package with the
2011     ``--profiling-detail`` and ``--library-profiling-detail`` flags.
2013     It is typically better for the person building the package to pick
2014     the profiling detail level rather than for the package author. So
2015     unless you have special needs it is probably better not to specify
2016     any of the GHC ``-fprof-auto*`` flags here. However if you wish to
2017     override the profiling detail level, you can do so using the
2018     :pkg-field:`ghc-prof-options` field: use ``-fno-prof-auto`` or one of the
2019     other ``-fprof-auto*`` flags.
2021 .. pkg-field:: ghc-shared-options: token list
2023     Additional options for GHC when the package is built as shared
2024     library. The options specified via this field are combined with the
2025     ones specified via :pkg-field:`ghc-options`, and are passed to GHC during
2026     both the compile and link phases.
2028 .. pkg-field:: ghcjs-options: token list
2030    Like :pkg-field:`ghc-options` but applies to GHCJS
2032 .. pkg-field:: ghcjs-prof-options: token list
2034    Like :pkg-field:`ghc-prof-options` but applies to GHCJS
2036 .. pkg-field:: ghcjs-shared-options: token list
2038    Like :pkg-field:`ghc-shared-options` but applies to GHCJS
2040 .. pkg-field:: includes: filename list
2042     A list of header files to be included in any compilations via C.
2043     This field applies to both header files that are already installed
2044     on the system and to those coming with the package to be installed.
2045     The former files should be found in absolute paths, while the latter
2046     files should be found in paths relative to the top of the source
2047     tree or relative to one of the directories listed in
2048     :pkg-field:`include-dirs`.
2050     These files typically contain function prototypes for foreign
2051     imports used by the package. This is in contrast to
2052     :pkg-field:`install-includes`, which lists header files that are intended
2053     to be exposed to other packages that transitively depend on this
2054     library.
2056 .. pkg-field:: install-includes: filename list
2058     A list of header files from this package to be installed into
2059     ``$libdir/includes`` when the package is installed. Files listed in
2060     :pkg-field:`install-includes` should be found in relative to the top of the
2061     source tree or relative to one of the directories listed in
2062     :pkg-field:`include-dirs`.
2064     :pkg-field:`install-includes` is typically used to name header files that
2065     contain prototypes for foreign imports used in Haskell code in this
2066     package, for which the C implementations are also provided with the
2067     package. For example, here is a ``.cabal`` file for a hypothetical
2068     ``bindings-clib`` package that bundles the C source code for ``clib``::
2070         include-dirs:     cbits
2071         c-sources:        clib.c
2072         install-includes: clib.h
2074     Now any package that depends (directly or transitively) on the
2075     ``bindings-clib`` library can use ``clib.h``.
2077     Note that in order for files listed in :pkg-field:`install-includes` to be
2078     usable when compiling the package itself, they need to be listed in
2079     the :pkg-field:`includes` field as well.
2081 .. pkg-field:: include-dirs: directory list
2083     A list of directories to search for header files, when preprocessing
2084     with ``c2hs``, ``hsc2hs``, ``cpphs`` or the C preprocessor, and also
2085     when compiling via C. Directories can be absolute paths (e.g., for
2086     system directories) or paths that are relative to the top of the
2087     source tree. Cabal looks in these directories when attempting to
2088     locate files listed in :pkg-field:`includes` and
2089     :pkg-field:`install-includes`.
2091 .. pkg-field:: c-sources: filename list
2093     A list of C source files to be compiled and linked with the Haskell
2094     files.
2096 .. pkg-field:: cxx-sources: filename list
2097     :since: 2.2
2099     A list of C++ source files to be compiled and linked with the Haskell
2100     files. Useful for segregating C and C++ sources when supplying different
2101     command-line arguments to the compiler via the :pkg-field:`cc-options`
2102     and the :pkg-field:`cxx-options` fields. The files listed in the
2103     :pkg-field:`cxx-sources` can reference files listed in the
2104     :pkg-field:`c-sources` field and vice-versa. The object files will be linked
2105     appropriately.
2107 .. pkg-field:: asm-sources: filename list
2108     :since: 3.0
2110     A list of assembly source files to be compiled and linked with the
2111     Haskell files.
2113 .. pkg-field:: cmm-sources: filename list
2114     :since: 3.0
2116     A list of C-- source files to be compiled and linked with the Haskell
2117     files.
2119 .. pkg-field:: js-sources: filename list
2121     A list of JavaScript source files to be linked with the Haskell
2122     files (only for JavaScript targets).
2124 .. pkg-field:: extra-libraries: token list
2126     A list of extra libraries to link with (when not linking fully static
2127     executables).
2129 .. pkg-field:: extra-libraries-static: token list
2131     A list of extra libraries to link with (when linking fully static
2132     executables).
2134 .. pkg-field:: extra-ghci-libraries: token list
2136     A list of extra libraries to be used instead of 'extra-libraries'
2137     when the package is loaded with GHCi.
2139 .. pkg-field:: extra-bundled-libraries: token list
2140    :since: 2.2
2142    A list of libraries that are supposed to be copied from the build
2143    directory alongside the produced Haskell libraries.  Note that you
2144    are under the obligation to produce those libraries in the build
2145    directory (e.g. via a custom setup).  Libraries listed here will
2146    be included when ``copy``-ing packages and be listed in the
2147    ``hs-libraries`` of the package configuration in the package database.
2148    Library names must either be prefixed with "HS" or "C" and corresponding
2149    library file names must match:
2151       - Libraries with name "HS<library-name>":
2152          - `libHS<library-name>.a`
2153          - `libHS<library-name>-ghc<ghc-flavour><ghc-version>.<dyn-library-extension>*`
2154       - Libraries with name "C<library-name>":
2155          - `libC<library-name>.a`
2156          - `lib<library-name>.<dyn-library-extension>*`
2158 .. pkg-field:: extra-lib-dirs: directory list
2160     A list of directories to search for libraries (when not linking fully static
2161     executables).
2163 .. pkg-field:: extra-lib-dirs-static: directory list
2165     A list of directories to search for libraries (when linking fully static
2166     executables).
2168 .. pkg-field:: extra-library-flavours: notsure
2170     TBW
2172 .. pkg-field:: extra-dynamic-library-flavours: notsure
2174     TBW
2176 .. pkg-field:: cc-options: token list
2178     Command-line arguments to be passed to the C compiler. Since the
2179     arguments are compiler-dependent, this field is more useful with the
2180     setup described in the section on `system-dependent parameters`_.
2182 .. pkg-field:: cpp-options: token list
2184     Command-line arguments for pre-processing Haskell code. Applies to
2185     Haskell source and other pre-processed Haskell source like .hsc
2186     .chs. Does not apply to C code, that's what cc-options is for.
2188 .. pkg-field:: cxx-options: token list
2189     :since: 2.2
2191     Command-line arguments to be passed to the compiler when compiling
2192     C++ code. The C++ sources to which these command-line arguments
2193     should be applied can be specified with the :pkg-field:`cxx-sources`
2194     field. Command-line options for C and C++ can be passed separately to
2195     the compiler when compiling both C and C++ sources by segregating the C
2196     and C++ sources with the :pkg-field:`c-sources` and
2197     :pkg-field:`cxx-sources` fields respectively, and providing different
2198     command-line arguments with the :pkg-field:`cc-options` and the
2199     :pkg-field:`cxx-options` fields.
2201 .. pkg-field:: cmm-options: token list
2202     :since: 3.0
2204     Command-line arguments to be passed to the compiler when compiling
2205     C-- code. See also :pkg-field:`cmm-sources`.
2207 .. pkg-field:: asm-options: token list
2208     :since: 3.0
2210     Command-line arguments to be passed to the assembler when compiling
2211     assembler code. See also :pkg-field:`asm-sources`.
2213 .. pkg-field:: ld-options: token list
2215     Command-line arguments to be passed to the linker. Since the
2216     arguments are compiler-dependent, this field is more useful with the
2217     setup described in the section on `system-dependent parameters`_.
2219 .. pkg-field:: hsc2hs-options: token list
2220     :since: 3.6
2222     Command-line arguments to be passed to ``hsc2hs``.
2224 .. pkg-field:: pkgconfig-depends: package list
2226     A list of
2227     `pkg-config <http://www.freedesktop.org/wiki/Software/pkg-config/>`__
2228     packages, needed to build this package. They can be annotated with
2229     versions, e.g. ``gtk+-2.0 >= 2.10, cairo >= 1.0``. If no version
2230     constraint is specified, any version is assumed to be acceptable.
2231     Cabal uses ``pkg-config`` to find if the packages are available on
2232     the system and to find the extra compilation and linker options
2233     needed to use the packages.
2235     If you need to bind to a C library that supports ``pkg-config`` then
2236     it is much preferable to use this field rather than hard code options
2237     into the other fields. ``pkg-config --list-all`` will show you all
2238     supported libraries. Depending on your system you may need to adjust
2239     ``PKG_CONFIG_PATH``.
2241 .. pkg-field:: frameworks: token list
2243     On Darwin/MacOS X, a list of frameworks to link to. See Apple's
2244     developer documentation for more details on frameworks. This entry
2245     is ignored on all other platforms.
2247 .. pkg-field:: extra-framework-dirs: directory list
2248     :since: 1.24
2250     On Darwin/MacOS X, a list of directories to search for frameworks.
2251     This entry is ignored on all other platforms.
2253 .. pkg-field:: mixins: mixin list
2254     :since: 2.0
2256     Supported only in GHC 8.2 and later. A list of packages mentioned in the
2257     :pkg-field:`build-depends` field, each optionally accompanied by a list of
2258     module and module signature renamings.  A valid mixin obeys the
2259     following syntax:
2261     ::
2263         Mixin ::= PackageName IncludeRenaming
2264         IncludeRenaming ::= ModuleRenaming { "requires" ModuleRenaming }
2265         ModuleRenaming ::=
2266             {- empty -}
2267           | "(" Renaming "," ... "," Renaming ")"
2268           | "hiding" "(" ModuleName "," ... "," ModuleName ")"
2269         Renaming ::=
2270             ModuleName
2271           | ModuleName "as" ModuleName
2273     The simplest mixin syntax is simply the name of a package mentioned in the
2274     :pkg-field:`build-depends` field. For example:
2276     ::
2278         library
2279           build-depends:
2280             foo ^>= 1.2.3
2281           mixins:
2282             foo
2284     But this doesn't have any effect. More interesting is to use the mixin
2285     entry to rename one or more modules from the package, like this:
2287     ::
2289         library
2290           mixins:
2291             foo (Foo.Bar as AnotherFoo.Bar, Foo.Baz as AnotherFoo.Baz)
2293     Note that renaming a module like this will hide all the modules
2294     that are not explicitly named.
2296     Modules can also be hidden:
2298     ::
2300         library:
2301           mixins:
2302             foo hiding (Foo.Bar)
2304     Hiding modules exposes everything that is not explicitly hidden.
2306     .. Note::
2308        Cabal files with :pkg-field:`cabal-version` < 3.0 suffer from an
2309        infelicity in how the entries of :pkg-field:`mixins` are parsed: an
2310        entry will fail to parse if the provided renaming clause has whitespace
2311        after the opening parenthesis.
2313        See issues :issue:`5150`, :issue:`4864`, and :issue:`5293`.
2315     There can be multiple mixin entries for a given package, in effect creating
2316     multiple copies of the dependency:
2318     ::
2320         library
2321           mixins:
2322             foo (Foo.Bar as AnotherFoo.Bar, Foo.Baz as AnotherFoo.Baz),
2323             foo (Foo.Bar as YetAnotherFoo.Bar)
2325     The ``requires`` clause is used to rename the module signatures required by
2326     a package:
2328     ::
2330         library
2331           mixins:
2332             foo (Foo.Bar as AnotherFoo.Bar) requires (Foo.SomeSig as AnotherFoo.SomeSig)
2334     Signature-only packages don't have any modules, so only the signatures can
2335     be renamed, with the following syntax:
2337     ::
2339         library
2340           mixins:
2341             sigonly requires (SigOnly.SomeSig as AnotherSigOnly.SomeSig)
2343     See the :pkg-field:`library:signatures` field for more details.
2345     Mixin packages are part of the Backpack_ extension to the
2346     Haskell module system.
2348     The matching of the module signatures required by a
2349     :pkg-field:`build-depends` dependency with the implementation modules
2350     present in another dependency is triggered by a coincidence of names. When
2351     the names of the signature and of the implementation are already the same,
2352     the matching is automatic. But when the names don't coincide, or we want to
2353     instantiate a signature in two different ways, adding mixin entries that
2354     perform renamings becomes necessary.
2356     .. Warning::
2358        Backpack_ has the limitation that implementation modules that instantiate
2359        signatures required by a :pkg-field:`build-depends` dependency can't
2360        reside in the same component that has the dependency. They must reside
2361        in a different package dependency, or at least in a separate internal
2362        library.
2364 Configurations
2365 ^^^^^^^^^^^^^^
2367 Library and executable sections may include conditional blocks, which
2368 test for various system parameters and configuration flags. The flags
2369 mechanism is rather generic, but most of the time a flag represents
2370 certain feature, that can be switched on or off by the package user.
2371 Here is an example package description file using configurations:
2373 Example: A package containing a library and executable programs
2374 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2378     Cabal-Version: 3.0
2379     Name: Test1
2380     Version: 0.0.1
2381     License: BSD-3-Clause
2382     Author:  Jane Doe
2383     Synopsis: Test package to test configurations
2384     Category: Example
2385     Build-Type: Simple
2387     Flag Debug
2388       Description: Enable debug support
2389       Default:     False
2390       Manual:      True
2392     Flag WebFrontend
2393       Description: Include API for web frontend.
2394       Default:     False
2395       Manual:      True
2397     Flag NewDirectory
2398       description: Whether to build against @directory >= 1.2@
2399       -- This is an automatic flag which the solver will
2400       -- assign automatically while searching for a solution
2402     Library
2403       Build-Depends:      base >= 4.2 && < 4.9
2404       Exposed-Modules:    Testing.Test1
2405       Default-Extensions: CPP
2406       Default-Language:   Haskell2010
2408       GHC-Options: -Wall
2409       if flag(Debug)
2410         CPP-Options: -DDEBUG
2411         if !os(windows)
2412           CC-Options: "-DDEBUG"
2413         else
2414           CC-Options: "-DNDEBUG"
2416       if flag(WebFrontend)
2417         Build-Depends: cgi >= 0.42 && < 0.44
2418         Other-Modules: Testing.WebStuff
2419         CPP-Options: -DWEBFRONTEND
2421         if flag(NewDirectory)
2422             build-depends: directory >= 1.2 && < 1.4
2423             Build-Depends: time >= 1.0 && < 1.9
2424         else
2425             build-depends: directory == 1.1.*
2426             Build-Depends: old-time >= 1.0 && < 1.2
2428     Executable test1
2429       Main-is:          T1.hs
2430       Other-Modules:    Testing.Test1
2431       Build-Depends:    base >= 4.2 && < 4.9
2432       Default-Language: Haskell2010
2434       if flag(debug)
2435         CC-Options: "-DDEBUG"
2436         CPP-Options: -DDEBUG
2438 Layout
2439 """"""
2441 Flags, conditionals, library and executable sections use layout to
2442 indicate structure. This is very similar to the Haskell layout rule.
2443 Entries in a section have to all be indented to the same level which
2444 must be more than the section header. Tabs are not allowed to be used
2445 for indentation.
2447 As an alternative to using layout you can also use explicit braces
2448 ``{}``. In this case the indentation of entries in a section does not
2449 matter, though different fields within a block must be on different
2450 lines. Here is a bit of the above example again, using braces:
2452 Example: Using explicit braces rather than indentation for layout
2453 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2457     Cabal-Version: 3.0
2458     Name: Test1
2459     Version: 0.0.1
2460     License: BSD-3-Clause
2461     Author:  Jane Doe
2462     Synopsis: Test package to test configurations
2463     Category: Example
2464     Build-Type: Simple
2466     Flag Debug {
2467       Description: Enable debug support
2468       Default:     False
2469       Manual:      True
2470     }
2472     Library {
2473       Build-Depends:       base >= 4.2 && < 4.9
2474       Exposed-Modules:     Testing.Test1
2475       Default-Extensions:  CPP
2476       Default-language:    Haskell2010
2477       if flag(debug) {
2478         CPP-Options: -DDEBUG
2479         if !os(windows) {
2480           CC-Options: "-DDEBUG"
2481         } else {
2482           CC-Options: "-DNDEBUG"
2483         }
2484       }
2485     }
2487 Configuration Flags
2488 """""""""""""""""""
2490 .. pkg-section:: flag name
2491     :synopsis: Flag declaration.
2493     Flag section declares a flag which can be used in `conditional blocks`_.
2495     Flag names are case-insensitive and must match ``[[:alnum:]_][[:alnum:]_-]*``
2496     regular expression, or expressed as ABNF_:
2498     .. code-block:: abnf
2500        flag-name = (UALNUM / "_") *(UALNUM / "_" / "-")
2502        UALNUM = UALPHA / DIGIT
2503        UALPHA = ... ; set of alphabetic Unicode code-points
2505     .. note::
2507         Hackage accepts ASCII-only flags, ``[a-zA-Z0-9_][a-zA-Z0-9_-]*`` regexp.
2509 .. pkg-field:: description: freeform
2511     The description of this flag.
2513 .. pkg-field:: default: boolean
2515     :default: ``True``
2517     The default value of this flag.
2519     .. note::
2521       This value may be :ref:`overridden in several
2522       ways <controlling flag assignments>`. The
2523       rationale for having flags default to True is that users usually
2524       want new features as soon as they are available. Flags representing
2525       features that are not (yet) recommended for most users (such as
2526       experimental features or debugging support) should therefore
2527       explicitly override the default to False.
2529 .. pkg-field:: manual: boolean
2531     :default: ``False``
2532     :since: 1.6
2534     By default, Cabal will first try to satisfy dependencies with the
2535     default flag value and then, if that is not possible, with the
2536     negated value. However, if the flag is manual, then the default
2537     value (which can be overridden by commandline flags) will be used.
2539 Conditional Blocks
2540 ^^^^^^^^^^^^^^^^^^
2542 Conditional blocks may appear anywhere inside a library or executable
2543 section. They have to follow rather strict formatting rules. Conditional
2544 blocks must always be of the shape
2548       if condition
2549          property-descriptions-or-conditionals
2555       if condition
2556            property-descriptions-or-conditionals
2557       else
2558            property-descriptions-or-conditionals
2560 Note that the ``if`` and the condition have to be all on the same line.
2562 Since Cabal 2.2 conditional blocks support ``elif`` construct.
2566       if condition1
2567            property-descriptions-or-conditionals
2568       elif condition2
2569            property-descriptions-or-conditionals
2570       else
2571            property-descriptions-or-conditionals
2573 .. _conditions:
2575 Conditions
2576 """"""""""
2578 Conditions can be formed using boolean tests and the boolean operators
2579 ``||`` (disjunction / logical "or"), ``&&`` (conjunction / logical
2580 "and"), or ``!`` (negation / logical "not"). The unary ``!`` takes
2581 highest precedence, ``||`` takes lowest. Precedence levels may be
2582 overridden through the use of parentheses. For example,
2583 ``os(darwin) && !arch(i386) || os(freebsd)`` is equivalent to
2584 ``(os(darwin) && !(arch(i386))) || os(freebsd)``.
2586 The following tests are currently supported.
2588 :samp:`os({name})`
2589     Tests if the current operating system is *name*. The argument is
2590     tested against ``System.Info.os`` on the target system. There is
2591     unfortunately some disagreement between Haskell implementations
2592     about the standard values of ``System.Info.os``. Cabal canonicalises
2593     it so that in particular ``os(windows)`` works on all
2594     implementations. If the canonicalised os names match, this test
2595     evaluates to true, otherwise false. The match is case-insensitive.
2596 :samp:`arch({name})`
2597     Tests if the current architecture is *name*. The argument is matched
2598     against ``System.Info.arch`` on the target system. If the arch names
2599     match, this test evaluates to true, otherwise false. The match is
2600     case-insensitive.
2601 :samp:`impl({compiler})`
2602     Tests for the configured Haskell implementation. An optional version
2603     constraint may be specified (for example ``impl(ghc >= 6.6.1)``). If
2604     the configured implementation is of the right type and matches the
2605     version constraint, then this evaluates to true, otherwise false.
2606     The match is case-insensitive.
2608     Note that including a version constraint in an ``impl`` test causes
2609     it to check for two properties:
2611     -  The current compiler has the specified name, and
2613     -  The compiler's version satisfied the specified version constraint
2615     As a result, ``!impl(ghc >= x.y.z)`` is not entirely equivalent to
2616     ``impl(ghc < x.y.z)``. The test ``!impl(ghc >= x.y.z)`` checks that:
2618     -  The current compiler is not GHC, or
2620     -  The version of GHC is earlier than version x.y.z.
2622 :samp:`flag({name})`
2623     Evaluates to the current assignment of the flag of the given name.
2624     Flag names are case insensitive. Testing for flags that have not
2625     been introduced with a flag section is an error.
2626 ``true``
2627     Constant value true.
2628 ``false``
2629     Constant value false.
2631 .. _resolution-of-conditions-and-flags:
2633 Resolution of Conditions and Flags
2634 """"""""""""""""""""""""""""""""""
2636 If a package descriptions specifies configuration flags the package user
2637 can :ref:`control these in several ways <controlling flag assignments>`. If the
2638 user does not fix the value of a flag, Cabal will try to find a flag
2639 assignment in the following way.
2641 -  For each flag specified, it will assign its default value, evaluate
2642    all conditions with this flag assignment, and check if all
2643    dependencies can be satisfied. If this check succeeded, the package
2644    will be configured with those flag assignments.
2646 -  If dependencies were missing, the last flag (as by the order in which
2647    the flags were introduced in the package description) is tried with
2648    its alternative value and so on. This continues until either an
2649    assignment is found where all dependencies can be satisfied, or all
2650    possible flag assignments have been tried.
2652 To put it another way, Cabal does a complete backtracking search to find
2653 a satisfiable package configuration. It is only the dependencies
2654 specified in the :pkg-field:`build-depends` field in conditional blocks that
2655 determine if a particular flag assignment is satisfiable
2656 (:pkg-field:`build-tools` are not considered). The order of the declaration and
2657 the default value of the flags determines the search order. Flags
2658 overridden on the command line fix the assignment of that flag, so no
2659 backtracking will be tried for that flag.
2661 If no suitable flag assignment could be found, the configuration phase
2662 will fail and a list of missing dependencies will be printed. Note that
2663 this resolution process is exponential in the worst case (i.e., in the
2664 case where dependencies cannot be satisfied). There are some
2665 optimizations applied internally, but the overall complexity remains
2666 unchanged.
2668 Meaning of field values when using conditionals
2669 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2671 During the configuration phase, a flag assignment is chosen, all
2672 conditionals are evaluated, and the package description is combined into
2673 a flat package descriptions. If the same field is declared both inside
2674 a conditional and outside then they are combined using the following rules.
2676 -  Boolean fields are combined using conjunction (logical "and").
2678 -  List fields are combined by appending the inner items to the outer
2679    items, for example
2681    ::
2683        other-extensions: CPP
2684        if impl(ghc)
2685          other-extensions: MultiParamTypeClasses
2687    when compiled using GHC will be combined to
2689    ::
2691        other-extensions: CPP, MultiParamTypeClasses
2693    Similarly, if two conditional sections appear at the same nesting
2694    level, properties specified in the latter will come after properties
2695    specified in the former.
2697 -  All other fields must not be specified in ambiguous ways. For example
2699    ::
2701        Main-is: Main.hs
2702        if flag(useothermain)
2703          Main-is: OtherMain.hs
2705    will lead to an error. Instead use
2707    ::
2709        if flag(useothermain)
2710          Main-is: OtherMain.hs
2711        else
2712          Main-is: Main.hs
2714 .. _common-stanzas:
2716 Common stanzas
2717 ^^^^^^^^^^^^^^
2719 .. pkg-section:: common name
2720     :since: 2.2
2721     :synopsis: Common build info section
2723 Starting with Cabal-2.2 it's possible to use common build info stanzas.
2727       common deps
2728         build-depends: base ^>= 4.11
2729         ghc-options: -Wall
2731       common test-deps
2732         build-depends: tasty ^>= 0.12.0.1
2734       library
2735         import:           deps
2736         exposed-modules:  Foo
2737         default-language: Haskell2010
2739       test-suite tests
2740         import:           deps, test-deps
2741         type:             exitcode-stdio-1.0
2742         main-is:          Tests.hs
2743         build-depends:    foo
2744         default-language: Haskell2010
2746 -  You can use `build information`_ fields in common stanzas.
2748 -  Common stanzas must be defined before use.
2750 -  Common stanzas can import other common stanzas.
2752 -  You can import multiple stanzas at once. Stanza names must be separated by commas.
2754 -  ``import`` must be the first field in a section. Since Cabal 3.0 imports
2755    are also allowed inside conditionals.
2757 .. Note::
2759     The name `import` was chosen, because there is ``includes`` field.
2761 .. pkg-section:: None
2763 .. pkg-field:: import: token-list
2765     TBW
2767 Source Repositories
2768 ^^^^^^^^^^^^^^^^^^^
2770 .. pkg-section:: source-repository
2771     :since: 1.6
2773 It is often useful to be able to specify a source revision control
2774 repository for a package. Cabal lets you specify this information in
2775 a relatively structured form which enables other tools to interpret and
2776 make effective use of the information. For example the information
2777 should be sufficient for an automatic tool to checkout the sources.
2779 Cabal supports specifying different information for various common
2780 source control systems. Obviously not all automated tools will support
2781 all source control systems.
2783 Cabal supports specifying repositories for different use cases. By
2784 declaring which case we mean automated tools can be more useful. There
2785 are currently two kinds defined:
2787 -  The ``head`` kind refers to the latest development branch of the
2788    package. This may be used for example to track activity of a project
2789    or as an indication to outside developers what sources to get for
2790    making new contributions.
2792 -  The ``this`` kind refers to the branch and tag of a repository that
2793    contains the sources for this version or release of a package. For
2794    most source control systems this involves specifying a tag, id or
2795    hash of some form and perhaps a branch. The purpose is to be able to
2796    reconstruct the sources corresponding to a particular package
2797    version. This might be used to indicate what sources to get if
2798    someone needs to fix a bug in an older branch that is no longer an
2799    active head branch.
2801 You can specify one kind or the other or both. As an example here are
2802 the repositories for the Cabal library. Note that the ``this`` kind of
2803 repository specifies a tag.
2807     source-repository head
2808       type:     git
2809       location: https://github.com/haskell/cabal
2811     source-repository this
2812       type:     git
2813       location: https://github.com/haskell/cabal
2814       tag:      1.6.1
2816 The exact fields are as follows:
2818 .. pkg-field:: type: token
2820     The name of the source control system used for this repository. The
2821     currently recognised types are:
2823     -  ``darcs``
2824     -  ``git``
2825     -  ``svn``
2826     -  ``cvs``
2827     -  ``mercurial`` (or alias ``hg``)
2828     -  ``bazaar`` (or alias ``bzr``)
2829     -  ``arch``
2830     -  ``monotone``
2832     This field is required.
2834 .. pkg-field:: location: URL
2836     The location of the repository. The exact form of this field depends
2837     on the repository type. For example:
2839     -  for darcs: ``http://code.haskell.org/foo/``
2840     -  for git: ``git://github.com/foo/bar.git``
2841     -  for CVS: ``anoncvs@cvs.foo.org:/cvs``
2843     This field is required.
2845 .. pkg-field:: module: token
2847     CVS requires a named module, as each CVS server can host multiple
2848     named repositories.
2850     This field is required for the CVS repository type and should not be
2851     used otherwise.
2853 .. pkg-field:: branch: token
2855     Many source control systems support the notion of a branch, as a
2856     distinct concept from having repositories in separate locations. For
2857     example CVS, SVN and git use branches while darcs uses different
2858     locations for different branches. If you need to specify a branch to
2859     identify a your repository then specify it in this field.
2861     This field is optional.
2863 .. pkg-field:: tag: token
2865     A tag identifies a particular state of a source repository. The tag
2866     can be used with a ``this`` repository kind to identify the state of
2867     a repository corresponding to a particular package version or
2868     release. The exact form of the tag depends on the repository type.
2870     This field is required for the ``this`` repository kind.
2872 .. pkg-field:: subdir: directory
2874     Some projects put the sources for multiple packages under a single
2875     source repository. This field lets you specify the relative path
2876     from the root of the repository to the top directory for the
2877     package, i.e. the directory containing the package's ``.cabal``
2878     file.
2880     This field is optional. It defaults to empty which corresponds to the
2881     root directory of the repository.
2883 Downloading a package's source
2884 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2886 The ``cabal get`` command allows to access a package's source code -
2887 either by unpacking a tarball downloaded from Hackage (the default) or
2888 by checking out a working copy from the package's source repository.
2892     $ cabal get [FLAGS] PACKAGES
2894 The ``get`` command supports the following options:
2896 ``-d --destdir`` *PATH*
2897     Where to place the package source, defaults to (a subdirectory of)
2898     the current directory.
2899 ``-s --source-repository`` *[head\|this\|...]*
2900     Clone the package's source repository using the appropriate version
2901     control system. The optional argument allows to choose a specific
2902     repository kind.
2903 ``--index-state`` *[HEAD\|@<unix-timestamp>\|<iso8601-utc-timestamp>]*
2904     Use source package index state as it existed at a previous time. Accepts
2905     unix-timestamps (e.g. ``@1474732068``), ISO8601 UTC timestamps (e.g.
2906     ``2016-09-24T17:47:48Z``), or ``HEAD`` (default).
2907     This determines which package versions are available as well as which
2908     ``.cabal`` file revision is selected (unless ``--pristine`` is used).
2909 ``--only-package-description``
2910     Unpack only the package description file. A synonym,
2911     ``--package-description-only``, is provided for convenience.
2912 ``--pristine``
2913     Unpack the original pristine tarball, rather than updating the
2914     ``.cabal`` file with the latest revision from the package archive.
2916 Custom setup scripts
2917 --------------------
2919 Since Cabal 1.24, custom ``Setup.hs`` are required to accurately track
2920 their dependencies by declaring them in the ``.cabal`` file rather than
2921 rely on dependencies being implicitly in scope.  Please refer to
2922 `this article <https://www.well-typed.com/blog/2015/07/cabal-setup-deps/>`__
2923 for more details.
2925 As of Cabal library version 3.0, ``defaultMain*`` variants implement support
2926 for response files. Custom ``Setup.hs`` files that do not use one of these
2927 main functions are required to implement their own support, such as by using
2928 ``GHC.ResponseFile.getArgsWithResponseFiles``.
2930 Declaring a ``custom-setup`` stanza also enables the generation of
2931 ``MIN_VERSION_package_(A,B,C)`` CPP macros for the Setup component.
2933 .. pkg-section:: custom-setup
2934    :synopsis: Custom Setup.hs build information.
2935    :since: 1.24
2937    The optional :pkg-section:`custom-setup` stanza contains information needed
2938    for the compilation of custom ``Setup.hs`` scripts,
2942     custom-setup
2943       setup-depends:
2944         base  >= 4.5 && < 4.11,
2945         Cabal >= 1.14 && < 1.25
2947 .. pkg-field:: setup-depends: package list
2948     :since: 1.24
2950     The dependencies needed to compile ``Setup.hs``. See the
2951     :pkg-field:`build-depends` field for a description of the syntax expected by
2952     this field.
2954     If the field is not specified the implicit package set will be used.
2955     The package set contains packages bundled with GHC (i.e. ``base``,
2956     ``bytestring``) and specifically ``Cabal``.
2957     The specific bounds are put on ``Cabal`` dependency:
2958     lower-bound is inferred from :pkg-field:`cabal-version`,
2959     and the upper-bound is ``< 1.25``.
2961     ``Cabal`` version is additionally restricted by GHC,
2962     with absolute minimum being ``1.20``, and for example ``Custom``
2963     builds with GHC-8.10 require at least ``Cabal-3.2``.
2966 Backward compatibility and ``custom-setup``
2967 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2969 Versions prior to Cabal 1.24 don't recognise ``custom-setup`` stanzas,
2970 and will behave agnostic to them (except for warning about an unknown
2971 section). Consequently, versions prior to Cabal 1.24 can't ensure the
2972 declared dependencies ``setup-depends`` are in scope, and instead
2973 whatever is registered in the current package database environment
2974 will become eligible (and resolved by the compiler) for the
2975 ``Setup.hs`` module.
2977 The availability of the
2978 ``MIN_VERSION_package_(A,B,C)`` CPP macros
2979 inside ``Setup.hs`` scripts depends on the condition that either
2981 - a ``custom-setup`` section has been declared (or ``cabal build`` is being
2982   used which injects an implicit hard-coded ``custom-setup`` stanza if it's missing), or
2983 - GHC 8.0 or later is used (which natively injects package version CPP macros)
2985 Consequently, if you need to write backward compatible ``Setup.hs``
2986 scripts using CPP, you should declare a ``custom-setup`` stanza and
2987 use the pattern below:
2989 .. code-block:: haskell
2991     {-# LANGUAGE CPP #-}
2992     import Distribution.Simple
2994     #if defined(MIN_VERSION_Cabal)
2995     -- version macros are available and can be used as usual
2996     # if MIN_VERSION_Cabal(a,b,c)
2997     -- code specific to lib:Cabal >= a.b.c
2998     # else
2999     -- code specific to lib:Cabal < a.b.c
3000     # endif
3001     #else
3002     # warning Enabling heuristic fall-back. Please upgrade cabal-install to 1.24 or later if Setup.hs fails to compile.
3004     -- package version macros not available; except for exotic environments,
3005     -- you can heuristically assume that lib:Cabal's version is correlated
3006     -- with __GLASGOW_HASKELL__, and specifically since we can assume that
3007     -- GHC < 8.0, we can assume that lib:Cabal is version 1.22 or older.
3008     #endif
3010     main = ...
3012 The simplified (heuristic) CPP pattern shown below is useful if all you need
3013 is to distinguish ``Cabal < 2.0`` from ``Cabal >= 2.0``.
3015 .. code-block:: haskell
3017     {-# LANGUAGE CPP #-}
3018     import Distribution.Simple
3020     #if !defined(MIN_VERSION_Cabal)
3021     # define MIN_VERSION_Cabal(a,b,c) 0
3022     #endif
3024     #if MIN_VERSION_Cabal(2,0,0)
3025     -- code for lib:Cabal >= 2.0
3026     #else
3027     -- code for lib:Cabal < 2.0
3028     #endif
3030     main = ...
3034 Autogenerated modules and includes
3035 ----------------------------------
3037 .. pkg-section:: None
3039 Modules that are built automatically at setup, created with a custom
3040 setup script, must appear on :pkg-field:`other-modules` for the library,
3041 executable, test-suite or benchmark stanzas or also on
3042 :pkg-field:`library:exposed-modules` for libraries to be used, but are not
3043 really on the package when distributed. This makes commands like sdist fail
3044 because the file is not found.
3046 These special modules must appear again on the :pkg-field:`autogen-modules`
3047 field of the stanza that is using them, besides :pkg-field:`other-modules` or
3048 :pkg-field:`library:exposed-modules`. With this there is no need to create
3049 complex build hooks for this poweruser case.
3051 .. pkg-field:: autogen-modules: module list
3052    :since: 2.0
3054    .. todo:: document autogen-modules field
3056 Right now :pkg-field:`executable:main-is` modules are not supported on
3057 :pkg-field:`autogen-modules`.
3061     Library
3062         default-language: Haskell2010
3063         build-depends: base
3064         exposed-modules:
3065             MyLibrary
3066             MyLibHelperModule
3067         other-modules:
3068             MyLibModule
3069         autogen-modules:
3070             MyLibHelperModule
3072     Executable Exe
3073         default-language: Haskell2010
3074         main-is: Dummy.hs
3075         build-depends: base
3076         other-modules:
3077             MyExeModule
3078             MyExeHelperModule
3079         autogen-modules:
3080             MyExeHelperModule
3082 .. pkg-field:: autogen-includes: filename list
3083    :since: 3.0
3085    A list of header files from this package which are autogenerated
3086    (e.g. by a ``configure`` script). Autogenerated header files are not
3087    packaged by ``sdist`` command.
3089 Virtual modules
3090 ---------------
3094 .. pkg-field:: virtual-modules: module list
3095    :since: 2.2
3097    TBW
3100 .. _accessing-data-files:
3102 Accessing data files from package code
3103 --------------------------------------
3105 The placement on the target system of files listed in
3106 the :pkg-field:`data-files` field varies between systems, and in some cases
3107 one can even move packages around after installation
3108 (see :ref:`prefix independence`). To
3109 enable packages to find these files in a portable way, Cabal generates a
3110 module called :file:`Paths_{pkgname}` (with any hyphens in *pkgname*
3111 replaced by underscores) during building, so that it may be imported by
3112 modules of the package. This module defines a function
3114 .. code-block:: haskell
3116     getDataFileName :: FilePath -> IO FilePath
3118 If the argument is a filename listed in the :pkg-field:`data-files` field, the
3119 result is the name of the corresponding file on the system on which the
3120 program is running.
3122 .. Note::
3124    If you decide to import the :file:`Paths_{pkgname}` module then it
3125    *must* be listed in the :pkg-field:`other-modules` field just like any other
3126    module in your package and on :pkg-field:`autogen-modules` as the file is
3127    autogenerated.
3129 The :file:`Paths_{pkgname}` module is not platform independent, as any
3130 other autogenerated module, so it does not get included in the source
3131 tarballs generated by ``sdist``.
3133 The :file:`Paths_{pkgname}` module also includes some other useful
3134 functions and values, which record the version of the package and some
3135 other directories which the package has been configured to be installed
3136 into (e.g. data files live in ``getDataDir``):
3138 .. code-block:: haskell
3140     version :: Version
3142     getBinDir :: IO FilePath
3143     getLibDir :: IO FilePath
3144     getDynLibDir :: IO FilePath
3145     getDataDir :: IO FilePath
3146     getLibexecDir :: IO FilePath
3147     getSysconfDir :: IO FilePath
3149 The actual location of all these directories can be individually
3150 overridden at runtime using environment variables of the form
3151 ``pkg_name_var``, where ``pkg_name`` is the name of the package with all
3152 hyphens converted into underscores, and ``var`` is either ``bindir``,
3153 ``libdir``, ``dynlibdir``, ``datadir``, ``libexedir`` or ``sysconfdir``. For example,
3154 the configured data directory for ``pretty-show`` is controlled with the
3155 ``pretty_show_datadir`` environment variable.
3157 Accessing the package version
3158 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3160 The aforementioned auto generated :file:`Paths_{pkgname}` module also
3161 exports the constant ``version ::``
3162 `Version <http://hackage.haskell.org/package/base/docs/Data-Version.html>`__
3163 which is defined as the version of your package as specified in the
3164 ``version`` field.
3166 .. _system-dependent parameters:
3168 System-dependent parameters
3169 ---------------------------
3171 For some packages, especially those interfacing with C libraries,
3172 implementation details and the build procedure depend on the build
3173 environment. The ``build-type`` ``Configure`` can be used to handle many
3174 such situations. In this case, ``Setup.hs`` should be:
3176 .. code-block:: haskell
3178     import Distribution.Simple
3179     main = defaultMainWithHooks autoconfUserHooks
3181 Most packages, however, would probably do better using the ``Simple``
3182 build type and `configurations`_.
3184 The :pkg-field:`build-type` ``Configure`` differs from ``Simple`` in two ways:
3186 -  The package root directory must contain a shell script called
3187    ``configure``. The configure step will run the script. This
3188    ``configure`` script may be produced by
3189    `autoconf <http://www.gnu.org/software/autoconf/>`__ or may be
3190    hand-written. The ``configure`` script typically discovers
3191    information about the system and records it for later steps, e.g. by
3192    generating system-dependent header files for inclusion in C source
3193    files and preprocessed Haskell source files. (Clearly this won't work
3194    for Windows without MSYS or Cygwin: other ideas are needed.)
3196 -  If the package root directory contains a file called
3197    *package*\ ``.buildinfo`` after the configuration step, subsequent
3198    steps will read it to obtain additional settings for `build
3199    information`_ fields,to be merged with the ones
3200    given in the ``.cabal`` file. In particular, this file may be
3201    generated by the ``configure`` script mentioned above, allowing these
3202    settings to vary depending on the build environment.
3204 The build information file should have the following structure:
3206     *buildinfo*
3208     ``executable:`` *name* *buildinfo*
3210     ``executable:`` *name* *buildinfo* ...
3212 where each *buildinfo* consists of settings of fields listed in the
3213 section on `build information`_. The first one (if
3214 present) relates to the library, while each of the others relate to the
3215 named executable. (The names must match the package description, but you
3216 don't have to have entries for all of them.)
3218 Neither of these files is required. If they are absent, this setup
3219 script is equivalent to ``defaultMain``.
3221 Example: Using autoconf
3222 ^^^^^^^^^^^^^^^^^^^^^^^
3224 This example is for people familiar with the
3225 `autoconf <http://www.gnu.org/software/autoconf/>`__ tools.
3227 In the X11 package, the file ``configure.ac`` contains:
3229 .. code-block:: shell
3231     AC_INIT([Haskell X11 package], [1.1], [libraries@haskell.org], [X11])
3233     # Safety check: Ensure that we are in the correct source directory.
3234     AC_CONFIG_SRCDIR([X11.cabal])
3236     # Header file to place defines in
3237     AC_CONFIG_HEADERS([include/HsX11Config.h])
3239     # Check for X11 include paths and libraries
3240     AC_PATH_XTRA
3241     AC_TRY_CPP([#include <X11/Xlib.h>],,[no_x=yes])
3243     # Build the package if we found X11 stuff
3244     if test "$no_x" = yes
3245     then BUILD_PACKAGE_BOOL=False
3246     else BUILD_PACKAGE_BOOL=True
3247     fi
3248     AC_SUBST([BUILD_PACKAGE_BOOL])
3250     AC_CONFIG_FILES([X11.buildinfo])
3251     AC_OUTPUT
3253 Then the setup script will run the ``configure`` script, which checks
3254 for the presence of the X11 libraries and substitutes for variables in
3255 the file ``X11.buildinfo.in``:
3259     buildable: @BUILD_PACKAGE_BOOL@
3260     cc-options: @X_CFLAGS@
3261     ld-options: @X_LIBS@
3263 This generates a file ``X11.buildinfo`` supplying the parameters needed
3264 by later stages:
3268     buildable: True
3269     cc-options:  -I/usr/X11R6/include
3270     ld-options:  -L/usr/X11R6/lib
3272 The ``configure`` script also generates a header file
3273 ``include/HsX11Config.h`` containing C preprocessor defines recording
3274 the results of various tests. This file may be included by C source
3275 files and preprocessed Haskell source files in the package.
3277 .. Note::
3279    Packages using these features will also need to list additional
3280    files such as ``configure``, templates for ``.buildinfo`` files, files
3281    named only in ``.buildinfo`` files, header files and so on in the
3282    :pkg-field:`extra-source-files` field to ensure that they are included in
3283    source distributions. They should also list files and directories generated
3284    by ``configure`` in the :pkg-field:`extra-tmp-files` field to ensure that
3285    they are removed by ``setup clean``.
3287 Quite often the files generated by ``configure`` need to be listed
3288 somewhere in the package description (for example, in the
3289 :pkg-field:`install-includes` field). However, we usually don't want generated
3290 files to be included in the source tarball. The solution is again
3291 provided by the ``.buildinfo`` file. In the above example, the following
3292 line should be added to ``X11.buildinfo``:
3296     install-includes: HsX11Config.h
3298 In this way, the generated ``HsX11Config.h`` file won't be included in
3299 the source tarball in addition to ``HsX11Config.h.in``, but it will be
3300 copied to the right location during the install process. Packages that
3301 use custom ``Setup.hs`` scripts can update the necessary fields
3302 programmatically instead of using the ``.buildinfo`` file.
3304 Conditional compilation
3305 -----------------------
3307 Sometimes you want to write code that works with more than one version
3308 of a dependency. You can specify a range of versions for the dependency
3309 in the :pkg-field:`build-depends`, but how do you then write the code that can
3310 use different versions of the API?
3312 Haskell lets you preprocess your code using the C preprocessor (either
3313 the real C preprocessor, or ``cpphs``). To enable this, add
3314 ``extensions: CPP`` to your package description. When using CPP, Cabal
3315 provides some pre-defined macros to let you test the version of
3316 dependent packages; for example, suppose your package works with either
3317 version 3 or version 4 of the ``base`` package, you could select the
3318 available version in your Haskell modules like this:
3320 .. code-block:: cpp
3322     #if MIN_VERSION_base(4,0,0)
3323     ... code that works with base-4 ...
3324     #else
3325     ... code that works with base-3 ...
3326     #endif
3328 In general, Cabal supplies a macro
3329 ``MIN_VERSION_``\ *``package``*\ ``_(A,B,C)`` for each package depended
3330 on via :pkg-field:`build-depends`. This macro is true if the actual version of
3331 the package in use is greater than or equal to ``A.B.C`` (using the
3332 conventional ordering on version numbers, which is lexicographic on the
3333 sequence, but numeric on each component, so for example 1.2.0 is greater
3334 than 1.0.3).
3336 Since version 1.20, the ``MIN_TOOL_VERSION_``\ *``tool``*
3337 family of macros lets you condition on the version of build tools used to
3338 build the program (e.g. ``hsc2hs``).
3340 Since version 1.24, the macro ``CURRENT_COMPONENT_ID``, which
3341 expands to the string of the component identifier that uniquely
3342 identifies this component.  Furthermore, if the package is a library,
3343 the macro ``CURRENT_PACKAGE_KEY`` records the identifier that was passed
3344 to GHC for use in symbols and for type equality.
3346 Since version 2.0, the macro ``CURRENT_PACKAGE_VERSION`` expands
3347 to the string version number of the current package.
3349 Cabal places the definitions of these macros into an
3350 automatically-generated header file, which is included when
3351 preprocessing Haskell source code by passing options to the C
3352 preprocessor.
3354 Cabal also allows to detect when the source code is being used for
3355 generating documentation. The ``__HADDOCK_VERSION__`` macro is defined
3356 only when compiling via Haddock_
3357 instead of a normal Haskell compiler. The value of the
3358 ``__HADDOCK_VERSION__`` macro is defined as ``A*1000 + B*10 + C``, where
3359 ``A.B.C`` is the Haddock version. This can be useful for working around
3360 bugs in Haddock or generating prettier documentation in some special
3361 cases.
3363 .. _more-complex-packages:
3365 More complex packages
3366 ---------------------
3368 For packages that don't fit the simple schemes described above, you have
3369 a few options:
3371 -  By using the :pkg-field:`build-type` ``Custom``, you can supply your own
3372    ``Setup.hs`` file, and customize the simple build infrastructure
3373    using *hooks*. These allow you to perform additional actions before
3374    and after each command is run, and also to specify additional
3375    preprocessors. A typical ``Setup.hs`` may look like this:
3377    .. code-block:: haskell
3379        import Distribution.Simple
3380        main = defaultMainWithHooks simpleUserHooks { postHaddock = posthaddock }
3382        posthaddock args flags desc info = ....
3384    See ``UserHooks`` in
3385    `Distribution.Simple <https://hackage.haskell.org/package/Cabal/docs/Distribution-Simple.html>`__
3386    for the details, but note that this interface is experimental, and
3387    likely to change in future releases.
3389    If you use a custom ``Setup.hs`` file you should strongly consider
3390    adding a :pkg-section:`custom-setup` stanza with a
3391    :pkg-field:`custom-setup:setup-depends` field to ensure that your setup
3392    script does not break with future dependency versions.
3394 -  You could delegate all the work to ``make``, though this is unlikely
3395    to be very portable. Cabal supports this with the :pkg-field:`build-type`
3396    ``Make`` and a trivial setup library
3397    `Distribution.Make <https://hackage.haskell.org/package/Cabal/docs/Distribution-Make.html>`__,
3398    which simply parses the command line arguments and invokes ``make``.
3399    Here ``Setup.hs`` should look like this:
3401    .. code-block:: haskell
3403        import Distribution.Make
3404        main = defaultMain
3406    The root directory of the package should contain a ``configure``
3407    script, and, after that has run, a ``Makefile`` with a default target
3408    that builds the package, plus targets ``install``, ``register``,
3409    ``unregister``, ``clean``, ``dist`` and ``docs``. Some options to
3410    commands are passed through as follows:
3412    -  The ``--with-hc-pkg``, ``--prefix``, ``--bindir``, ``--libdir``,
3413       ``--dynlibdir``, ``--datadir``, ``--libexecdir`` and ``--sysconfdir`` options to
3414       the ``configure`` command are passed on to the ``configure``
3415       script. In addition the value of the ``--with-compiler`` option is
3416       passed in a ``--with-hc`` option and all options specified with
3417       ``--configure-option=`` are passed on.
3419    -  The ``--destdir`` option to the ``copy`` command becomes a setting
3420       of a ``destdir`` variable on the invocation of ``make copy``. The
3421       supplied ``Makefile`` should provide a ``copy`` target, which will
3422       probably look like this:
3424       .. code-block:: make
3426           copy :
3427                   $(MAKE) install prefix=$(destdir)/$(prefix) \
3428                                   bindir=$(destdir)/$(bindir) \
3429                                   libdir=$(destdir)/$(libdir) \
3430                                   dynlibdir=$(destdir)/$(dynlibdir) \
3431                                   datadir=$(destdir)/$(datadir) \
3432                                   libexecdir=$(destdir)/$(libexecdir) \
3433                                   sysconfdir=$(destdir)/$(sysconfdir) \
3435 -  Finally, with the :pkg-field:`build-type` ``Custom``, you can also write your
3436    own setup script from scratch, and you may use the Cabal
3437    library for all or part of the work. One option is to copy the source
3438    of ``Distribution.Simple``, and alter it for your needs. Good luck.
3440 .. _Backpack:
3442 Backpack
3443 --------
3445 Cabal and GHC jointly support Backpack, an extension to Haskell's module
3446 system which makes it possible to parametrize a package over some
3447 modules, which can be instantiated later arbitrarily by a user.  This
3448 means you can write a library to be agnostic over some data
3449 representation, and then instantiate it several times with different
3450 data representations.  Like C++ templates, instantiated packages are
3451 recompiled for each instantiation, which means you do not pay any
3452 runtime cost for parametrizing packages in this way.  Backpack modules
3453 are somewhat experimental; while fully supported by cabal-install, they are currently
3454 `not supported by Stack <https://github.com/commercialhaskell/stack/issues/2540>`__.
3456 A Backpack package is defined by use of the
3457 :pkg-field:`library:signatures` field, or by (transitive) dependency on
3458 a package that defines some requirements.  To define a parametrized
3459 package, define a signature file (file extension ``hsig``) that
3460 specifies the signature of the module you want to parametrize over, and
3461 add it to your Cabal file in the :pkg-field:`library:signatures` field.
3463 .. code-block:: haskell
3464     :caption: .hsig
3466     signature Str where
3468     data Str
3470     concat :: [Str] -> Str
3472 .. code-block:: cabal
3473     :caption: parametrized.cabal
3475     cabal-version: 2.2
3476     name: parametrized
3478     library
3479       build-depends: base
3480       signatures: Str
3481       exposed-modules: MyModule
3483 You can define any number of regular modules (e.g., ``MyModule``) that
3484 import signatures and use them as regular modules.
3486 If you are familiar with ML modules, you might now expect there to be
3487 some way to apply the parametrized package with an implementation of
3488 the ``Str`` module to get a concrete instantiation of the package.
3489 Backpack operates slightly differently with a concept of *mix-in
3490 linking*, where you provide an implementation of ``Str`` simply by
3491 bringing another module into scope with the same name as the
3492 requirement.  For example, if you had a package ``str-impl`` that provided a
3493 module named ``Str``, instantiating ``parametrized`` is as simple as
3494 just depending on both ``str-impl`` and ``parametrized``:
3496 .. code-block:: cabal
3497     :caption: combined.cabal
3499     cabal-version: 2.2
3500     name: combined
3502     library
3503       build-depends: base, str-impl, parametrized
3505 Note that due to technical limitations, you cannot directly define
3506 ``Str`` in the ``combined`` library; it must be placed in its own
3507 library (you can use :ref:`Internal Libraries <sublibs>` to conveniently
3508 define a sub-library).
3510 However, a more common situation is that your names don't match up
3511 exactly.  The :pkg-field:`library:mixins` field can be used to rename
3512 signatures and modules to line up names as necessary.  If you have
3513 a requirement ``Str`` and an implementation ``Data.Text``, you can
3514 line up the names in one of two ways:
3516 * Rename the requirement to match the implementation:
3517   ``mixins: parametrized requires (Str as Data.Text)``
3518 * Rename the implementation to match the requirement:
3519   ``mixins: text (Data.Text as Str)``
3521 The :pkg-field:`library:mixins` field can also be used to disambiguate
3522 between multiple instantiations of the same package; for each
3523 instantiation of the package, give it a separate entry in mixins with
3524 the requirements and provided modules renamed to be distinct.
3526 .. code-block:: cabal
3527     :caption: .cabal
3529     cabal-version: 2.2
3530     name: double-combined
3532     library
3533       build-depends: base, text, bytestring, parametrized
3534       mixins:
3535         parametrized (MyModule as MyModule.Text) requires (Str as Data.Text),
3536         parametrized (MyModule as MyModule.BS) requires (Str as Data.ByteString)
3538 Intensive use of Backpack sometimes involves creating lots of small
3539 parametrized libraries; :ref:`Internal Libraries <sublibs>` can be used
3540 to define all of these libraries in a single package without having to
3541 create many separate Cabal packages.  You may also find it useful to use
3542 :pkg-field:`library:reexported-modules` to reexport instantiated
3543 libraries to Backpack-unware users (e.g., Backpack can be used entirely
3544 as an implementation detail.)
3546 Backpack imposes a limitation on Template Haskell that goes beyond the usual TH
3547 stage restriction: it's not possible to splice TH code imported from a
3548 compilation unit that is still "indefinite", that is, a unit for which some
3549 module signatures still haven't been matched with implementations. The reason
3550 is that indefinite units are typechecked, but not compiled, so there's no
3551 actual TH code to run while splicing. Splicing TH code from a definite
3552 compilation unit into an indefinite one works normally.
3554 For more information about Backpack, check out the
3555 `GHC wiki page <https://gitlab.haskell.org/ghc/ghc/-/wikis/backpack>`__.
3557 .. include:: references.inc
3559 .. rubric:: Footnotes
3561 .. [#old-style-build-tool-depends]
3563   Some packages (ab)use :pkg-field:`build-depends` on old-style builds, but this has a few major drawbacks:
3565     - 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.
3566     - it may or may not place the executable on ``PATH``.
3567     - it does not ensure the correct version of the package is installed, so you might end up overwriting versions with each other.