cabal-package.rst 120 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
Package Description
===================

The Cabal package is the unit of distribution. When installed, its
purpose is to make available:

-  One or more Haskell programs.

-  At most one library, exposing a number of Haskell modules.

However having both a library and executables in a package does not work
very well; if the executables depend on the library, they must
explicitly list all the modules they directly or indirectly import from
that library. Fortunately, starting with Cabal 1.8.0.4, executables can
also declare the package that they are in as a dependency, and Cabal
will treat them as if they were in another package that depended on the
library.

Internally, the package may consist of much more than a bunch of Haskell
modules: it may also have C source code and header files, source code
meant for preprocessing, documentation, test cases, auxiliary tools etc.

A package is identified by a globally-unique *package name*, which
consists of one or more alphanumeric words separated by hyphens. To
avoid ambiguity, each of these words should contain at least one letter.
Chaos will result if two distinct packages with the same name are
installed on the same system. A particular version of the package is
distinguished by a *version number*, consisting of a sequence of one or
more integers separated by dots. These can be combined to form a single
text string called the *package ID*, using a hyphen to separate the name
from the version, e.g. "``HUnit-1.1``".

.. Note::

   Packages are not part of the Haskell language; they simply
   populate the hierarchical space of module names. In GHC 6.6 and later a
   program may contain multiple modules with the same name if they come
   from separate packages; in all other current Haskell systems packages
   may not overlap in the modules they provide, including hidden modules.

Creating a package
------------------

Suppose you have a directory hierarchy containing the source files that
make up your package. You will need to add two more files to the root
directory of the package:

:file:`{package-name}.cabal`
    a Unicode UTF-8 text file containing a package description. For
    details of the syntax of this file, see the section on
    `package descriptions`_.

:file:`Setup.hs`
    a single-module Haskell program to perform various setup tasks (with
    the interface described in the section on :ref:`installing-packages`).
    This module should import only modules that will be present in all Haskell
    implementations, including modules of the Cabal library. The content of
    this file is determined by the :pkg-field:`build-type` setting in the
    ``.cabal`` file. In most cases it will be trivial, calling on the Cabal
    library to do most of the work.

Once you have these, you can create a source bundle of this directory
for distribution. Building of the package is discussed in the section on
:ref:`installing-packages`.

One of the purposes of Cabal is to make it easier to build a package
with different Haskell implementations. So it provides abstractions of
features present in different Haskell implementations and wherever
possible it is best to take advantage of these to increase portability.
Where necessary however it is possible to use specific features of
specific implementations. For example one of the pieces of information a
package author can put in the package's ``.cabal`` file is what language
extensions the code uses. This is far preferable to specifying flags for
a specific compiler as it allows Cabal to pick the right flags for the
Haskell implementation that the user picks. It also allows Cabal to
figure out if the language extension is even supported by the Haskell
implementation that the user picks. Where compiler-specific options are
needed however, there is an "escape hatch" available. The developer can
specify implementation-specific options and more generally there is a
configuration mechanism to customise many aspects of how a package is
built depending on the Haskell implementation, the Operating system,
computer architecture and user-specified configuration flags.

::

    name:     Foo
    version:  1.0

    library
      build-depends:   base >= 4 && < 5
      exposed-modules: Foo
      extensions:      ForeignFunctionInterface
      ghc-options:     -Wall
      if os(windows)
        build-depends: Win32 >= 2.1 && < 2.6

Example: A package containing a simple library
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The HUnit package contains a file ``HUnit.cabal`` containing:

::

    name:           HUnit
    version:        1.1.1
    synopsis:       A unit testing framework for Haskell
    homepage:       http://hunit.sourceforge.net/
    category:       Testing
    author:         Dean Herington
    license:        BSD3
    license-file:   LICENSE
    cabal-version:  1.12
    build-type:     Simple

    library
      build-depends:      base >= 2 && < 4
      exposed-modules:    Test.HUnit.Base, Test.HUnit.Lang,
                          Test.HUnit.Terminal, Test.HUnit.Text, Test.HUnit
      default-extensions: CPP

and the following ``Setup.hs``:

.. code-block:: haskell

    import Distribution.Simple
    main = defaultMain

Example: A package containing executable programs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

::

    name:           TestPackage
    version:        0.0
    synopsis:       Small package with two programs
    author:         Angela Author
    license:        BSD3
    build-type:     Simple
    cabal-version:  >= 1.8

    executable program1
      build-depends:  HUnit >= 1.1.1 && < 1.2
      main-is:        Main.hs
      hs-source-dirs: prog1

    executable program2
      main-is:        Main.hs
      build-depends:  HUnit >= 1.1.1 && < 1.2
      hs-source-dirs: prog2
      other-modules:  Utils

with ``Setup.hs`` the same as above.

Example: A package containing a library and executable programs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

::

    name:            TestPackage
    version:         0.0
    synopsis:        Package with library and two programs
    license:         BSD3
    author:          Angela Author
    build-type:      Simple
    cabal-version:   >= 1.8

    library
      build-depends:   HUnit >= 1.1.1 && < 1.2
      exposed-modules: A, B, C

    executable program1
      main-is:         Main.hs
      hs-source-dirs:  prog1
      other-modules:   A, B

    executable program2
      main-is:         Main.hs
      hs-source-dirs:  prog2
      other-modules:   A, C, Utils

with ``Setup.hs`` the same as above. Note that any library modules
required (directly or indirectly) by an executable must be listed again.

The trivial setup script used in these examples uses the *simple build
infrastructure* provided by the Cabal library (see
`Distribution.Simple <../release/cabal-latest/doc/API/Cabal/Distribution-Simple.html>`__).
The simplicity lies in its interface rather that its implementation. It
automatically handles preprocessing with standard preprocessors, and
builds packages for all the Haskell implementations.

The simple build infrastructure can also handle packages where building
is governed by system-dependent parameters, if you specify a little more
(see the section on `system-dependent parameters`_).
A few packages require `more elaborate solutions <more complex packages>`_.

.. _pkg-desc:

Package descriptions
--------------------

The package description file must have a name ending in "``.cabal``". It
must be a Unicode text file encoded using valid UTF-8. There must be
exactly one such file in the directory. The first part of the name is
usually the package name, and some of the tools that operate on Cabal
packages require this; specifically, Hackage rejects packages which
don't follow this rule.

In the package description file, lines whose first non-whitespace
characters are "``--``" are treated as comments and ignored.

Jan Hrček's avatar
Jan Hrček committed
211
This file should contain a number global property descriptions and
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
several sections.

-  The `package properties`_ describe the package
   as a whole, such as name, license, author, etc.

-  Optionally, a number of *configuration flags* can be declared. These
   can be used to enable or disable certain features of a package. (see
   the section on `configurations`_).

-  The (optional) library section specifies the `library`_ properties and
   relevant `build information`_.

-  Following is an arbitrary number of executable sections which describe
   an executable program and relevant `build information`_.

Each section consists of a number of property descriptions in the form
of field/value pairs, with a syntax roughly like mail message headers.

-  Case is not significant in field names, but is significant in field
   values.

-  To continue a field value, indent the next line relative to the field
   name.

-  Field names may be indented, but all field values in the same section
   must use the same indentation.

-  Tabs are *not* allowed as indentation characters due to a missing
   standard interpretation of tab width.

-  Before Cabal 3.0, to get a blank line in a field value, use an indented "``.``"

The syntax of the value depends on the field. Field types include:

*token*, *filename*, *directory*
    Either a sequence of one or more non-space non-comma characters, or
    a quoted string in Haskell 98 lexical syntax. The latter can be used
    for escaping whitespace, for example:
    ``ghc-options: -Wall "-with-rtsopts=-T -I1"``. Unless otherwise
    stated, relative filenames and directories are interpreted from the
    package root directory.
*freeform*, *URL*, *address*
    An arbitrary, uninterpreted string.
*identifier*
    A letter followed by zero or more alphanumerics or underscores.
*compiler*
    A compiler flavor (one of: ``GHC``, ``UHC`` or ``LHC``)
    followed by a version range. For example, ``GHC ==6.10.3``, or
    ``LHC >=0.6 && <0.8``.

Modules and preprocessors
^^^^^^^^^^^^^^^^^^^^^^^^^

Haskell module names listed in the :pkg-field:`library:exposed-modules` and
:pkg-field:`library:other-modules` fields may correspond to Haskell source
files, i.e. with names ending in "``.hs``" or "``.lhs``", or to inputs for
various Haskell preprocessors. The simple build infrastructure understands the
extensions:

-  ``.gc`` (:hackage-pkg:`greencard`)
-  ``.chs`` (:hackage-pkg:`c2hs`)
-  ``.hsc`` (:hackage-pkg:`hsc2hs`)
-  ``.y`` and ``.ly`` (happy_)
-  ``.x`` (alex_)
-  ``.cpphs`` (cpphs_)

When building, Cabal will automatically run the appropriate preprocessor
and compile the Haskell module it produces. For the ``c2hs`` and
``hsc2hs`` preprocessors, Cabal will also automatically add, compile and
link any C sources generated by the preprocessor (produced by
``hsc2hs``'s ``#def`` feature or ``c2hs``'s auto-generated wrapper
functions). Dependencies on pre-processors are specified via the
:pkg-field:`build-tools` or :pkg-field:`build-tool-depends` fields.

Some fields take lists of values, which are optionally separated by
commas, except for the :pkg-field:`build-depends` field, where the commas are
mandatory.

Some fields are marked as required. All others are optional, and unless
otherwise specified have empty default values.

Package properties
^^^^^^^^^^^^^^^^^^

These fields may occur in the first top-level properties section and
describe the package as a whole:

.. pkg-field:: name: package-name (required)

    The unique name of the package, without the version number.

    As pointed out in the section on `package descriptions`_, some
    tools require the package-name specified for this field to match
    the package description's file-name :file:`{package-name}.cabal`.

    Package names are case-sensitive and must match the regular expression
    (i.e. alphanumeric "words" separated by dashes; each alphanumeric
    word must contain at least one letter):
    ``[[:digit:]]*[[:alpha:]][[:alnum:]]*(-[[:digit:]]*[[:alpha:]][[:alnum:]]*)*``.

    Or, expressed in ABNF_:

    .. code-block:: abnf

        package-name      = package-name-part *("-" package-name-part)
        package-name-part = *DIGIT UALPHA *UALNUM

        UALNUM = UALPHA / DIGIT
        UALPHA = ... ; set of alphabetic Unicode code-points

    .. note::

        Hackage restricts package names to the ASCII subset.

.. pkg-field:: version: numbers (required)

    The package version number, usually consisting of a sequence of
    natural numbers separated by dots, i.e. as the regular
    expression ``[0-9]+([.][0-9]+)*`` or expressed in ABNF_:

    .. code-block:: abnf

        package-version = 1*DIGIT *("." 1*DIGIT)

.. pkg-field:: cabal-version: x.y[.z]

    The version of the Cabal specification that this package
    description uses. The Cabal specification does slowly evolve (see
    also :ref:`spec-history`), introducing new features and
Jan Hrček's avatar
Jan Hrček committed
341 342
    occasionally changing the meaning of existing features.
    Specifying which version of the specification you are using
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
    enables programs which process the package description to know
    what syntax to expect and what each part means.

    The version number you specify will affect both compatibility and
    behaviour. Most tools (including the Cabal library and the ``cabal``
    program) understand a range of versions of the Cabal specification.
    Older tools will of course only work with older versions of the
    Cabal specification that was known at the time. Most of the time,
    tools that are too old will recognise this fact and produce a
    suitable error message. Likewise, ``cabal check`` will tell you
    whether the version number is sufficiently high for the features
    you use in the package description.

    As for behaviour, new versions of the Cabal specification can change the
    meaning of existing syntax. This means if you want to take advantage
    of the new meaning or behaviour then you must specify the newer
    Cabal version. Tools are expected to use the meaning and behaviour
    appropriate to the version given in the package description.

    In particular, the syntax of package descriptions changed
    significantly with Cabal version 1.2 and the :pkg-field:`cabal-version`
    field is now required. Files written in the old syntax are still
    recognized, so if you require compatibility with very old Cabal
    versions then you may write your package description file using the
    old syntax. Please consult the user's guide of an older Cabal
    version for a description of that syntax.

    Starting with ``cabal-version: 2.2`` this field is only valid if
    fully contained in the very first line of a package description
    and ought to adhere to the ABNF_ grammar

    .. code-block:: abnf

        newstyle-spec-version-decl = "cabal-version" *WS ":" *WS newstyle-spec-version *WS

        newstyle-spec-version      = NUM "." NUM [ "." NUM ]

        NUM    = DIGIT0 / DIGITP 1*DIGIT0
        DIGIT0 = %x30-39
        DIGITP = %x31-39
        WS     = %20


    .. note::

        For package descriptions using a format prior to
        ``cabal-version: 1.12`` the legacy syntax resembling a version
        range syntax

        .. code-block:: cabal

            cabal-version: >= 1.10

        needs to be used.

        This legacy syntax is supported up until ``cabal-version: >=
        2.0`` it is however strongly recommended to avoid using the
        legacy syntax. See also :issue:`4899`.



.. pkg-field:: build-type: identifier

    :default: ``Custom`` or ``Simple``

    The type of build used by this package. Build types are the
    constructors of the
    `BuildType <../release/cabal-latest/doc/API/Cabal/Distribution-PackageDescription.html#t:BuildType>`__
    type. This field is optional and when missing, its default value
    is inferred according to the following rules:

     - When :pkg-field:`cabal-version` is set to ``2.2`` or higher,
       the default is ``Simple`` unless a :pkg-section:`custom-setup`
       exists, in which case the inferred default is ``Custom``.

     - For lower :pkg-field:`cabal-version` values, the default is
       ``Custom`` unconditionally.

    If the build type is anything other than ``Custom``, then the
    ``Setup.hs`` file *must* be exactly the standardized content
    discussed below. This is because in these cases, ``cabal`` will
    ignore the ``Setup.hs`` file completely, whereas other methods of
    package management, such as ``runhaskell Setup.hs [CMD]``, still
    rely on the ``Setup.hs`` file.

    For build type ``Simple``, the contents of ``Setup.hs`` must be:

    .. code-block:: haskell

        import Distribution.Simple
        main = defaultMain

    For build type ``Configure`` (see the section on `system-dependent
    parameters`_ below), the contents of
    ``Setup.hs`` must be:

    .. code-block:: haskell

        import Distribution.Simple
        main = defaultMainWithHooks autoconfUserHooks

    For build type ``Make`` (see the section on `more complex packages`_ below),
    the contents of ``Setup.hs`` must be:

    .. code-block:: haskell

        import Distribution.Make
        main = defaultMain

    For build type ``Custom``, the file ``Setup.hs`` can be customized,
    and will be used both by ``cabal`` and other tools.

    For most packages, the build type ``Simple`` is sufficient.

.. pkg-field:: license: SPDX expression

    :default: ``NONE``

    The type of license under which this package is distributed.

    Starting with ``cabal-version: 2.2`` the ``license`` field takes a
    (case-sensitive) SPDX expression such as

    .. code-block:: cabal

        license: Apache-2.0 AND (MIT OR GPL-2.0-or-later)

    See `SPDX IDs: How to use <https://spdx.org/ids-how>`__ for more
    examples of SPDX expressions.

    The version of the
    `list of SPDX license identifiers <https://spdx.org/licenses/>`__
    is a function of the :pkg-field:`cabal-version` value as defined
    in the following table:

    +--------------------------+--------------------+
    | Cabal specification      | SPDX license list  |
    | version                  | version            |
    |                          |                    |
    +==========================+====================+
    | ``cabal-version: 2.2``   | ``3.0 2017-12-28`` |
    +--------------------------+--------------------+
    | ``cabal-version: 2.4``   | ``3.2 2018-07-10`` |
    +--------------------------+--------------------+

    **Pre-SPDX Legacy Identifiers**

    The license identifier in the table below are defined for
    ``cabal-version: 2.0`` and previous versions of the Cabal
    specification.

    +--------------------------+-----------------+
    | :pkg-field:`license`     | Note            |
    | identifier               |                 |
    |                          |                 |
    +==========================+=================+
    | ``GPL``                  |                 |
    | ``GPL-2``                |                 |
    | ``GPL-3``                |                 |
    +--------------------------+-----------------+
    | ``LGPL``                 |                 |
    | ``LGPL-2.1``             |                 |
    | ``LGPL-3``               |                 |
    +--------------------------+-----------------+
    | ``AGPL``                 | since 1.18      |
    | ``AGPL-3``               |                 |
    +--------------------------+-----------------+
    | ``BSD2``                 | since 1.20      |
    +--------------------------+-----------------+
    | ``BSD3``                 |                 |
    +--------------------------+-----------------+
    | ``MIT``                  |                 |
    +--------------------------+-----------------+
    | ``ISC``                  | since 1.22      |
    +--------------------------+-----------------+
    | ``MPL-2.0``              | since 1.20      |
    +--------------------------+-----------------+
    | ``Apache``               |                 |
    | ``Apache-2.0``           |                 |
    +--------------------------+-----------------+
    | ``PublicDomain``         |                 |
    +--------------------------+-----------------+
    | ``AllRightsReserved``    |                 |
    +--------------------------+-----------------+
    | ``OtherLicense``         |                 |
    +--------------------------+-----------------+


.. pkg-field:: license-file: filename

    See :pkg-field:`license-files`.

.. pkg-field:: license-files: filename list
    :since: 1.20

    The name of a file(s) containing the precise copyright license for
    this package. The license file(s) will be installed with the
    package.

    If you have multiple license files then use the :pkg-field:`license-files`
    field instead of (or in addition to) the :pkg-field:`license-file` field.

.. pkg-field:: copyright: freeform

    The content of a copyright notice, typically the name of the holder
    of the copyright on the package and the year(s) from which copyright
    is claimed. For example::

      copyright: (c) 2006-2007 Joe Bloggs

.. pkg-field:: author: freeform

    The original author of the package.

    Remember that ``.cabal`` files are Unicode, using the UTF-8
    encoding.

.. pkg-field:: maintainer: address

    The current maintainer or maintainers of the package. This is an
    e-mail address to which users should send bug reports, feature
    requests and patches.

.. pkg-field:: stability: freeform

    The stability level of the package, e.g. ``alpha``,
    ``experimental``, ``provisional``, ``stable``.

.. pkg-field:: homepage: URL

    The package homepage.

.. pkg-field:: bug-reports: URL

    The URL where users should direct bug reports. This would normally
    be either:

    -  A ``mailto:`` URL, e.g. for a person or a mailing list.

    -  An ``http:`` (or ``https:``) URL for an online bug tracking
       system.

    For example Cabal itself uses a web-based bug tracking system

    ::

        bug-reports: https://github.com/haskell/cabal/issues

.. pkg-field:: package-url: URL

    The location of a source bundle for the package. The distribution
    should be a Cabal package.

.. pkg-field:: synopsis: freeform

    A very short description of the package, for use in a table of
    packages. This is your headline, so keep it short (one line) but as
    informative as possible. Save space by not including the package
    name or saying it's written in Haskell.

.. pkg-field:: description: freeform

    Description of the package. This may be several paragraphs, and
    should be aimed at a Haskell programmer who has never heard of your
    package before.

    For library packages, this field is used as prologue text by
    :ref:`setup-haddock` and thus may contain the same markup as Haddock_
    documentation comments.

.. pkg-field:: category: freeform

    A classification category for future use by the package catalogue
    Hackage_. These categories have not
    yet been specified, but the upper levels of the module hierarchy
    make a good start.

.. pkg-field:: tested-with: compiler list

    A list of compilers and versions against which the package has been
    tested (or at least built). The value of this field is not used by Cabal
    and is rather intended as extra metadata for use by third party
    tooling, such as e.g. CI tooling.

    Here's a typical usage example

    ::

        tested-with: GHC == 8.6.3, GHC == 8.4.4, GHC == 8.2.2, GHC == 8.0.2,
                     GHC == 7.10.3, GHC == 7.8.4, GHC == 7.6.3, GHC == 7.4.2

    which can (starting with Cabal 3.0) also be written using the more
    concise set notation syntax

    ::

        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 }

.. pkg-field:: data-files: filename list

    A list of files to be installed for run-time use by the package.
    This is useful for packages that use a large amount of static data,
    such as tables of values or code templates. Cabal provides a way to
    `find these files at run-time <#accessing-data-files-from-package-code>`_.

    A limited form of ``*`` wildcards in file names, for example
    ``data-files: images/*.png`` matches all the ``.png`` files in the
    ``images`` directory. ``data-files: audio/**/*.mp3`` matches all
    the ``.mp3`` files in the ``audio`` directory, including
    subdirectories.

    The specific limitations of this wildcard syntax are

    - ``*`` wildcards are only allowed in place of the file name, not
      in the directory name or file extension. It must replace the
      whole file name (e.g., ``*.html`` is allowed, but
      ``chapter-*.html`` is not). If a wildcard is used, it must be
      used with an extension, so ``data-files: data/*`` is not
      allowed.

    - Prior to Cabal 2.4, when matching a wildcard plus extension, a
      file's full extension must match exactly, so ``*.gz`` matches
      ``foo.gz`` but not ``foo.tar.gz``. This restriction has been
      lifted when ``cabal-version: 2.4`` or greater so that ``*.gz``
      does match ``foo.tar.gz``

    - ``*`` wildcards will not match if the file name is empty (e.g.,
      ``*.html`` will not match ``foo/.html``).

    - ``**`` wildcards can only appear as the final path component
      before the file name (e.g., ``data/**/images/*.jpg`` is not
      allowed). If a ``**`` wildcard is used, then the file name must
      include a ``*`` wildcard (e.g., ``data/**/README.rst`` is not
      allowed).

    - A wildcard that does not match any files is an error.

    The reason for providing only a very limited form of wildcard is to
    concisely express the common case of a large number of related files
    of the same file type without making it too easy to accidentally
    include unwanted files.

    On efficiency: if you use ``**`` patterns, the directory tree will
    be walked starting with the parent directory of the ``**``. If
    that's the root of the project, this might include ``.git/``,
    ``dist-newstyle/``, or other large directories! To avoid this
    behaviour, put the files that wildcards will match against in
    their own folder.

    ``**`` wildcards are available starting in Cabal 2.4.

.. pkg-field:: data-dir: directory

    The directory where Cabal looks for data files to install, relative
    to the source directory. By default, Cabal will look in the source
    directory itself.

.. pkg-field:: extra-source-files: filename list

    A list of additional files to be included in source distributions
    built with :ref:`setup-sdist`. As with :pkg-field:`data-files` it can use
    a limited form of ``*`` wildcards in file names.

.. pkg-field:: extra-doc-files: filename list
    :since: 1.18

    A list of additional files to be included in source distributions,
    and also copied to the html directory when Haddock documentation is
    generated. As with :pkg-field:`data-files` it can use a limited form of
    ``*`` wildcards in file names.

.. pkg-field:: extra-tmp-files: filename list

    A list of additional files or directories to be removed by
    :ref:`setup-clean`. These  would typically be additional files created by
    additional hooks, such as the scheme described in the section on
    `system-dependent parameters`_

Library
^^^^^^^

.. pkg-section:: library name
    :synopsis: Library build information.

    Build information for libraries.

    Currently, there can only be one publicly exposed library in a
    package, and its name is the same as package name set by global
    :pkg-field:`name` field. In this case, the ``name`` argument to
    the :pkg-section:`library` section must be omitted.

    Starting with Cabal 2.0, private internal sub-library components
Jan Hrček's avatar
Jan Hrček committed
735
    can be defined by setting the ``name`` field to a name
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
    different from the current package's name; see section on
    :ref:`Internal Libraries <sublibs>` for more information.

The library section should contain the following fields:

.. pkg-field:: exposed-modules: identifier list

    :required: if this package contains a library

    A list of modules added by this package.

.. pkg-field:: virtual-modules: identifier list
    :since: 2.2

    A list of virtual modules provided by this package.  Virtual modules
    are modules without a source file.  See for example the ``GHC.Prim``
    module from the ``ghc-prim`` package.  Modules listed here will not be
    built, but still end up in the list of ``exposed-modules`` in the
    installed package info when the package is registered in the package
    database.

.. pkg-field:: exposed: boolean

    :default: ``True``

    Some Haskell compilers (notably GHC) support the notion of packages
    being "exposed" or "hidden" which means the modules they provide can
    be easily imported without always having to specify which package
    they come from. However this only works effectively if the modules
    provided by all exposed packages do not overlap (otherwise a module
    import would be ambiguous).

    Almost all new libraries use hierarchical module names that do not
    clash, so it is very uncommon to have to use this field. However it
    may be necessary to set ``exposed: False`` for some old libraries
    that use a flat module namespace or where it is known that the
    exposed modules would clash with other common modules.

Jan Hrček's avatar
Jan Hrček committed
774
.. pkg-field:: visibility: visibility specifiers
775

Jan Hrček's avatar
Jan Hrček committed
776
    :since: 3.0
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406

    :default: ``private`` for internal libraries. Cannot be set for public library.

    Cabal recognizes ``public`` and ``private`` here...

    Multiple public libraries...

.. pkg-field:: reexported-modules: exportlist
    :since: 1.22

    Supported only in GHC 7.10 and later. A list of modules to
    *reexport* from this package. The syntax of this field is
    ``orig-pkg:Name as NewName`` to reexport module ``Name`` from
    ``orig-pkg`` with the new name ``NewName``. We also support
    abbreviated versions of the syntax: if you omit ``as NewName``,
    we'll reexport without renaming; if you omit ``orig-pkg``, then we
    will automatically figure out which package to reexport from, if
    it's unambiguous.

    Reexported modules are useful for compatibility shims when a package
    has been split into multiple packages, and they have the useful
    property that if a package provides a module, and another package
    reexports it under the same name, these are not considered a
    conflict (as would be the case with a stub module.) They can also be
    used to resolve name conflicts.

.. pkg-field:: signatures: signature list
    :since: 2.0

    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.

    Module signatures are part of the Backpack_ extension to
    the Haskell module system.

    Packages that do not export any modules and only export required signatures
    are called "signature-only packages", and their signatures are subjected to
    `signature thinning
    <https://wiki.haskell.org/Module_signature#How_to_use_a_signature_package>`__.



The library section may also contain build information fields (see the
section on `build information`_).

.. _sublibs:

**Internal Libraries**

Cabal 2.0 and later support "internal libraries", which are extra named
libraries (as opposed to the usual unnamed library section). For
example, suppose that your test suite needs access to some internal
modules in your library, which you do not otherwise want to export. You
could put these modules in an internal library, which the main library
and the test suite :pkg-field:`build-depends` upon. Then your Cabal file might
look something like this:

::

    cabal-version:  2.0
    name:           foo
    version:        0.1.0.0
    license:        BSD3
    build-type:     Simple

    library foo-internal
        exposed-modules: Foo.Internal
        -- NOTE: no explicit constraints on base needed
        --       as they're inherited from the 'library' stanza
        build-depends: base

    library
        exposed-modules: Foo.Public
        build-depends: foo-internal, base >= 4.3 && < 5

    test-suite test-foo
        type:       exitcode-stdio-1.0
        main-is:    test-foo.hs
        -- NOTE: no constraints on 'foo-internal' as same-package
        --       dependencies implicitly refer to the same package instance
        build-depends: foo-internal, base

Internal libraries are also useful for packages that define multiple
executables, but do not define a publicly accessible library. Internal
libraries are only visible internally in the package (so they can only
be added to the :pkg-field:`build-depends` of same-package libraries,
executables, test suites, etc.) Internal libraries locally shadow any
packages which have the same name; consequently, don't name an internal
library with the same name as an external dependency if you need to be
able to refer to the external dependency in a
:pkg-field:`build-depends` declaration.

Shadowing can be used to vendor an external dependency into a package
and thus emulate *private dependencies*. Below is an example based on
a real-world use case:

::

    cabal-version: 2.2
    name: haddock-library
    version: 1.6.0

    library
      build-depends:
        , base         ^>= 4.11.1.0
        , bytestring   ^>= 0.10.2.0
        , containers   ^>= 0.4.2.1 || ^>= 0.5.0.0
        , transformers ^>= 0.5.0.0

      hs-source-dirs:       src

      -- internal sub-lib
      build-depends:        attoparsec

      exposed-modules:
        Documentation.Haddock

    library attoparsec
      build-depends:
        , base         ^>= 4.11.1.0
        , bytestring   ^>= 0.10.2.0
        , deepseq      ^>= 1.4.0.0

      hs-source-dirs:       vendor/attoparsec-0.13.1.0

      -- NB: haddock-library needs only small part of lib:attoparsec
      --     internally, so we only bundle that subset here
      exposed-modules:
        Data.Attoparsec.ByteString
        Data.Attoparsec.Combinator

      other-modules:
        Data.Attoparsec.Internal

      ghc-options: -funbox-strict-fields -Wall -fwarn-tabs -O2


Opening an interpreter session
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

While developing a package, it is often useful to make its code
available inside an interpreter session. This can be done with the
``repl`` command:

.. code-block:: console

    $ cabal repl

The name comes from the acronym
`REPL <http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop>`__,
which stands for "read-eval-print-loop". By default ``cabal repl`` loads
the first component in a package. If the package contains several named
components, the name can be given as an argument to ``repl``. The name
can be also optionally prefixed with the component's type for
disambiguation purposes. Example:

.. code-block:: console

    $ cabal repl foo
    $ cabal repl exe:foo
    $ cabal repl test:bar
    $ cabal repl bench:baz

Freezing dependency versions
""""""""""""""""""""""""""""

If a package is built in several different environments, such as a
development environment, a staging environment and a production
environment, it may be necessary or desirable to ensure that the same
dependency versions are selected in each environment. This can be done
with the ``freeze`` command:

.. code-block:: console

    $ cabal freeze

The command writes the selected version for all dependencies to the
``cabal.config`` file. All environments which share this file will use
the dependency versions specified in it.

Generating dependency version bounds
""""""""""""""""""""""""""""""""""""

Cabal also has the ability to suggest dependency version bounds that
conform to `Package Versioning Policy`_, which is
a recommended versioning system for publicly released Cabal packages.
This is done by running the ``gen-bounds`` command:

.. code-block:: console

    $ cabal gen-bounds

For example, given the following dependencies specified in
:pkg-field:`build-depends`:

::

    build-depends:
      foo == 0.5.2
      bar == 1.1

``gen-bounds`` will suggest changing them to the following:

::

    build-depends:
      foo >= 0.5.2 && < 0.6
      bar >= 1.1 && < 1.2

Listing outdated dependency version bounds
""""""""""""""""""""""""""""""""""""""""""

Manually updating dependency version bounds in a ``.cabal`` file or a
freeze file can be tedious, especially when there's a lot of
dependencies. The ``cabal outdated`` command is designed to help with
that. It will print a list of packages for which there is a new
version on Hackage that is outside the version bound specified in the
``build-depends`` field. The ``outdated`` command can also be
configured to act on the freeze file (both old- and v2-style) and
ignore major (or all) version bumps on Hackage for a subset of
dependencies.

The following flags are supported by the ``outdated`` command:

``--freeze-file``
    Read dependency version bounds from the freeze file (``cabal.config``)
    instead of the package description file (``$PACKAGENAME.cabal``).
    ``--v1-freeze-file`` is an alias for this flag starting in Cabal 2.4.
``--v2-freeze-file``
    :since: 2.4

    Read dependency version bounds from the v2-style freeze file
    (by default, ``cabal.project.freeze``) instead of the package
    description file. ``--new-freeze-file`` is an alias for this flag
    that can be used with pre-2.4 ``cabal``.
``--project-file`` *PROJECTFILE*
    :since: 2.4

    Read dependendency version bounds from the v2-style freeze file
    related to the named project file (i.e., ``$PROJECTFILE.freeze``)
    instead of the package desctription file. If multiple ``--project-file``
    flags are provided, only the final one is considered. This flag
    must only be passed in when ``--new-freeze-file`` is present.
``--simple-output``
    Print only the names of outdated dependencies, one per line.
``--exit-code``
    Exit with a non-zero exit code when there are outdated dependencies.
``-q, --quiet``
    Don't print any output. Implies ``-v0`` and ``--exit-code``.
``--ignore`` *PACKAGENAMES*
    Don't warn about outdated dependency version bounds for the packages in this
    list.
``--minor`` *[PACKAGENAMES]*
    Ignore major version bumps for these packages. E.g. if there's a version 2.0
    of a package ``pkg`` on Hackage and the freeze file specifies the constraint
    ``pkg == 1.9``, ``cabal outdated --freeze --minor=pkg`` will only consider
    the ``pkg`` outdated when there's a version of ``pkg`` on Hackage satisfying
    ``pkg > 1.9 && < 2.0``. ``--minor`` can also be used without arguments, in
    that case major version bumps are ignored for all packages.

Examples:

.. code-block:: console

    $ cd /some/package
    $ cabal outdated
    Outdated dependencies:
    haskell-src-exts <1.17 (latest: 1.19.1)
    language-javascript <0.6 (latest: 0.6.0.9)
    unix ==2.7.2.0 (latest: 2.7.2.1)

    $ cabal outdated --simple-output
    haskell-src-exts
    language-javascript
    unix

    $ cabal outdated --ignore=haskell-src-exts
    Outdated dependencies:
    language-javascript <0.6 (latest: 0.6.0.9)
    unix ==2.7.2.0 (latest: 2.7.2.1)

    $ cabal outdated --ignore=haskell-src-exts,language-javascript,unix
    All dependencies are up to date.

    $ cabal outdated --ignore=haskell-src-exts,language-javascript,unix -q
    $ echo $?
    0

    $ cd /some/other/package
    $ cabal outdated --freeze-file
    Outdated dependencies:
    HTTP ==4000.3.3 (latest: 4000.3.4)
    HUnit ==1.3.1.1 (latest: 1.5.0.0)

    $ cabal outdated --freeze-file --ignore=HTTP --minor=HUnit
    Outdated dependencies:
    HUnit ==1.3.1.1 (latest: 1.3.1.2)


Executables
^^^^^^^^^^^

.. pkg-section:: executable name
    :synopsis: Executable build info section.

    Executable sections (if present) describe executable programs contained
    in the package and must have an argument after the section label, which
    defines the name of the executable. This is a freeform argument but may
    not contain spaces.

The executable may be described using the following fields, as well as
build information fields (see the section on `build information`_).

.. pkg-field:: main-is: filename (required)

    The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
    module. Note that it is the ``.hs`` filename that must be listed,
    even if that file is generated using a preprocessor. The source file
    must be relative to one of the directories listed in
    :pkg-field:`hs-source-dirs`. Further, while the name of the file may
    vary, the module itself must be named ``Main``.

    Starting with ``cabal-version: 1.18`` this field supports
    specifying a C, C++, or objC source file as the main entry point.

.. pkg-field:: scope: token
    :since: 2.0

    Whether the executable is ``public`` (default) or ``private``, i.e. meant to
    be run by other programs rather than the user. Private executables are
    installed into `$libexecdir/$libexecsubdir`.

Running executables
"""""""""""""""""""

You can have Cabal build and run your executables by using the ``run``
command:

.. code-block:: console

    $ cabal run EXECUTABLE [-- EXECUTABLE_FLAGS]

This command will configure, build and run the executable
``EXECUTABLE``. The double dash separator is required to distinguish
executable flags from ``run``'s own flags. If there is only one
executable defined in the whole package, the executable's name can be
omitted. See the output of ``cabal help run`` for a list of options you
can pass to ``cabal run``.

Test suites
^^^^^^^^^^^

.. pkg-section:: test-suite name
    :synopsis: Test suite build information.

    Test suite sections (if present) describe package test suites and must
    have an argument after the section label, which defines the name of the
    test suite. This is a freeform argument, but may not contain spaces. It
    should be unique among the names of the package's other test suites, the
    package's executables, and the package itself. Using test suite sections
    requires at least Cabal version 1.9.2.

The test suite may be described using the following fields, as well as
build information fields (see the section on `build information`_).

.. pkg-field:: type: interface (required)

    The interface type and version of the test suite. Cabal supports two
    test suite interfaces, called ``exitcode-stdio-1.0`` and
    ``detailed-0.9``. Each of these types may require or disallow other
    fields as described below.

Test suites using the ``exitcode-stdio-1.0`` interface are executables
that indicate test failure with a non-zero exit code when run; they may
provide human-readable log information through the standard output and
error channels. The ``exitcode-stdio-1.0`` type requires the ``main-is``
field.

.. pkg-field:: main-is: filename
    :synopsis: Module containing tests main function.

    :required: ``exitcode-stdio-1.0``
    :disallowed: ``detailed-0.9``

    The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
    module. Note that it is the ``.hs`` filename that must be listed,
    even if that file is generated using a preprocessor. The source file
    must be relative to one of the directories listed in
    :pkg-field:`hs-source-dirs`. This field is analogous to the ``main-is`` field
    of an executable section.

Test suites using the ``detailed-0.9`` interface are modules exporting
the symbol ``tests :: IO [Test]``. The ``Test`` type is exported by the
module ``Distribution.TestSuite`` provided by Cabal. For more details,
see the example below.

The ``detailed-0.9`` interface allows Cabal and other test agents to
inspect a test suite's results case by case, producing detailed human-
and machine-readable log files. The ``detailed-0.9`` interface requires
the :pkg-field:`test-module` field.

.. pkg-field:: test-module: identifier

    :required: ``detailed-0.9``
    :disallowed: ``exitcode-stdio-1.0``

    The module exporting the ``tests`` symbol.

Example: Package using ``exitcode-stdio-1.0`` interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""

The example package description and executable source file below
demonstrate the use of the ``exitcode-stdio-1.0`` interface.

.. code-block:: cabal
    :caption: foo.cabal

    Name:           foo
    Version:        1.0
    License:        BSD3
    Cabal-Version:  >= 1.9.2
    Build-Type:     Simple

    Test-Suite test-foo
        type:       exitcode-stdio-1.0
        main-is:    test-foo.hs
        build-depends: base >= 4 && < 5

.. code-block:: haskell
    :caption: test-foo.hs

    module Main where

    import System.Exit (exitFailure)

    main = do
        putStrLn "This test always fails!"
        exitFailure

Example: Package using ``detailed-0.9`` interface
"""""""""""""""""""""""""""""""""""""""""""""""""

The example package description and test module source file below
demonstrate the use of the ``detailed-0.9`` interface. The test module
also develops a simple implementation of the interface set by
``Distribution.TestSuite``, but in actual usage the implementation would
be provided by the library that provides the testing facility.

.. code-block:: cabal
    :caption: bar.cabal

    Name:           bar
    Version:        1.0
    License:        BSD3
    Cabal-Version:  >= 1.9.2
    Build-Type:     Simple

    Test-Suite test-bar
        type:       detailed-0.9
        test-module: Bar
        build-depends: base >= 4 && < 5, Cabal >= 1.9.2 && < 2


.. code-block:: haskell
    :caption: Bar.hs

    module Bar ( tests ) where

    import Distribution.TestSuite

    tests :: IO [Test]
    tests = return [ Test succeeds, Test fails ]
      where
        succeeds = TestInstance
            { run = return $ Finished Pass
            , name = "succeeds"
            , tags = []
            , options = []
            , setOption = \_ _ -> Right succeeds
            }
        fails = TestInstance
            { run = return $ Finished $ Fail "Always fails!"
            , name = "fails"
            , tags = []
            , options = []
            , setOption = \_ _ -> Right fails
            }

Running test suites
"""""""""""""""""""

You can have Cabal run your test suites using its built-in test runner:

::

    $ cabal configure --enable-tests
    $ cabal build
    $ cabal test

See the output of ``cabal help test`` for a list of options you can pass
to ``cabal test``.

Benchmarks
^^^^^^^^^^

.. pkg-section:: benchmark name
    :since: 1.9.2
    :synopsis: Benchmark build information.

    Benchmark sections (if present) describe benchmarks contained in the
    package and must have an argument after the section label, which defines
    the name of the benchmark. This is a freeform argument, but may not
    contain spaces. It should be unique among the names of the package's
    other benchmarks, the package's test suites, the package's executables,
    and the package itself. Using benchmark sections requires at least Cabal
    version 1.9.2.

The benchmark may be described using the following fields, as well as
build information fields (see the section on `build information`_).

.. pkg-field:: type: interface (required)

    The interface type and version of the benchmark. At the moment Cabal
    only support one benchmark interface, called ``exitcode-stdio-1.0``.

Benchmarks using the ``exitcode-stdio-1.0`` interface are executables
that indicate failure to run the benchmark with a non-zero exit code
when run; they may provide human-readable information through the
standard output and error channels.

.. pkg-field:: main-is: filename

    :required: ``exitcode-stdio-1.0``

    The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
    module. Note that it is the ``.hs`` filename that must be listed,
    even if that file is generated using a preprocessor. The source file
    must be relative to one of the directories listed in
    :pkg-field:`hs-source-dirs`. This field is analogous to the ``main-is``
    field of an executable section. Further, while the name of the file may
    vary, the module itself must be named ``Main``.

Example: Package using ``exitcode-stdio-1.0`` interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""

The example package description and executable source file below
demonstrate the use of the ``exitcode-stdio-1.0`` interface.

.. code-block:: cabal
    :caption: foo.cabal
    :name: foo-bench.cabal

    Name:           foo
    Version:        1.0
    License:        BSD3
    Cabal-Version:  >= 1.9.2
    Build-Type:     Simple

    Benchmark bench-foo
        type:       exitcode-stdio-1.0
        main-is:    bench-foo.hs
        build-depends: base >= 4 && < 5, time >= 1.1 && < 1.7

.. code-block:: haskell
    :caption: bench-foo.hs

    {-# LANGUAGE BangPatterns #-}
    module Main where

    import Data.Time.Clock

    fib 0 = 1
    fib 1 = 1
    fib n = fib (n-1) + fib (n-2)

    main = do
        start <- getCurrentTime
        let !r = fib 20
        end <- getCurrentTime
        putStrLn $ "fib 20 took " ++ show (diffUTCTime end start)

Running benchmarks
""""""""""""""""""

You can have Cabal run your benchmark using its built-in benchmark
runner:

::

    $ cabal configure --enable-benchmarks
    $ cabal build
    $ cabal bench

See the output of ``cabal help bench`` for a list of options you can
pass to ``cabal bench``.

Foreign libraries
^^^^^^^^^^^^^^^^^

Foreign libraries are system libraries intended to be linked against
programs written in C or other "foreign" languages. They
come in two primary flavours: dynamic libraries (``.so`` files on Linux,
``.dylib`` files on OSX, ``.dll`` files on Windows, etc.) are linked against
executables when the executable is run (or even lazily during
execution), while static libraries (``.a`` files on Linux/OSX, ``.lib``
files on Windows) get linked against the executable at compile time.

Foreign libraries only work with GHC 7.8 and later.

A typical stanza for a foreign library looks like

::

    foreign-library myforeignlib
      type:                native-shared
      lib-version-info:    6:3:2

      if os(Windows)
        options: standalone
        mod-def-file: MyForeignLib.def

      other-modules:       MyForeignLib.SomeModule
                           MyForeignLib.SomeOtherModule
      build-depends:       base >=4.7 && <4.9
      hs-source-dirs:      src
      c-sources:           csrc/MyForeignLibWrapper.c
      default-language:    Haskell2010


.. pkg-section:: foreign-library name
    :since: 2.0
Jan Hrček's avatar
Jan Hrček committed
1407
    :synopsis: Foreign library build information.
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532

    Build information for `foreign libraries`_.

.. pkg-field:: type: foreign library type

   Cabal recognizes ``native-static`` and ``native-shared`` here, although
   we currently only support building `native-shared` libraries.

.. pkg-field:: options: foreign library option list

   Options for building the foreign library, typically specific to the
   specified type of foreign library. Currently we only support
   ``standalone`` here. A standalone dynamic library is one that does not
   have any dependencies on other (Haskell) shared libraries; without
   the ``standalone`` option the generated library would have dependencies
   on the Haskell runtime library (``libHSrts``), the base library
   (``libHSbase``), etc. Currently, ``standalone`` *must* be used on Windows
   and *must not* be used on any other platform.

.. pkg-field:: mod-def-file: filename

   This option can only be used when creating dynamic Windows libraries
   (that is, when using ``native-shared`` and the ``os`` is ``Windows``). If
   used, it must be a path to a *module definition file*. The details of
   module definition files are beyond the scope of this document; see the
   `GHC <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/win32-dlls.html>`_
   manual for some details and some further pointers.

.. pkg-field:: lib-version-info: current:revision:age

   This field is currently only used on Linux.

   This field specifies a Libtool-style version-info field that sets
   an appropriate ABI version for the foreign library. Note that the
   three numbers specified in this field do not directly specify the
   actual ABI version: ``6:3:2`` results in library version ``4.2.3``.

   With this field set, the SONAME of the library is set, and symlinks
   are installed.

   How you should bump this field on an ABI change depends on the
   breakage you introduce:

   -  Programs using the previous version may use the new version as
      drop-in replacement, and programs using the new version can also
      work with the previous one. In other words, no recompiling nor
      relinking is needed. In this case, bump ``revision`` only, don't
      touch current nor age.
   -  Programs using the previous version may use the new version as
      drop-in replacement, but programs using the new version may use
      APIs not present in the previous one. In other words, a program
      linking against the new version may fail with "unresolved
      symbols" if linking against the old version at runtime: set
      revision to 0, bump current and age.
   -  Programs may need to be changed, recompiled, and relinked in
      order to use the new version. Bump current, set revision and age
      to 0.

   Also refer to the Libtool documentation on the version-info field.

.. pkg-field:: lib-version-linux: version

   This field is only used on Linux.

   Specifies the library ABI version directly for foreign libraries
   built on Linux: so specifying ``4.2.3`` causes a library
   ``libfoo.so.4.2.3`` to be built with SONAME ``libfoo.so.4``, and
   appropriate symlinks ``libfoo.so.4`` and ``libfoo.so`` to be
   installed.

Note that typically foreign libraries should export a way to initialize
and shutdown the Haskell runtime. In the example above, this is done by
the ``csrc/MyForeignLibWrapper.c`` file, which might look something like

.. code-block:: c

    #include <stdlib.h>
    #include "HsFFI.h"

    HsBool myForeignLibInit(void){
      int argc = 2;
      char *argv[] = { "+RTS", "-A32m", NULL };
      char **pargv = argv;

      // Initialize Haskell runtime
      hs_init(&argc, &pargv);

      // do any other initialization here and
      // return false if there was a problem
      return HS_BOOL_TRUE;
    }

    void myForeignLibExit(void){
      hs_exit();
    }

With modern ghc regular libraries are installed in directories that contain
package keys. This isn't usually a problem because the package gets registered
in ghc's package DB and so we can figure out what the location of the library
is. Foreign libraries however don't get registered, which means that we'd have
to have a way of finding out where a platform library got installed (other than by
searching the ``lib/`` directory). Instead, we install foreign libraries in
``~/.cabal/lib``, much like we install executables in ``~/.cabal/bin``.

Build information
^^^^^^^^^^^^^^^^^
.. pkg-section:: None

The following fields may be optionally present in a library, executable,
test suite or benchmark section, and give information for the building
of the corresponding library or executable. See also the sections on
`system-dependent parameters`_ and `configurations`_ for a way to supply
system-dependent values for these fields.

.. pkg-field:: build-depends: library list

    Declares the *library* dependencies required to build the current
    package component; see :pkg-field:`build-tool-depends` for
    declaring build-time *tool* dependencies. External library
    dependencies should be annotated with a version constraint.

    **Library Names**

    External libraries are identified by the package's name they're
    provided by (currently a package can only publicly expose its
Jan Hrček's avatar
Jan Hrček committed
1533
    main library component; in future, packages with multiple exposed
1534 1535 1536 1537 1538
    public library components will be supported and a syntax for
    referring to public sub-libraries will be provided).

    In order to specify an intra-package dependency on an internal
    library component you can use the unqualified name of the
1539
    library component. Note that locally defined sub-library
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
    names shadow external package names of the same name. See section on
    :ref:`Internal Libraries <sublibs>` for examples and more information.

    **Version Constraints**

    Version constraints use the operators ``==, >=, >, <, <=`` and a
    version number. Multiple constraints can be combined using ``&&`` or
    ``||``. If no version constraint is specified, any version is
    assumed to be acceptable. For example:

    ::

        library
          build-depends:
            base >= 2,
            foo >= 1.2.3 && < 1.3,
            bar

    Dependencies like ``foo >= 1.2.3 && < 1.3`` turn out to be very
1559
    common because it is recommended practice for package versions to
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
    correspond to API versions (see PVP_).

    Since Cabal 1.6, there is a special wildcard syntax to help with
    such ranges

    ::

        build-depends: foo ==1.2.*

    It is only syntactic sugar. It is exactly equivalent to
    ``foo >= 1.2 && < 1.3``.

    .. Warning::

       A potential pitfall of the wildcard syntax is that the
       constraint ``nats == 1.0.*`` doesn't match the release
       ``nats-1`` because the version ``1`` is lexicographically less
       than ``1.0``. This is not an issue with the caret-operator
       ``^>=`` described below.

    Starting with Cabal 2.0, there's a new version operator to express
    PVP_-style major upper bounds conveniently, and is inspired by similar
    syntactic sugar found in other language ecosystems where it's often
    called the "Caret" operator:

    ::

        build-depends:
          foo ^>= 1.2.3.4,
          bar ^>= 1

    This allows to assert the positive knowledge that this package is
    *known* to be semantically compatible with the releases
    ``foo-1.2.3.4`` and ``bar-1`` respectively. The information
    encoded via such ``^>=``-assertions is used by the cabal solver to
    infer version constraints describing semantically compatible
    version ranges according to the PVP_ contract (see below).

    Another way to say this is that ``foo < 1.3`` expresses *negative*
    information, i.e. "``foo-1.3`` or ``foo-1.4.2`` will *not* be
    compatible"; whereas ``foo ^>= 1.2.3.4`` asserts the *positive*
    information that "``foo-1.2.3.4`` is *known* to be compatible" and (in
    the absence of additional information) according to the PVP_
    contract we can (positively) infer right away that all versions
    satisfying ``foo >= 1.2.3.4 && < 1.3`` will be compatible as well.

    .. Note::

       More generally, the PVP_ contract implies that we can safely
       relax the lower bound to ``>= 1.2``, because if we know that
       ``foo-1.2.3.4`` is semantically compatible, then so is
       ``foo-1.2`` (if it typechecks). But we'd need to perform
       additional static analysis (i.e. perform typechecking) in order
       to know if our package in the role of an API consumer will
       successfully typecheck against the dependency ``foo-1.2``.  But
       since we cannot do this analysis during constraint solving and
       to keep things simple, we pragmatically use ``foo >= 1.2.3.4``
       as the initially inferred approximation for the lower bound
       resulting from the assertion ``foo ^>= 1.2.3.4``. If further
       evidence becomes available that e.g. ``foo-1.2`` typechecks,
       one can simply revise the dependency specification to include
       the assertion ``foo ^>= 1.2``.

    The subtle but important difference in signaling allows tooling to
    treat explicitly expressed ``<``-style constraints and inferred
    (``^>=``-style) upper bounds differently.  For instance,
    :option:`--allow-newer`'s ``^``-modifier allows to relax only
    ``^>=``-style bounds while leaving explicitly stated
    ``<``-constraints unaffected.

    Ignoring the signaling intent, the default syntactic desugaring rules are

    - ``^>= x`` == ``>= x && < x.1``
    - ``^>= x.y`` == ``>= x.y && < x.(y+1)``
    - ``^>= x.y.z`` == ``>= x.y.z && < x.(y+1)``
    - ``^>= x.y.z.u`` == ``>= x.y.z.u && < x.(y+1)``
    - etc.

    .. Note::

1640
       One might expect the desugaring to truncate all version
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786
       components below (and including) the patch-level, i.e.
       ``^>= x.y.z.u`` == ``>= x.y.z && < x.(y+1)``,
       as the major and minor version components alone are supposed to
       uniquely identify the API according to the PVP_.  However, by
       designing ``^>=`` to be closer to the ``>=`` operator, we avoid
       the potentially confusing effect of ``^>=`` being more liberal
       than ``>=`` in the presence of patch-level versions.

    Consequently, the example declaration above is equivalent to

    ::

        build-depends:
          foo >= 1.2.3.4 && < 1.3,
          bar >= 1 && < 1.1

    .. Note::

       Prior to Cabal 1.8, ``build-depends`` specified in each
       section were global to all sections. This was unintentional, but
       some packages were written to depend on it, so if you need your
       :pkg-field:`build-depends` to be local to each section, you must specify
       at least ``Cabal-Version: >= 1.8`` in your ``.cabal`` file.

    .. Note::

       Cabal 1.20 experimentally supported module thinning and
       renaming in ``build-depends``; however, this support has since been
       removed and should not be used.

    Starting with Cabal 3.0, a set notation for the ``==`` and ``^>=`` operator
    is available. For instance,

    ::

        tested-with: GHC == 8.6.3, GHC == 8.4.4, GHC == 8.2.2, GHC == 8.0.2,
                     GHC == 7.10.3, GHC == 7.8.4, GHC == 7.6.3, GHC == 7.4.2

        build-depends: network ^>= 2.6.3.6 || ^>= 2.7.0.2 || ^>= 2.8.0.0 || ^>= 3.0.1.0

    can be then written in a more convenient and concise form

    ::

        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 }

        build-depends: network ^>= { 2.6.3.6, 2.7.0.2, 2.8.0.0, 3.0.1.0 }


.. pkg-field:: other-modules: identifier list

    A list of modules used by the component but not exposed to users.
    For a library component, these would be hidden modules of the
    library. For an executable, these would be auxiliary modules to be
    linked with the file named in the ``main-is`` field.

    .. Note::

       Every module in the package *must* be listed in one of
       :pkg-field:`other-modules`, :pkg-field:`library:exposed-modules` or
       :pkg-field:`executable:main-is` fields.

.. pkg-field:: hs-source-dir: directory list
    :deprecated: 2.0
    :removed: 3.0

    :default: ``.``

    Root directories for the module hierarchy.

    Deprecated in favor of :pkg-field:`hs-source-dirs`.

.. pkg-field:: hs-source-dirs: directory list

    :default: ``.``

    Root directories for the module hierarchy.

    .. note::

      Components can share source directories but modules found there will be
      recompiled even if other components already built them, i.e., if a
      library and an executable share a source directory and the executable
      depends on the library and imports its ``Foo`` module, ``Foo`` will be
      compiled twice, once as part of the library and again for the executable.

.. pkg-field:: default-extensions: identifier list

    A list of Haskell extensions used by every module. These determine
    corresponding compiler options enabled for all files. Extension
    names are the constructors of the
    `Extension <../release/cabal-latest/doc/API/Cabal/Language-Haskell-Extension.html#t:Extension>`__
    type. For example, ``CPP`` specifies that Haskell source files are
    to be preprocessed with a C preprocessor.

.. pkg-field:: other-extensions: identifier list

    A list of Haskell extensions used by some (but not necessarily all)
    modules. From GHC version 6.6 onward, these may be specified by
    placing a ``LANGUAGE`` pragma in the source files affected e.g.

    .. code-block:: haskell

        {-# LANGUAGE CPP, MultiParamTypeClasses #-}

    In Cabal-1.24 the dependency solver will use this and
    :pkg-field:`default-extensions` information. Cabal prior to 1.24 will abort
    compilation if the current compiler doesn't provide the extensions.

    If you use some extensions conditionally, using CPP or conditional
    module lists, it is good to replicate the condition in
    :pkg-field:`other-extensions` declarations:

    ::

        other-extensions: CPP
        if impl(ghc >= 7.5)
          other-extensions: PolyKinds

    You could also omit the conditionally used extensions, as they are
    for information only, but it is recommended to replicate them in
    :pkg-field:`other-extensions` declarations.

.. pkg-field:: extensions: identifier list
   :deprecated: 1.12
   :removed: 3.0

   Deprecated in favor of :pkg-field:`default-extensions`.

.. pkg-field:: build-tool-depends: package:executable list
    :since: 2.0

    A list of Haskell executables needed to build this component. Executables are provided
    during the whole duration of the component, so this field can be used for executables
    needed during :pkg-section:`test-suite` as well.

    Each is specified by the package containing the executable and the name of the
    executable itself, separated by a colon, and optionally followed by a version bound.

    All executables defined in the given Cabal file are termed as *internal* dependencies
    as opposed to the rest which are *external* dependencies.

    Each of the two is handled differently:

    1. External dependencies can (and should) contain a version bound like conventional
       :pkg-field:`build-depends` dependencies.
Jan Hrček's avatar
Jan Hrček committed
1787
    2. Internal dependencies should not contain a version bound, as they will be always
1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264
       resolved within the same configuration of the package in the build plan.
       Specifically, version bounds that include the package's version will be warned for
       being extraneous, and version bounds that exclude the package's version will raise
       an error for being impossible to follow.

    For example (1) using a test-suite to make sure README.md Haskell snippets are tested using
    `markdown-unlit <http://hackage.haskell.org/package/markdown-unlit>`__:

    ::

        build-tool-depends: markdown-unlit:markdown-unlit >= 0.5.0 && < 0.6

    For example (2) using a test-suite to test executable behaviour in the same package:

    ::

        build-tool-depends: mypackage:executable

    Cabal tries to make sure that all specified programs are atomically built and prepended
    on the ``$PATH`` shell variable before building the component in question, but can only do
    so for Nix-style builds. Specifically:

    a) For Nix-style local builds, both internal and external dependencies.
    b) For old-style builds, only for internal dependencies [#old-style-build-tool-depends]_.
       It's up to the user to provide needed executables in this case under `$PATH.`


    .. note::

      :pkg-field:`build-tool-depends` was added in Cabal 2.0, and it will
      be ignored (with a warning) with old versions of Cabal.  See
      :pkg-field:`build-tools` for more information about backwards
      compatibility.

.. pkg-field:: build-tools: program list
    :deprecated: 2.0
    :removed: 3.0

    Deprecated in favor of :pkg-field:`build-tool-depends`, but :ref:`see below for backwards compatibility information <buildtoolsbc>`.

    A list of Haskell programs needed to build this component.
    Each may be followed by an optional version bound.
    Confusingly, each program in the list either refer to one of three things:

      1. Another executables in the same package (supported since Cabal 1.12)

      2. Tool name contained in Cabal's :ref:`hard-coded set of common tools <buildtoolsmap>`

      3. A pre-built executable that should already be on the ``PATH``
         (supported since Cabal 2.0)

    These cases are listed in order of priority:
    an executable in the package will override any of the hard-coded packages with the same name,
    and a hard-coded package will override any executable on the ``PATH``.

    In the first two cases, the list entry is desugared into a :pkg-field:`build-tool-depends` entry.
    In the first case, the entry is desugared into a :pkg-field:`build-tool-depends` entry by prefixing with ``$pkg:``.
    In the second case, it is desugared by looking up the package and executable name in a hard-coded table.
    In either case, the optional version bound is passed through unchanged.
    Refer to the documentation for :pkg-field:`build-tool-depends` to understand the desugared field's meaning, along with restrictions on version bounds.

    .. _buildtoolsbc:

    **Backward Compatibility**

    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.
    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.
    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``.

    .. _buildtoolsmap:

    **Set of Known Tool Names**

    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::

        build-tools: alex >= 3.2.1 && < 3.3, happy >= 1.19.5 && < 1.20

    is simply desugared into the equivalent specification::

        build-tool-depends: alex:alex >= 3.2.1 && < 3.3, happy:happy >= 1.19.5 && < 1.20

    +--------------------------+-----------------------------------+-----------------+
    | :pkg-field:`build-tools` | desugared                         | Note            |
    | identifier               | :pkg-field:`build-tool-depends`   |                 |
    |                          | identifier                        |                 |
    +==========================+===================================+=================+
    | ``alex``                 | ``alex:alex``                     |                 |
    +--------------------------+-----------------------------------+-----------------+
    | ``c2hs``                 | ``c2hs:c2hs``                     |                 |
    +--------------------------+-----------------------------------+-----------------+
    | ``cpphs``                | ``cpphs:cpphs``                   |                 |
    +--------------------------+-----------------------------------+-----------------+
    | ``greencard``            | ``greencard:greencard``           |                 |
    +--------------------------+-----------------------------------+-----------------+
    | ``haddock``              | ``haddock:haddock``               |                 |
    +--------------------------+-----------------------------------+-----------------+
    | ``happy``                | ``happy:happy``                   |                 |
    +--------------------------+-----------------------------------+-----------------+
    | ``hsc2hs``               | ``hsc2hs:hsc2hs``                 |                 |
    +--------------------------+-----------------------------------+-----------------+
    | ``hscolour``             | ``hscolour:hscolour``             |                 |
    +--------------------------+-----------------------------------+-----------------+
    | ``hspec-discover``       | ``hspec-discover:hspec-discover`` | since Cabal 2.0 |
    +--------------------------+-----------------------------------+-----------------+

    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.

.. pkg-field:: buildable: boolean

    :default: ``True``

    Is the component buildable? Like some of the other fields below,
    this field is more useful with the slightly more elaborate form of
    the simple build infrastructure described in the section on
    `system-dependent parameters`_.

.. pkg-field:: ghc-options: token list

    Additional options for GHC. You can often achieve the same effect
    using the :pkg-field:`default-extensions` field, which is preferred.

    Options required only by one module may be specified by placing an
    ``OPTIONS_GHC`` pragma in the source file affected.

    As with many other fields, whitespace can be escaped by using
    Haskell string syntax. Example:
    ``ghc-options: -Wcompat "-with-rtsopts=-T -I1" -Wall``.

.. pkg-field:: ghc-prof-options: token list

    Additional options for GHC when the package is built with profiling
    enabled.

    Note that as of Cabal-1.24, the default profiling detail level
    defaults to ``exported-functions`` for libraries and
    ``toplevel-functions`` for executables. For GHC these correspond to
    the flags ``-fprof-auto-exported`` and ``-fprof-auto-top``. Prior to
    Cabal-1.24 the level defaulted to ``none``. These levels can be
    adjusted by the person building the package with the
    ``--profiling-detail`` and ``--library-profiling-detail`` flags.

    It is typically better for the person building the package to pick
    the profiling detail level rather than for the package author. So
    unless you have special needs it is probably better not to specify
    any of the GHC ``-fprof-auto*`` flags here. However if you wish to
    override the profiling detail level, you can do so using the
    :pkg-field:`ghc-prof-options` field: use ``-fno-prof-auto`` or one of the
    other ``-fprof-auto*`` flags.

.. pkg-field:: ghc-shared-options: token list

    Additional options for GHC when the package is built as shared
    library. The options specified via this field are combined with the
    ones specified via :pkg-field:`ghc-options`, and are passed to GHC during
    both the compile and link phases.

.. pkg-field:: includes: filename list

    A list of header files to be included in any compilations via C.
    This field applies to both header files that are already installed
    on the system and to those coming with the package to be installed.
    The former files should be found in absolute paths, while the latter
    files should be found in paths relative to the top of the source
    tree or relative to one of the directories listed in
    :pkg-field:`include-dirs`.

    These files typically contain function prototypes for foreign
    imports used by the package. This is in contrast to
    :pkg-field:`install-includes`, which lists header files that are intended
    to be exposed to other packages that transitively depend on this
    library.

.. pkg-field:: install-includes: filename list

    A list of header files from this package to be installed into
    ``$libdir/includes`` when the package is installed. Files listed in
    :pkg-field:`install-includes` should be found in relative to the top of the
    source tree or relative to one of the directories listed in
    :pkg-field:`include-dirs`.

    :pkg-field:`install-includes` is typically used to name header files that
    contain prototypes for foreign imports used in Haskell code in this
    package, for which the C implementations are also provided with the
    package. For example, here is a ``.cabal`` file for a hypothetical
    ``bindings-clib`` package that bundles the C source code for ``clib``::

        include-dirs:     cbits
        c-sources:        clib.c
        install-includes: clib.h

    Now any package that depends (directly or transitively) on the
    ``bindings-clib`` library can use ``clib.h``.

    Note that in order for files listed in :pkg-field:`install-includes` to be
    usable when compiling the package itself, they need to be listed in
    the :pkg-field:`includes` field as well.

.. pkg-field:: include-dirs: directory list

    A list of directories to search for header files, when preprocessing
    with ``c2hs``, ``hsc2hs``, ``cpphs`` or the C preprocessor, and also
    when compiling via C. Directories can be absolute paths (e.g., for
    system directories) or paths that are relative to the top of the
    source tree. Cabal looks in these directories when attempting to
    locate files listed in :pkg-field:`includes` and
    :pkg-field:`install-includes`.

.. pkg-field:: c-sources: filename list

    A list of C source files to be compiled and linked with the Haskell
    files.

.. pkg-field:: cxx-sources: filename list
    :since: 2.2

    A list of C++ source files to be compiled and linked with the Haskell
    files. Useful for segregating C and C++ sources when supplying different
    command-line arguments to the compiler via the :pkg-field:`cc-options`
    and the :pkg-field:`cxx-options` fields. The files listed in the
    :pkg-field:`cxx-sources` can reference files listed in the
    :pkg-field:`c-sources` field and vice-versa. The object files will be linked
    appropriately.

.. pkg-field:: asm-sources: filename list
    :since: 3.0

    A list of assembly source files to be compiled and linked with the
    Haskell files.

.. pkg-field:: cmm-sources: filename list
    :since: 3.0

    A list of C-- source files to be compiled and linked with the Haskell
    files.

.. pkg-field:: js-sources: filename list

    A list of JavaScript source files to be linked with the Haskell
    files (only for JavaScript targets).

.. pkg-field:: extra-libraries: token list

    A list of extra libraries to link with.

.. pkg-field:: extra-ghci-libraries: token list

    A list of extra libraries to be used instead of 'extra-libraries'
    when the package is loaded with GHCi.

.. pkg-field:: extra-bundled-libraries: token list
   :since: 2.2

   A list of libraries that are supposed to be copied from the build
   directory alongside the produced Haskell libraries.  Note that you
   are under the obligation to produce those libraries in the build
   directory (e.g. via a custom setup).  Libraries listed here will
   be included when ``copy``-ing packages and be listed in the
   ``hs-libraries`` of the package configuration in the package database.
   Library names must either be prefixed with "HS" or "C" and corresponding
   library file names must match:

      - Libraries with name "HS<library-name>":
         - `libHS<library-name>.a`
         - `libHS<library-name>-ghc<ghc-flavour><ghc-version>.<dyn-library-extension>*`
      - Libraries with name "C<library-name>":
         - `libC<library-name>.a`
         - `lib<library-name>.<dyn-library-extension>*`

.. pkg-field:: extra-lib-dirs: directory list

    A list of directories to search for libraries.

.. pkg-field:: cc-options: token list

    Command-line arguments to be passed to the C compiler. Since the
    arguments are compiler-dependent, this field is more useful with the
    setup described in the section on `system-dependent parameters`_.

.. pkg-field:: cpp-options: token list

    Command-line arguments for pre-processing Haskell code. Applies to
    Haskell source and other pre-processed Haskell source like .hsc
    .chs. Does not apply to C code, that's what cc-options is for.

.. pkg-field:: cxx-options: token list
    :since: 2.2

    Command-line arguments to be passed to the compiler when compiling
    C++ code. The C++ sources to which these command-line arguments
    should be applied can be specified with the :pkg-field:`cxx-sources`
    field. Command-line options for C and C++ can be passed separately to
    the compiler when compiling both C and C++ sources by segregating the C
    and C++ sources with the :pkg-field:`c-sources` and
    :pkg-field:`cxx-sources` fields respectively, and providing different
    command-line arguments with the :pkg-field:`cc-options` and the
    :pkg-field:`cxx-options` fields.

.. pkg-field:: cmm-options: token list
    :since: 3.0

    Command-line arguments to be passed to the compiler when compiling
    C-- code. See also :pkg-field:`cmm-sources`.

.. pkg-field:: asm-options: token list
    :since: 3.0

    Command-line arguments to be passed to the assembler when compiling
    assembler code. See also :pkg-field:`asm-sources`.

.. pkg-field:: ld-options: token list

    Command-line arguments to be passed to the linker. Since the
    arguments are compiler-dependent, this field is more useful with the
    setup described in the section on `system-dependent parameters`_.

.. pkg-field:: pkgconfig-depends: package list

    A list of
    `pkg-config <http://www.freedesktop.org/wiki/Software/pkg-config/>`__
    packages, needed to build this package. They can be annotated with
    versions, e.g. ``gtk+-2.0 >= 2.10, cairo >= 1.0``. If no version
    constraint is specified, any version is assumed to be acceptable.
    Cabal uses ``pkg-config`` to find if the packages are available on
    the system and to find the extra compilation and linker options
    needed to use the packages.

    If you need to bind to a C library that supports ``pkg-config`` then
    it is much preferable to use this field rather than hard code options
    into the other fields. ``pkg-config --list-all`` will show you all
    supported libraries. Depending on your system you may need to adjust
    ``PKG_CONFIG_PATH``.

.. pkg-field:: frameworks: token list

    On Darwin/MacOS X, a list of frameworks to link to. See Apple's
    developer documentation for more details on frameworks. This entry
    is ignored on all other platforms.

.. pkg-field:: extra-frameworks-dirs: directory list
    :since: 1.24

    On Darwin/MacOS X, a list of directories to search for frameworks.
    This entry is ignored on all other platforms.

.. pkg-field:: mixins: mixin list
    :since: 2.0

    Supported only in GHC 8.2 and later. A list of packages mentioned in the
    :pkg-field:`build-depends` field, each optionally accompanied by a list of
    module and module signature renamings.

    The simplest mixin syntax is simply the name of a package mentioned in the
    :pkg-field:`build-depends` field. For example:

    ::

        library
          build-depends:
            foo ^>= 1.2.3
          mixins:
            foo

    But this doesn't have any effect. More interesting is to use the mixin
    entry to rename one or more modules from the package, like this:

    ::

        library
          mixins:
            foo (Foo.Bar as AnotherFoo.Bar, Foo.Baz as AnotherFoo.Baz)

    Note that renaming a module like this will hide all the modules
    that are not explicitly named.

    Modules can also be hidden:

    ::

        library:
          mixins:
            foo hiding (Foo.Bar)

    Hiding modules exposes everything that is not explicitly hidden.

    .. Note::

       The current version of Cabal suffers from an infelicity in how the
       entries of :pkg-field:`mixins` are parsed: an entry will fail to parse
       if the provided renaming clause has whitespace after the opening
       parenthesis. This will be fixed in future versions of Cabal.

       See issues :issue:`5150`, :issue:`4864`, and :issue:`5293`.

    There can be multiple mixin entries for a given package, in effect creating
    multiple copies of the dependency:

    ::

        library
          mixins:
            foo (Foo.Bar as AnotherFoo.Bar, Foo.Baz as AnotherFoo.Baz),
            foo (Foo.Bar as YetAnotherFoo.Bar)

    The ``requires`` clause is used to rename the module signatures required by
    a package:

    ::

        library
          mixins:
            foo (Foo.Bar as AnotherFoo.Bar) requires (Foo.SomeSig as AnotherFoo.SomeSig)

    Signature-only packages don't have any modules, so only the signatures can
    be renamed, with the following syntax:

    ::

        library
          mixins:
            sigonly requires (SigOnly.SomeSig as AnotherSigOnly.SomeSig)

    See the :pkg-field:`library:signatures` field for more details.

    Mixin packages are part of the Backpack_ extension to the
    Haskell module system.

    The matching of the module signatures required by a
    :pkg-field:`build-depends` dependency with the implementation modules
    present in another dependency is triggered by a coincidence of names. When
    the names of the signature and of the implementation are already the same,
    the matching is automatic. But when the names don't coincide, or we want to
    instantiate a signature in two different ways, adding mixin entries that
    perform renamings becomes necessary.

    .. Warning::

       Backpack_ has the limitation that implementation modules that instantiate
       signatures required by a :pkg-field:`build-depends` dependency can't
       reside in the same component that has the dependency. They must reside
       in a different package dependency, or at least in a separate internal
       library.

Configurations
^^^^^^^^^^^^^^

Library and executable sections may include conditional blocks, which
test for various system parameters and configuration flags. The flags
mechanism is rather generic, but most of the time a flag represents
certain feature, that can be switched on or off by the package user.
Here is an example package description file using configurations:

Example: A package containing a library and executable programs
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

::

    Name: Test1
    Version: 0.0.1
    Cabal-Version: >= 1.8
    License: BSD3
    Author:  Jane Doe
    Synopsis: Test package to test configurations
    Category: Example
    Build-Type: Simple

    Flag Debug
      Description: Enable debug support
      Default:     False
      Manual:      True

    Flag WebFrontend
      Description: Include API for web frontend.
      Default:     False
      Manual:      True

    Flag NewDirectory
      description: Whether to build against @directory >= 1.2@
2265
      -- This is an automatic flag which the solver will