1 Package Description — <package>.cabal File
2 ==========================================
4 The package description file, commonly known as "the Cabal file", describes the
5 contents of a package. The Cabal package is the unit of distribution. When
6 installed, its purpose is to make available one or more:
8 - Haskell programs (executables); and/or
10 - libraries, exposing a number of Haskell modules.
12 Public library components can be depended upon by other Cabal packages and all
13 library components (both public and private) can be depended upon by other
14 components of the same package.
16 Internally, the package may consist of much more than a bunch of Haskell
17 modules: it may also have C source code and header files, source code
18 meant for preprocessing, documentation, test cases, auxiliary tools etc.
20 A package is identified by a globally-unique *package name*, which
21 consists of one or more alphanumeric words separated by hyphens. To
22 avoid ambiguity, each of these words should contain at least one letter.
23 Chaos will result if two distinct packages with the same name are
24 installed on the same system. A particular version of the package is
25 distinguished by a *version number*, consisting of a sequence of one or
26 more integers separated by dots. These can be combined to form a single
27 text string called the *package ID*, using a hyphen to separate the name
28 from the version, e.g. "``HUnit-1.1``".
32 Packages are not part of the Haskell language; they simply
33 populate the hierarchical space of module names. In GHC 6.6 and later a
34 program may contain multiple modules with the same name if they come
35 from separate packages; in all other current Haskell systems packages
36 may not overlap in the modules they provide, including hidden modules.
41 Suppose you have a directory hierarchy containing the source files that
42 make up your package. You will need to add two more files to the root
43 directory of the package:
45 :file:`{package-name}.cabal`
46 a Unicode UTF-8 text file containing a package description. For
47 details of the syntax of this file, see the section on
48 `package descriptions`_.
51 a single-module Haskell program to perform various setup tasks (with
52 the interface described in the section on :ref:`setup-commands`).
53 This module should import only modules that will be present in all Haskell
54 implementations, including modules of the Cabal library. The content of
55 this file is determined by the :pkg-field:`build-type` setting in the
56 ``.cabal`` file. In most cases it will be trivial, calling on the Cabal
57 library to do most of the work.
59 Once you have these, you can create a source bundle of this directory
60 for distribution. Building of the package is demonstrated in the section
61 :ref:`building-packages`.
63 One of the purposes of Cabal is to make it easier to build a package
64 with different Haskell implementations. So it provides abstractions of
65 features present in different Haskell implementations and wherever
66 possible it is best to take advantage of these to increase portability.
67 Where necessary however it is possible to use specific features of
68 specific implementations. For example one of the pieces of information a
69 package author can put in the package's ``.cabal`` file is what language
70 extensions the code uses. This is far preferable to specifying flags for
71 a specific compiler as it allows Cabal to pick the right flags for the
72 Haskell implementation that the user picks. It also allows Cabal to
73 figure out if the language extension is even supported by the Haskell
74 implementation that the user picks. Where compiler-specific options are
75 needed however, there is an "escape hatch" available. The developer can
76 specify implementation-specific options and more generally there is a
77 configuration mechanism to customise many aspects of how a package is
78 built depending on the Haskell implementation, the Operating system,
79 computer architecture and user-specified configuration flags.
87 default-language: Haskell2010
88 build-depends: base >= 4 && < 5
90 extensions: ForeignFunctionInterface
93 build-depends: Win32 >= 2.1 && < 2.6
95 Example: A package containing a simple library
96 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98 The HUnit package contains a file ``HUnit.cabal`` containing:
105 synopsis: A unit testing framework for Haskell
106 homepage: http://hunit.sourceforge.net/
108 author: Dean Herington
109 license: BSD-3-Clause
110 license-file: LICENSE
114 build-depends: base >= 2 && < 4
115 exposed-modules: Test.HUnit.Base, Test.HUnit.Lang,
116 Test.HUnit.Terminal, Test.HUnit.Text, Test.HUnit
117 default-extensions: CPP
118 default-language: Haskell2010
120 and the following ``Setup.hs``:
122 .. code-block:: haskell
124 import Distribution.Simple
127 Example: A package containing executable programs
128 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135 synopsis: Small package with two programs
136 author: Angela Author
137 license: BSD-3-Clause
141 build-depends: HUnit >= 1.1.1 && < 1.2
143 hs-source-dirs: prog1
144 default-language: Haskell2010
147 -- A different main.hs because of hs-source-dirs.
149 build-depends: HUnit >= 1.1.1 && < 1.2
150 hs-source-dirs: prog2
152 default-language: Haskell2010
154 with ``Setup.hs`` the same as above.
156 Example: A package containing a library and executable programs
157 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
164 synopsis: Package with library and two programs
165 license: BSD-3-Clause
166 author: Angela Author
170 build-depends: HUnit >= 1.1.1 && < 1.2
172 exposed-modules: A, B, C
173 default-language: Haskell2010
177 hs-source-dirs: prog1
179 default-language: Haskell2010
182 -- A different main.hs because of hs-source-dirs.
184 -- No bound on a library provided by the same package.
185 build-depends: TestPackage
186 hs-source-dirs: prog2
188 default-language: Haskell2010
190 with ``Setup.hs`` the same as above. Note that any library modules
191 required (directly or indirectly) by an executable must be listed again.
193 The trivial setup script used in these examples uses the *simple build
194 infrastructure* provided by the Cabal library (see
195 `Distribution.Simple <https://hackage.haskell.org/package/Cabal/docs/Distribution-Simple.html>`__).
196 The simplicity lies in its interface rather that its implementation. It
197 automatically handles preprocessing with standard preprocessors, and
198 builds packages for all the Haskell implementations.
200 The simple build infrastructure can also handle packages where building
201 is governed by system-dependent parameters, if you specify a little more
202 (see the section on `system-dependent parameters`_).
203 A few packages require `more elaborate solutions <#more-complex-packages>`_.
210 The package description file must have a name ending in "``.cabal``". It
211 must be a Unicode text file encoded using valid UTF-8. There must be
212 exactly one such file in the directory. The first part of the name is
213 usually the package name, and some of the tools that operate on Cabal
214 packages require this; specifically, Hackage rejects packages which
215 don't follow this rule.
217 In the package description file, lines whose first non-whitespace
218 characters are "``--``" are treated as comments and ignored.
220 This file should contain a number global property descriptions and
223 - The `package properties`_ describe the package
224 as a whole, such as name, license, author, etc.
226 - Optionally, a number of *configuration flags* can be declared. These
227 can be used to enable or disable certain features of a package. (see
228 the section on `configurations`_).
230 - The (optional) library section specifies the `library`_ properties and
231 relevant `build information`_.
233 - Following is an arbitrary number of executable sections which describe
234 an executable program and relevant `build information`_.
236 Each section consists of a number of property descriptions in the form
237 of field/value pairs, with a syntax roughly like mail message headers.
239 - Case is not significant in field names, but is significant in field
242 - To continue a field value, indent the next line relative to the field
245 - Field names may be indented, but all field values in the same section
246 must use the same indentation.
248 - Tabs are *not* allowed as indentation characters due to a missing
249 standard interpretation of tab width.
251 - Before Cabal 3.0, to get a blank line in a field value, use an indented "``.``"
253 The syntax of the value depends on the field. Field types include:
255 *token*, *filename*, *directory*
256 Either a sequence of one or more non-space non-comma characters, or
257 a quoted string in Haskell 98 lexical syntax. The latter can be used
258 for escaping whitespace, for example:
259 ``ghc-options: -Wall "-with-rtsopts=-T -I1"``. Unless otherwise
260 stated, relative filenames and directories are interpreted from the
261 package root directory.
262 *freeform*, *URL*, *address*
263 An arbitrary, uninterpreted string.
265 A letter followed by zero or more alphanumerics or underscores.
267 A compiler flavor (one of: ``GHC``, ``UHC`` or ``LHC``)
268 followed by a version range. For example, ``GHC ==6.10.3``, or
269 ``LHC >=0.6 && <0.8``.
271 Modules and preprocessors
272 ^^^^^^^^^^^^^^^^^^^^^^^^^
274 Haskell module names listed in the :pkg-field:`library:exposed-modules` and
275 :pkg-field:`library:other-modules` fields may correspond to Haskell source
276 files, i.e. with names ending in "``.hs``" or "``.lhs``", or to inputs for
277 various Haskell preprocessors. The simple build infrastructure understands the
280 - ``.gc`` (:hackage-pkg:`greencard`)
281 - ``.chs`` (:hackage-pkg:`c2hs`)
282 - ``.hsc`` (:hackage-pkg:`hsc2hs`)
283 - ``.y`` and ``.ly`` (happy_)
285 - ``.cpphs`` (cpphs_)
287 When building, Cabal will automatically run the appropriate preprocessor
288 and compile the Haskell module it produces. For the ``c2hs`` and
289 ``hsc2hs`` preprocessors, Cabal will also automatically add, compile and
290 link any C sources generated by the preprocessor (produced by
291 ``hsc2hs``'s ``#def`` feature or ``c2hs``'s auto-generated wrapper
292 functions). Dependencies on pre-processors are specified via the
293 :pkg-field:`build-tools` or :pkg-field:`build-tool-depends` fields.
295 Some fields take lists of values, which are optionally separated by
296 commas, except for the :pkg-field:`build-depends` field, where the commas are
299 Some fields are marked as required. All others are optional, and unless
300 otherwise specified have empty default values.
305 These fields may occur in the first top-level properties section and
306 describe the package as a whole:
308 .. pkg-field:: name: package-name (required)
310 The unique name of the package, without the version number.
312 As pointed out in the section on `package descriptions`_, some
313 tools require the package-name specified for this field to match
314 the package description's file-name :file:`{package-name}.cabal`.
316 Package names are case-sensitive and must match the regular expression
317 (i.e. alphanumeric "words" separated by dashes; each alphanumeric
318 word must contain at least one letter):
319 ``[[:digit:]]*[[:alpha:]][[:alnum:]]*(-[[:digit:]]*[[:alpha:]][[:alnum:]]*)*``.
321 Or, expressed in ABNF_:
325 package-name = package-name-part *("-" package-name-part)
326 package-name-part = *DIGIT UALPHA *UALNUM
328 UALNUM = UALPHA / DIGIT
329 UALPHA = ... ; set of alphabetic Unicode code-points
333 Hackage restricts package names to the ASCII subset.
335 .. pkg-field:: version: numbers (required)
337 The package version number, usually consisting of a sequence of
338 natural numbers separated by dots, i.e. as the regular
339 expression ``[0-9]+([.][0-9]+)*`` or expressed in ABNF_:
343 package-version = 1*DIGIT *("." 1*DIGIT)
345 .. pkg-field:: cabal-version: x.y[.z]
347 The version of the Cabal specification that this package
348 description uses. The Cabal specification does slowly evolve (see
349 also :ref:`spec-history`), introducing new features and
350 occasionally changing the meaning of existing features.
351 Specifying which version of the specification you are using
352 enables programs which process the package description to know
353 what syntax to expect and what each part means.
355 The version number you specify will affect both compatibility and
356 behaviour. Most tools (including the Cabal library and the ``cabal``
357 program) understand a range of versions of the Cabal specification.
358 Older tools will of course only work with older versions of the
359 Cabal specification that was known at the time. Most of the time,
360 tools that are too old will recognise this fact and produce a
361 suitable error message. Likewise, ``cabal check`` will tell you
362 whether the version number is sufficiently high for the features
363 you use in the package description.
365 As for behaviour, new versions of the Cabal specification can change the
366 meaning of existing syntax. This means if you want to take advantage
367 of the new meaning or behaviour then you must specify the newer
368 Cabal version. Tools are expected to use the meaning and behaviour
369 appropriate to the version given in the package description.
371 In particular, the syntax of package descriptions changed
372 significantly with Cabal version 1.2 and the :pkg-field:`cabal-version`
373 field is now required. Files written in the old syntax are still
374 recognized, so if you require compatibility with very old Cabal
375 versions then you may write your package description file using the
376 old syntax. Please consult the user's guide of an older Cabal
377 version for a description of that syntax.
379 Starting with ``cabal-version: 2.2`` this field is only valid if
380 fully contained in the very first line of a package description
381 and ought to adhere to the ABNF_ grammar
385 newstyle-spec-version-decl = "cabal-version" *WS ":" *WS newstyle-spec-version *WS
387 newstyle-spec-version = NUM "." NUM [ "." NUM ]
389 NUM = DIGIT0 / DIGITP 1*DIGIT0
397 For package descriptions using a format prior to
398 ``cabal-version: 1.12`` the legacy syntax resembling a version
401 .. code-block:: cabal
403 cabal-version: >= 1.10
407 This legacy syntax is supported up until ``cabal-version: >=
408 2.0`` it is however strongly recommended to avoid using the
409 legacy syntax. See also :issue:`4899`.
413 .. pkg-field:: build-type: identifier
415 :default: ``Custom`` or ``Simple``
417 The type of build used by this package. Build types are the
419 `BuildType <https://hackage.haskell.org/package/Cabal-syntax/docs/Distribution-Types-BuildType.html#t:BuildType>`__
420 type. This field is optional and when missing, its default value
421 is inferred according to the following rules:
423 - When :pkg-field:`cabal-version` is set to ``2.2`` or higher,
424 the default is ``Simple`` unless a :pkg-section:`custom-setup`
425 exists, in which case the inferred default is ``Custom``.
427 - For lower :pkg-field:`cabal-version` values, the default is
428 ``Custom`` unconditionally.
430 If the build type is anything other than ``Custom``, then the
431 ``Setup.hs`` file *must* be exactly the standardized content
432 discussed below. This is because in these cases, ``cabal`` will
433 ignore the ``Setup.hs`` file completely, whereas other methods of
434 package management, such as ``runhaskell Setup.hs [CMD]``, still
435 rely on the ``Setup.hs`` file.
437 For build type ``Simple``, the contents of ``Setup.hs`` must be:
439 .. code-block:: haskell
441 import Distribution.Simple
444 For build type ``Hooks``, the contents of ``Setup.hs`` must be:
446 .. code-block:: haskell
448 import Distribution.Simple
449 import SetupHooks (setupHooks)
450 main = defaultMainWithSetupHooks setupHooks
452 For build type ``Configure`` (see the section on `system-dependent
453 parameters`_ below), the contents of
454 ``Setup.hs`` must be:
456 .. code-block:: haskell
458 import Distribution.Simple
459 main = defaultMainWithHooks autoconfUserHooks
461 For build type ``Make`` (see the section on `more complex packages`_ below),
462 the contents of ``Setup.hs`` must be:
464 .. code-block:: haskell
466 import Distribution.Make
469 For build type ``Custom``, the file ``Setup.hs`` can be customized,
470 and will be used both by ``cabal`` and other tools.
472 For most packages, the build type ``Simple`` is sufficient. For more exotic
473 needs, the ``Hooks`` build type is recommended; see :ref:`setup-hooks`.
475 .. pkg-field:: license: SPDX expression
479 The type of license under which this package is distributed.
481 Starting with ``cabal-version: 2.2`` the ``license`` field takes a
482 (case-sensitive) SPDX expression such as
484 .. code-block:: cabal
486 license: Apache-2.0 AND (MIT OR GPL-2.0-or-later)
488 See `SPDX IDs: How to use <https://spdx.org/ids-how>`__ for more
489 examples of SPDX expressions.
492 `list of SPDX license identifiers <https://spdx.org/licenses/>`__
493 is a function of the :pkg-field:`cabal-version` value as defined
494 in the following table:
496 +--------------------------+--------------------+
497 | Cabal specification | SPDX license list |
498 | version | version |
500 +==========================+====================+
501 | ``cabal-version: 2.2`` | ``3.0 2017-12-28`` |
502 +--------------------------+--------------------+
503 | ``cabal-version: 2.4`` | ``3.2 2018-07-10`` |
504 +--------------------------+--------------------+
506 **Pre-SPDX Legacy Identifiers**
508 The license identifier in the table below are defined for
509 ``cabal-version: 2.0`` and previous versions of the Cabal
512 +--------------------------+-----------------+
513 | :pkg-field:`license` | Note |
516 +==========================+=================+
520 +--------------------------+-----------------+
524 +--------------------------+-----------------+
525 | ``AGPL`` | since 1.18 |
527 +--------------------------+-----------------+
528 | ``BSD2`` | since 1.20 |
529 +--------------------------+-----------------+
531 +--------------------------+-----------------+
533 +--------------------------+-----------------+
534 | ``ISC`` | since 1.22 |
535 +--------------------------+-----------------+
536 | ``MPL-2.0`` | since 1.20 |
537 +--------------------------+-----------------+
540 +--------------------------+-----------------+
541 | ``PublicDomain`` | |
542 +--------------------------+-----------------+
543 | ``AllRightsReserved`` | |
544 +--------------------------+-----------------+
545 | ``OtherLicense`` | |
546 +--------------------------+-----------------+
549 .. pkg-field:: license-file: filename
551 See :pkg-field:`license-files`.
553 .. pkg-field:: license-files: filename list
556 The name of a file(s) containing the precise copyright license for
557 this package. The license file(s) will be installed with the
560 If you have multiple license files then use the :pkg-field:`license-files`
561 field instead of (or in addition to) the :pkg-field:`license-file` field.
563 .. pkg-field:: copyright: freeform
565 The content of a copyright notice, typically the name of the holder
566 of the copyright on the package and the year(s) from which copyright
567 is claimed. For example::
569 copyright: (c) 2006-2007 Joe Bloggs
571 .. pkg-field:: author: freeform
573 The original author of the package.
575 Remember that ``.cabal`` files are Unicode, using the UTF-8
578 .. pkg-field:: maintainer: address
580 The current maintainer or maintainers of the package. This is an
581 e-mail address to which users should send bug reports, feature
582 requests and patches.
584 .. pkg-field:: stability: freeform
586 The stability level of the package, e.g. ``alpha``,
587 ``experimental``, ``provisional``, ``stable``.
589 .. pkg-field:: homepage: URL
591 The package homepage.
593 .. pkg-field:: bug-reports: URL
595 The URL where users should direct bug reports. This would normally
598 - A ``mailto:`` URL, e.g. for a person or a mailing list.
600 - An ``http:`` (or ``https:``) URL for an online bug tracking
603 For example Cabal itself uses a web-based bug tracking system
607 bug-reports: https://github.com/haskell/cabal/issues
609 .. pkg-field:: package-url: URL
611 The location of a source bundle for the package. The distribution
612 should be a Cabal package.
614 .. pkg-field:: synopsis: freeform
616 A very short description of the package, for use in a table of
617 packages. This is your headline, so keep it short (one line) but as
618 informative as possible. Save space by not including the package
619 name or saying it's written in Haskell.
621 .. pkg-field:: description: freeform
623 Description of the package. This may be several paragraphs, and
624 should be aimed at a Haskell programmer who has never heard of your
627 For library packages, this field is used as prologue text by
628 :ref:`setup-haddock` and thus may contain the same markup as Haddock_
629 documentation comments.
631 .. pkg-field:: category: freeform
633 A classification category for future use by the package catalogue
634 Hackage_. These categories have not
635 yet been specified, but the upper levels of the module hierarchy
638 .. pkg-field:: tested-with: compiler list
640 A list of compilers and versions against which the package has been
641 tested (or at least built). The value of this field is not used by Cabal
642 and is rather intended as extra metadata for use by third party
643 tooling, such as e.g. CI tooling.
645 Here's a typical usage example:
649 tested-with: GHC == 9.10.1, GHC == 9.8.2, GHC == 9.6.5
651 The same can be spread over several lines, for instance:
655 tested-with: GHC == 9.10.1
659 The separating comma can also be dropped altogether:
668 However, this alternative might
669 `disappear <https://github.com/haskell/cabal/issues/4894#issuecomment-909008657>`__
672 Starting with :pkg-field:`cabal-version` 3.0,
673 there are further conveniences.
675 1. A preceding ``,`` is allowed, so a bullet-list style
676 is possible (recommended):
686 2. A concise set notation syntax is available:
690 tested-with: GHC == { 9.10.1, 9.8.2, 9.6.5 }
692 .. pkg-field:: data-files: filename list
694 A list of files to be installed for run-time use by the package.
695 This is useful for packages that use a large amount of static data,
696 such as tables of values or code templates. Cabal provides a way to
697 `find these files at run-time <#accessing-data-files-from-package-code>`_.
699 A limited form of ``*`` wildcards in file names, for example
700 ``data-files: images/*.png`` matches all the ``.png`` files in the
701 ``images`` directory. ``data-files: audio/**/*.mp3`` matches all
702 the ``.mp3`` files in the ``audio`` directory, including
705 The specific limitations of this wildcard syntax are
707 - ``*`` wildcards are only allowed in place of the file name, not
708 in the directory name or file extension. It must replace the
709 whole file name (e.g., ``*.html`` is allowed, but
710 ``chapter-*.html`` is not). If a wildcard is used, it must be
711 used with an extension, so ``data-files: data/*`` is not
714 - Prior to Cabal 2.4, when matching a wildcard plus extension, a
715 file's full extension must match exactly, so ``*.gz`` matches
716 ``foo.gz`` but not ``foo.tar.gz``. This restriction has been
717 lifted when ``cabal-version: 2.4`` or greater so that ``*.gz``
718 does match ``foo.tar.gz``
720 - ``*`` wildcards will not match if the file name is empty (e.g.,
721 ``*.html`` will not match ``foo/.html``).
723 - ``**`` wildcards can only appear as the final path component
724 before the file name (e.g., ``data/**/images/*.jpg`` is not
727 - Prior to Cabal 3.8, if a ``**`` wildcard is used, then
728 the file name must include a ``*`` wildcard (e.g.,
729 ``data/**/README.rst`` was not allowed). As of ``cabal-version:
730 3.8`` or greater, this restriction is lifted.
732 - A wildcard that does not match any files is an error.
734 The reason for providing only a very limited form of wildcard is to
735 concisely express the common case of a large number of related files
736 of the same file type without making it too easy to accidentally
737 include unwanted files.
739 On efficiency: if you use ``**`` patterns, the directory tree will
740 be walked starting with the parent directory of the ``**``. If
741 that's the root of the project, this might include ``.git/``,
742 ``dist-newstyle/``, or other large directories! To avoid this
743 behaviour, put the files that wildcards will match against in
746 ``**`` wildcards are available starting in Cabal 2.4
747 and `bug-free since Cabal 3.0 <https://github.com/haskell/cabal/issues/6125#issuecomment-1379878419>`_.
749 .. pkg-field:: data-dir: directory
751 The directory where Cabal looks for data files to install, relative
752 to the source directory. By default, Cabal will look in the source
755 .. pkg-field:: extra-source-files: filename list
757 A list of additional files to be included in source distributions built with :ref:`setup-sdist`.
758 As with :pkg-field:`data-files` it can use a limited form of ``*`` wildcards in file names.
759 Files listed here are tracked by ``cabal build``; changes in these files cause (partial) rebuilds.
761 .. pkg-field:: extra-doc-files: filename list
764 A list of additional files to be included in source distributions,
765 and also copied to the html directory when Haddock documentation is
766 generated. As with :pkg-field:`data-files` it can use a limited form of
767 ``*`` wildcards in file names.
769 .. pkg-field:: extra-tmp-files: filename list
771 A list of additional files or directories to be removed by
772 :ref:`setup-clean`. These would typically be additional files created by
773 additional hooks, such as the scheme described in the section on
774 `system-dependent parameters`_.
779 .. pkg-section:: library name
780 :synopsis: Library build information.
782 Build information for libraries.
784 A package can include zero or more library components. A library can be
785 unnamed or named (using the ``name`` argument). It can also be depended upon
786 only by components in the same package (private) or by those components and
787 components in other packages (public). A package can have no more than one
792 The 'cabal' executable provided by the 'cabal-install' package will not
793 accept dependencies on sublibraries of packages with no unnamed library.
795 This guide refers to an unnamed library as the main library and a named
796 library as a sublibrary (such components may be considered as subidiary, or
797 ancillary, to the main library). It refers to a private sublibrary as an
800 A sublibrary cannot have the same name as its package.
804 Before version 3.4 of the Cabal specification, a private sublibrary could
805 shadow a dependency on the main library of another package, if their
808 A main library is always public and a sublibrary is private by default.
809 See the :pkg-field:`library:visibility` field for setting a sublibrary as
812 Being able to include more than one public library in a package allows the
813 separation of the unit of distribution (the package) from the unit of
814 buildable code (the library). This is useful for Haskell projects with many
815 libraries that are distributed together as it avoids duplication and
816 potential inconsistencies.
820 Before version 3.0 of the Cabal specification, all sublibraries were
821 internal libraries. Before version 2.0, a package could not include
824 See :ref:`Sublibraries - Examples <sublibs>` for examples.
826 A library section should contain the following fields:
828 .. pkg-field:: visibility: visibility specifiers
833 ``private`` for sublibraries. Cannot be set for the main library, which
836 Can be set to ``private`` or ``public``. A ``private`` library component can
837 only be depended on by other components of the same package. A ``public``
838 component can be depended on by those components and by components of other
841 See the :pkg-field:`build-depends` field for the syntax to specify a
842 dependency on a library component.
844 .. pkg-field:: exposed-modules: identifier list
846 :required: if this package contains a library
848 A list of modules added by this package.
850 .. pkg-field:: virtual-modules: identifier list
853 A list of virtual modules provided by this package. Virtual modules
854 are modules without a source file. See for example the ``GHC.Prim``
855 module from the ``ghc-prim`` package. Modules listed here will not be
856 built, but still end up in the list of ``exposed-modules`` in the
857 installed package info when the package is registered in the package
860 .. pkg-field:: exposed: boolean
864 Some Haskell compilers (notably GHC) support the notion of packages
865 being "exposed" or "hidden" which means the modules they provide can
866 be easily imported without always having to specify which package
867 they come from. However this only works effectively if the modules
868 provided by all exposed packages do not overlap (otherwise a module
869 import would be ambiguous).
871 Almost all new libraries use hierarchical module names that do not
872 clash, so it is very uncommon to have to use this field. However it
873 may be necessary to set ``exposed: False`` for some old libraries
874 that use a flat module namespace or where it is known that the
875 exposed modules would clash with other common modules.
877 .. pkg-field:: reexported-modules: exportlist
880 Supported only in GHC 7.10 and later. A list of modules to
881 *reexport* from this package. The syntax of this field is
882 ``orig-pkg:Name as NewName`` to reexport module ``Name`` from
883 ``orig-pkg`` with the new name ``NewName``. We also support
884 abbreviated versions of the syntax: if you omit ``as NewName``,
885 we'll reexport without renaming; if you omit ``orig-pkg``, then we
886 will automatically figure out which package to reexport from, if
889 Reexported modules are useful for compatibility shims when a package
890 has been split into multiple packages, and they have the useful
891 property that if a package provides a module, and another package
892 reexports it under the same name, these are not considered a
893 conflict (as would be the case with a stub module.) They can also be
894 used to resolve name conflicts.
896 .. pkg-field:: signatures: signature list
899 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.
901 Module signatures are part of the :ref:`Backpack` extension to
902 the Haskell module system.
904 Packages that do not export any modules and only export required signatures
905 are called "signature-only packages", and their signatures are subjected to
907 <https://wiki.haskell.org/Module_signature#How_to_use_a_signature_package>`__.
911 The library section may also contain build information fields (see the
912 section on `build information`_).
916 **Sublibraries - Examples**
918 An example of the use of a private sublibrary (an internal library) is a test
919 suite that needs access to some internal modules in the package's main library,
920 which you do not otherwise want to expose. You could put those modules in an
921 internal library, which the main library and the test suite
922 :pkg-field:`build-depends` upon. Your Cabal file might then look something like
930 license: BSD-3-Clause
931 license-file: LICENSE
935 exposed-modules: Foo.Internal
936 -- NOTE: no explicit constraints on base needed
937 -- as they're inherited from the 'library' stanza
939 default-language: Haskell2010
942 exposed-modules: Foo.Public
943 build-depends: foo:foo-internal, base >= 4.3 && < 5
944 default-language: Haskell2010
947 type: exitcode-stdio-1.0
949 -- NOTE: no constraints on 'foo-internal' as same-package
950 -- dependencies implicitly refer to the same package instance
951 build-depends: foo:foo-internal, base
952 default-language: Haskell2010
954 Another example of the use of internal libraries is a package that includes one
955 or more executables but does not include a public library.
957 Internal libraries can be used to incorporate (vendor or bundle) an external
958 dependency into a package, effectively simulating *private dependencies*. Below
964 name: haddock-library
966 license: BSD-3-Clause
971 , bytestring ^>= 0.12.0.0
972 , containers ^>= 0.6.8 || ^>= 0.7.0
973 , transformers ^>= 0.6.1.0
978 build-depends: haddock-library:attoparsec
981 Documentation.Haddock
983 default-language: Haskell2010
988 , bytestring ^>= 0.12.0.0
989 , deepseq ^>= 1.5.0.0
991 hs-source-dirs: vendor/attoparsec-0.13.1.0
993 -- NB: haddock-library needs only small part of lib:attoparsec
994 -- internally, so we only bundle that subset here
996 Data.Attoparsec.ByteString
997 Data.Attoparsec.Combinator
1000 Data.Attoparsec.Internal
1002 ghc-options: -funbox-strict-fields -Wall -fwarn-tabs -O2
1004 default-language: Haskell2010
1009 A package description can contain multiple executable sections.
1010 The documentation of the `cabal run <cabal-commands.html#cabal-run>`__ command
1011 contains detailed information on how to run an executable.
1013 .. pkg-section:: executable name
1014 :synopsis: Executable build info section.
1016 Executable sections (if present) describe executable programs contained
1017 in the package and must have an argument after the section label, which
1018 defines the name of the executable. This is a freeform argument but may
1021 The executable may be described using the following fields, as well as
1022 build information fields (see the section on `build information`_).
1024 .. pkg-field:: main-is: filename (required)
1026 The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
1027 module. Note that it is the ``.hs`` filename that must be listed,
1028 even if that file is generated using a preprocessor. The source file
1029 must be relative to one of the directories listed in
1030 :pkg-field:`hs-source-dirs`. Further, while the name of the file may
1031 vary, the module itself must be named ``Main``.
1033 Starting with ``cabal-version: 1.18`` this field supports
1034 specifying a C, C++, or objC source file as the main entry point.
1036 .. pkg-field:: scope: token
1039 Whether the executable is ``public`` (default) or ``private``, i.e. meant to
1040 be run by other programs rather than the user. Private executables are
1041 installed into `$libexecdir/$libexecsubdir`.
1047 A package description can contain multiple test suite sections.
1048 The documentation of the `cabal test <cabal-commands.html#cabal-test>`__ command
1049 contains detailed information on how to run test suites.
1051 .. pkg-section:: test-suite name
1052 :synopsis: Test suite build information.
1054 Test suite sections (if present) describe package test suites and must
1055 have an argument after the section label, which defines the name of the
1056 test suite. This is a freeform argument, but may not contain spaces. It
1057 should be unique among the names of the package's other test suites, the
1058 package's executables, and the package itself. Using test suite sections
1059 requires at least Cabal version 1.9.2.
1061 The test suite may be described using the following fields, as well as
1062 build information fields (see the section on `build information`_).
1064 .. pkg-field:: type: interface (required until ``cabal-version`` 3.8)
1066 The interface type and version of the test suite. Cabal supports two
1067 test suite interfaces, called ``exitcode-stdio-1.0`` (default since ``cabal-version`` 3.8) and
1068 ``detailed-0.9``. Each of these types may require or disallow other
1069 fields as described below.
1071 Test suites using the ``exitcode-stdio-1.0`` (default since ``cabal-version`` 3.8) interface are executables
1072 that indicate test failure with a non-zero exit code when run; they may
1073 provide human-readable log information through the standard output and
1074 error channels. The ``exitcode-stdio-1.0`` type requires the ``main-is``
1077 .. pkg-field:: main-is: filename
1078 :synopsis: Module containing tests main function.
1080 :required: ``exitcode-stdio-1.0``
1081 :disallowed: ``detailed-0.9``
1083 The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
1084 module. Note that it is the ``.hs`` filename that must be listed,
1085 even if that file is generated using a preprocessor. The source file
1086 must be relative to one of the directories listed in
1087 :pkg-field:`hs-source-dirs`. This field is analogous to the ``main-is`` field
1088 of an executable section.
1090 Test suites using the ``detailed-0.9`` interface are modules exporting
1091 the symbol ``tests :: IO [Test]``. The ``Test`` type is exported by the
1092 module ``Distribution.TestSuite`` provided by Cabal. For more details,
1093 see the example below.
1095 The ``detailed-0.9`` interface allows Cabal and other test agents to
1096 inspect a test suite's results case by case, producing detailed human-
1097 and machine-readable log files. The ``detailed-0.9`` interface requires
1098 the :pkg-field:`test-module` field.
1100 .. pkg-field:: test-module: identifier
1102 :required: ``detailed-0.9``
1103 :disallowed: ``exitcode-stdio-1.0``
1105 The module exporting the ``tests`` symbol.
1107 .. pkg-field:: code-generators
1109 An optional list of preprocessors which can generate new modules
1110 for use in the test-suite.
1112 A list of executabes (possibly brought into scope by
1113 :pkg-field:`build-tool-depends`) that are run after all other
1114 preprocessors. These executables are invoked as so: ``exe-name
1115 TARGETDIR [SOURCEDIRS] -- [GHCOPTIONS]``. The arguments are, in order a target dir for
1116 output, a sequence of all source directories with source files of
1117 local lib components that the given test stanza depends on, and
1118 following a double dash, all options cabal would pass to ghc for a
1119 build. They are expected to output a newline-seperated list of
1120 generated modules which have been written to the targetdir
1121 (excepting, if written, the main module). This can
1122 be used for driving doctests and other discover-style tests generated
1126 Example: Package using ``exitcode-stdio-1.0`` interface
1127 """""""""""""""""""""""""""""""""""""""""""""""""""""""
1129 The example package description and executable source file below
1130 demonstrate the use of the ``exitcode-stdio-1.0`` interface.
1132 .. code-block:: cabal
1138 License: BSD-3-Clause
1142 type: exitcode-stdio-1.0
1143 main-is: test-foo.hs
1144 build-depends: base >= 4 && < 5
1145 default-language: Haskell2010
1147 .. code-block:: haskell
1148 :caption: test-foo.hs
1152 import System.Exit (exitFailure)
1155 putStrLn "This test always fails!"
1158 Example: Package using ``detailed-0.9`` interface
1159 """""""""""""""""""""""""""""""""""""""""""""""""
1161 The example package description and test module source file below
1162 demonstrate the use of the ``detailed-0.9`` interface. The test module
1163 also develops a simple implementation of the interface set by
1164 ``Distribution.TestSuite``, but in actual usage the implementation would
1165 be provided by the library that provides the testing facility.
1167 .. code-block:: cabal
1173 License: BSD-3-Clause
1179 build-depends: base >= 4 && < 5, Cabal >= 1.9.2 && < 2
1180 default-language: Haskell2010
1183 .. code-block:: haskell
1186 module Bar ( tests ) where
1188 import Distribution.TestSuite
1191 tests = return [ Test succeeds, Test fails ]
1193 succeeds = TestInstance
1194 { run = return $ Finished Pass
1198 , setOption = \_ _ -> Right succeeds
1200 fails = TestInstance
1201 { run = return $ Finished $ Fail "Always fails!"
1205 , setOption = \_ _ -> Right fails
1211 A package description can contain multiple benchmark sections.
1212 The documentation of the `cabal bench <cabal-commands.html#cabal-bench>`__ command
1213 contains detailed information on how to run benchmarks.
1215 .. pkg-section:: benchmark name
1217 :synopsis: Benchmark build information.
1219 Benchmark sections (if present) describe benchmarks contained in the
1220 package and must have an argument after the section label, which defines
1221 the name of the benchmark. This is a freeform argument, but may not
1222 contain spaces. It should be unique among the names of the package's
1223 other benchmarks, the package's test suites, the package's executables,
1224 and the package itself. Using benchmark sections requires at least Cabal
1227 The benchmark may be described using the following fields, as well as
1228 build information fields (see the section on `build information`_).
1230 .. pkg-field:: type: interface (required until ``cabal-version`` 3.8)
1232 The interface type and version of the benchmark. At the moment Cabal
1233 only support one benchmark interface, called ``exitcode-stdio-1.0``.
1235 Benchmarks using the ``exitcode-stdio-1.0`` (default since ``cabal-version`` 3.8) interface are executables
1236 that indicate failure to run the benchmark with a non-zero exit code
1237 when run; they may provide human-readable information through the
1238 standard output and error channels.
1240 .. pkg-field:: main-is: filename
1242 The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
1243 module. Note that it is the ``.hs`` filename that must be listed,
1244 even if that file is generated using a preprocessor. The source file
1245 must be relative to one of the directories listed in
1246 :pkg-field:`hs-source-dirs`. This field is analogous to the ``main-is``
1247 field of an executable section. Further, while the name of the file may
1248 vary, the module itself must be named ``Main``.
1251 """""""""""""""""""""""""""""""""""""""""""""""""""""""
1253 .. code-block:: cabal
1255 :name: foo-bench.cabal
1260 License: BSD-3-Clause
1264 type: exitcode-stdio-1.0
1265 main-is: bench-foo.hs
1266 build-depends: base >= 4 && < 5, time >= 1.1 && < 1.7
1267 default-language: Haskell2010
1269 .. code-block:: haskell
1270 :caption: bench-foo.hs
1272 {-# LANGUAGE BangPatterns #-}
1275 import Data.Time.Clock
1279 fib n = fib (n-1) + fib (n-2)
1282 start <- getCurrentTime
1284 end <- getCurrentTime
1285 putStrLn $ "fib 20 took " ++ show (diffUTCTime end start)
1291 .. pkg-section:: None
1293 The following fields may be optionally present in a library, executable,
1294 test suite or benchmark section, and give information for the building
1295 of the corresponding library or executable. See also the sections on
1296 `system-dependent parameters`_ and `configurations`_ for a way to supply
1297 system-dependent values for these fields.
1299 .. pkg-field:: build-depends: library list
1301 Declares the dependencies on *library* components required to build the
1302 current package component. See :pkg-field:`build-tool-depends` for declaring
1303 dependencies on build-time *tools*. Dependencies on libraries from another
1304 package should be annotated with a version constraint.
1308 A library is identified by the name of its package, optionally followed by a
1309 colon and the library's name (for example, ``my-package:my-library``). If a
1310 library name is omitted, the package's main library will be used. To refer
1311 expressly to a package's main library, use the name of the package as the
1312 library name (for example, ``my-package:my-package``). More than one library
1313 from the same package can be specified with the shorthand syntax
1314 ``my-package:{my-library1,my-library2}``.
1318 Before version 3.4 of the Cabal specification, from version 2.0, a
1319 private sublibrary (an internal library) was identified by only the name
1320 of the sublibrary. An internal library could shadow a dependency on the
1321 main library of another package, if the names clashed.
1323 See the section on :pkg-section:`library` for information about how a
1324 package can specify library components.
1326 **Version Constraints**
1328 Version constraints use the operators ``==, >=, >, <, <=`` and a
1329 version number. Multiple constraints can be combined using ``&&`` or
1334 Even though there is no ``/=`` operator, by combining operators we can
1335 skip over one or more versions, to skip a deprecated version or to skip
1336 versions that narrow the constraint solving more than we'd like.
1338 For example, the ``time =1.12.*`` series depends on ``base >=4.13 && <5``
1339 but ``time-1.12.3`` bumps the lower bound on base to ``>=4.14``. If we
1340 still want to compile with a ``ghc-8.8.*`` version of GHC that ships with
1341 ``base-4.13`` and with later GHC versions, then we can use ``time >=1.12
1342 && (time <1.12.3 || time >1.12.3)``.
1344 Hackage shows deprecated and preferred versions for packages, such as for
1345 `containers <https://hackage.haskell.org/package/containers/preferred>`_
1346 and `aeson <https://hackage.haskell.org/package/aeson/preferred>`_ for
1347 example. Deprecating package versions is not the same deprecating a
1348 package as a whole, for which Hackage keeps a `deprecated packages list
1349 <https://hackage.haskell.org/packages/deprecated>`_.
1351 If no version constraint is specified, any version is assumed to be
1352 acceptable. For example:
1359 foo >= 1.2.3 && < 1.3,
1362 Dependencies like ``foo >= 1.2.3 && < 1.3`` turn out to be very
1363 common because it is recommended practice for package versions to
1364 correspond to API versions (see PVP_).
1366 Since Cabal 1.6, there is a special wildcard syntax to help with
1371 build-depends: foo ==1.2.*
1373 It is only syntactic sugar. It is exactly equivalent to
1374 ``foo >= 1.2 && < 1.3``.
1378 A potential pitfall of the wildcard syntax is that the
1379 constraint ``nats == 1.0.*`` doesn't match the release
1380 ``nats-1`` because the version ``1`` is lexicographically less
1381 than ``1.0``. This is not an issue with the caret-operator
1382 ``^>=`` described below.
1384 Starting with Cabal 2.0, there's a new version operator to express
1385 PVP_-style major upper bounds conveniently, and is inspired by similar
1386 syntactic sugar found in other language ecosystems where it's often
1387 called the "Caret" operator:
1395 This allows to assert the positive knowledge that this package is
1396 *known* to be semantically compatible with the releases
1397 ``foo-1.2.3.4`` and ``bar-1`` respectively. The information
1398 encoded via such ``^>=``-assertions is used by the cabal solver to
1399 infer version constraints describing semantically compatible
1400 version ranges according to the PVP_ contract (see below).
1402 Another way to say this is that ``foo < 1.3`` expresses *negative*
1403 information, i.e. "``foo-1.3`` or ``foo-1.4.2`` will *not* be
1404 compatible"; whereas ``foo ^>= 1.2.3.4`` asserts the *positive*
1405 information that "``foo-1.2.3.4`` is *known* to be compatible" and (in
1406 the absence of additional information) according to the PVP_
1407 contract we can (positively) infer right away that all versions
1408 satisfying ``foo >= 1.2.3.4 && < 1.3`` will be compatible as well.
1412 More generally, the PVP_ contract implies that we can safely
1413 relax the lower bound to ``>= 1.2``, because if we know that
1414 ``foo-1.2.3.4`` is semantically compatible, then so is
1415 ``foo-1.2`` (if it typechecks). But we'd need to perform
1416 additional static analysis (i.e. perform typechecking) in order
1417 to know if our package in the role of an API consumer will
1418 successfully typecheck against the dependency ``foo-1.2``. But
1419 since we cannot do this analysis during constraint solving and
1420 to keep things simple, we pragmatically use ``foo >= 1.2.3.4``
1421 as the initially inferred approximation for the lower bound
1422 resulting from the assertion ``foo ^>= 1.2.3.4``. If further
1423 evidence becomes available that e.g. ``foo-1.2`` typechecks,
1424 one can simply revise the dependency specification to include
1425 the assertion ``foo ^>= 1.2``.
1427 The subtle but important difference in signaling allows tooling to
1428 treat explicitly expressed ``<``-style constraints and inferred
1429 (``^>=``-style) upper bounds differently. For instance,
1430 :cfg-field:`allow-newer`'s ``^``-modifier allows to relax only
1431 ``^>=``-style bounds while leaving explicitly stated
1432 ``<``-constraints unaffected.
1434 Ignoring the signaling intent, the default syntactic desugaring rules are
1436 - ``^>= x`` == ``>= x && < x.1``
1437 - ``^>= x.y`` == ``>= x.y && < x.(y+1)``
1438 - ``^>= x.y.z`` == ``>= x.y.z && < x.(y+1)``
1439 - ``^>= x.y.z.u`` == ``>= x.y.z.u && < x.(y+1)``
1444 One might expect the desugaring to truncate all version
1445 components below (and including) the patch-level, i.e.
1446 ``^>= x.y.z.u`` == ``>= x.y.z && < x.(y+1)``,
1447 as the major and minor version components alone are supposed to
1448 uniquely identify the API according to the PVP_. However, by
1449 designing ``^>=`` to be closer to the ``>=`` operator, we avoid
1450 the potentially confusing effect of ``^>=`` being more liberal
1451 than ``>=`` in the presence of patch-level versions.
1453 Consequently, the example declaration above is equivalent to
1458 foo >= 1.2.3.4 && < 1.3,
1463 Prior to Cabal 1.8, ``build-depends`` specified in each
1464 section were global to all sections. This was unintentional, but
1465 some packages were written to depend on it, so if you need your
1466 :pkg-field:`build-depends` to be local to each section, you must specify
1467 at least ``Cabal-Version: >= 1.8`` in your ``.cabal`` file.
1471 Cabal 1.20 experimentally supported module thinning and
1472 renaming in ``build-depends``; however, this support has since been
1473 removed and should not be used.
1475 Starting with Cabal 3.0, a set notation for the ``==`` and ``^>=`` operator
1476 is available. For instance,
1480 tested-with: GHC == 8.6.3, GHC == 8.4.4, GHC == 8.2.2, GHC == 8.0.2,
1481 GHC == 7.10.3, GHC == 7.8.4, GHC == 7.6.3, GHC == 7.4.2
1483 build-depends: network ^>= 2.6.3.6 || ^>= 2.7.0.2 || ^>= 2.8.0.0 || ^>= 3.0.1.0
1485 can be then written in a more convenient and concise form
1489 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 }
1491 build-depends: network ^>= { 2.6.3.6, 2.7.0.2, 2.8.0.0, 3.0.1.0 }
1494 .. pkg-field:: other-modules: identifier list
1496 A list of modules used by the component but not exposed to users.
1497 For a library component, these would be hidden modules of the
1498 library. For an executable, these would be auxiliary modules to be
1499 linked with the file named in the ``main-is`` field.
1503 Every module in the package *must* be listed in one of
1504 :pkg-field:`other-modules`, :pkg-field:`library:exposed-modules` or
1505 :pkg-field:`executable:main-is` fields.
1507 .. pkg-field:: hs-source-dir: directory list
1513 Root directories for the module hierarchy.
1515 Deprecated in favor of :pkg-field:`hs-source-dirs`.
1517 .. pkg-field:: hs-source-dirs: directory list
1521 Root directories for the module hierarchy.
1525 Components can share source directories but modules found there will be
1526 recompiled even if other components already built them, i.e., if a
1527 library and an executable share a source directory and the executable
1528 depends on the library and imports its ``Foo`` module, ``Foo`` will be
1529 compiled twice, once as part of the library and again for the executable.
1531 .. pkg-field:: default-extensions: identifier list
1534 A list of Haskell extensions used by every module. These determine
1535 corresponding compiler options enabled for all files. Extension
1536 names are the constructors of the
1537 `Extension <https://hackage.haskell.org/package/Cabal-syntax/docs/Language-Haskell-Extension.html#t:Extension>`__
1538 type. For example, ``CPP`` specifies that Haskell source files are
1539 to be preprocessed with a C preprocessor.
1541 .. pkg-field:: other-extensions: identifier list
1544 A list of Haskell extensions used by some (but not necessarily all)
1545 modules. From GHC version 6.6 onward, these may be specified by
1546 placing a ``LANGUAGE`` pragma in the source files affected e.g.
1548 .. code-block:: haskell
1550 {-# LANGUAGE CPP, MultiParamTypeClasses #-}
1552 In Cabal-1.24 the dependency solver will use this and
1553 :pkg-field:`default-extensions` information. Cabal prior to 1.24 will abort
1554 compilation if the current compiler doesn't provide the extensions.
1556 If you use some extensions conditionally, using CPP or conditional
1557 module lists, it is good to replicate the condition in
1558 :pkg-field:`other-extensions` declarations:
1562 other-extensions: CPP
1564 other-extensions: PolyKinds
1566 You could also omit the conditionally used extensions, as they are
1567 for information only, but it is recommended to replicate them in
1568 :pkg-field:`other-extensions` declarations.
1570 .. pkg-field:: default-language: identifier
1573 Specifies a language standard or a group of language extensions to be activated for the project. In the case of GHC, `see here for details <https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/control.html#controlling-extensions>`__.
1575 The possible values are:
1577 - ``GHC2024`` (only available for GHC version ``9.10`` or later)
1578 - ``GHC2021`` (only available for GHC version ``9.2`` or later)
1582 .. pkg-field:: other-languages: identifier
1587 .. pkg-field:: extensions: identifier list
1591 Deprecated in favor of :pkg-field:`default-extensions`.
1593 .. pkg-field:: build-tool-depends: package:executable list
1596 A list of Haskell executables needed to build this component. Executables are provided
1597 during the whole duration of the component, so this field can be used for executables
1598 needed during :pkg-section:`test-suite` as well.
1600 Each is specified by the package containing the executable and the name of the
1601 executable itself, separated by a colon, and optionally followed by a version bound.
1603 All executables defined in the given Cabal file are termed as *internal* dependencies
1604 as opposed to the rest which are *external* dependencies.
1606 Each of the two is handled differently:
1608 1. External dependencies can (and should) contain a version bound like conventional
1609 :pkg-field:`build-depends` dependencies.
1610 2. Internal dependencies should not contain a version bound, as they will be always
1611 resolved within the same configuration of the package in the build plan.
1612 Specifically, version bounds that include the package's version will be warned for
1613 being extraneous, and version bounds that exclude the package's version will raise
1614 an error for being impossible to follow.
1616 For example (1) using a test-suite to make sure README.md Haskell snippets are tested using
1617 `markdown-unlit <http://hackage.haskell.org/package/markdown-unlit>`__:
1621 build-tool-depends: markdown-unlit:markdown-unlit >= 0.5.0 && < 0.6
1623 For example (2) using a test-suite to test executable behaviour in the same package:
1627 build-tool-depends: mypackage:executable
1629 Cabal tries to make sure that all specified programs are atomically built and prepended
1630 on the ``PATH`` shell variable before building the component in question, but can only do
1631 so for Nix-style builds. Specifically:
1633 a) For Nix-style local builds, both internal and external dependencies.
1634 b) For old-style builds, only for internal dependencies [#old-style-build-tool-depends]_.
1635 It's up to the user to provide needed executables in this case under ``PATH``.
1640 :pkg-field:`build-tool-depends` was added in Cabal 2.0, and it will
1641 be ignored (with a warning) with old versions of Cabal. See
1642 :pkg-field:`build-tools` for more information about backwards
1645 .. pkg-field:: build-tools: program list
1649 Deprecated in favor of :pkg-field:`build-tool-depends`, but :ref:`see below for backwards compatibility information <buildtoolsbc>`.
1651 A list of Haskell programs needed to build this component.
1652 Each may be followed by an optional version bound.
1653 Confusingly, each program in the list either refer to one of three things:
1655 1. Another executables in the same package (supported since Cabal 1.12)
1657 2. Tool name contained in Cabal's :ref:`hard-coded set of common tools <buildtoolsmap>`
1659 3. A pre-built executable that should already be on the ``PATH``
1660 (supported since Cabal 2.0)
1662 These cases are listed in order of priority:
1663 an executable in the package will override any of the hard-coded packages with the same name,
1664 and a hard-coded package will override any executable on the ``PATH``.
1666 In the first two cases, the list entry is desugared into a :pkg-field:`build-tool-depends` entry.
1667 In the first case, the entry is desugared into a :pkg-field:`build-tool-depends` entry by prefixing with ``$pkg:``.
1668 In the second case, it is desugared by looking up the package and executable name in a hard-coded table.
1669 In either case, the optional version bound is passed through unchanged.
1670 Refer to the documentation for :pkg-field:`build-tool-depends` to understand the desugared field's meaning, along with restrictions on version bounds.
1674 **Backward Compatibility**
1676 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.
1677 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.
1678 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``.
1682 **Set of Known Tool Names**
1684 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::
1686 build-tools: alex >= 3.2.1 && < 3.3, happy >= 1.19.5 && < 1.20
1688 is simply desugared into the equivalent specification::
1690 build-tool-depends: alex:alex >= 3.2.1 && < 3.3, happy:happy >= 1.19.5 && < 1.20
1692 +--------------------------+-----------------------------------+-----------------+
1693 | :pkg-field:`build-tools` | desugared | Note |
1694 | identifier | :pkg-field:`build-tool-depends` | |
1696 +==========================+===================================+=================+
1697 | ``alex`` | ``alex:alex`` | |
1698 +--------------------------+-----------------------------------+-----------------+
1699 | ``c2hs`` | ``c2hs:c2hs`` | |
1700 +--------------------------+-----------------------------------+-----------------+
1701 | ``cpphs`` | ``cpphs:cpphs`` | |
1702 +--------------------------+-----------------------------------+-----------------+
1703 | ``greencard`` | ``greencard:greencard`` | |
1704 +--------------------------+-----------------------------------+-----------------+
1705 | ``haddock`` | ``haddock:haddock`` | |
1706 +--------------------------+-----------------------------------+-----------------+
1707 | ``happy`` | ``happy:happy`` | |
1708 +--------------------------+-----------------------------------+-----------------+
1709 | ``hsc2hs`` | ``hsc2hs:hsc2hs`` | |
1710 +--------------------------+-----------------------------------+-----------------+
1711 | ``hscolour`` | ``hscolour:hscolour`` | |
1712 +--------------------------+-----------------------------------+-----------------+
1713 | ``hspec-discover`` | ``hspec-discover:hspec-discover`` | since Cabal 2.0 |
1714 +--------------------------+-----------------------------------+-----------------+
1716 This built-in set can be programmatically extended via use of the
1717 :ref:`Hooks build type<setup-hooks>` .
1719 .. pkg-field:: buildable: boolean
1723 Is the component buildable? Like some of the other fields below,
1724 this field is more useful with the slightly more elaborate form of
1725 the simple build infrastructure described in the section on
1726 `system-dependent parameters`_.
1728 .. pkg-field:: ghc-options: token list
1730 Additional options for GHC.
1732 If specifying extensions (via ``-X<Extension>`` flags) one can often achieve
1733 the same effect using the :pkg-field:`default-extensions` field, which is
1736 Options required only by one module may be specified by placing an
1737 ``OPTIONS_GHC`` pragma in the source file affected.
1739 As with many other fields, whitespace can be escaped by using
1740 Haskell string syntax. Example:
1741 ``ghc-options: -Wcompat "-with-rtsopts=-T -I1" -Wall``.
1743 .. pkg-field:: ghc-prof-options: token list
1745 Additional options for GHC when the package is built with profiling
1748 Note that as of Cabal-1.24, the default profiling detail level
1749 defaults to ``exported-functions`` for libraries and
1750 ``toplevel-functions`` for executables. For GHC these correspond to
1751 the flags ``-fprof-auto-exported`` and ``-fprof-auto-top``. Prior to
1752 Cabal-1.24 the level defaulted to ``none``. These levels can be
1753 adjusted by the person building the package with the
1754 ``--profiling-detail`` and ``--library-profiling-detail`` flags.
1756 It is typically better for the person building the package to pick
1757 the profiling detail level rather than for the package author. So
1758 unless you have special needs it is probably better not to specify
1759 any of the GHC ``-fprof-auto*`` flags here. However if you wish to
1760 override the profiling detail level, you can do so using the
1761 :pkg-field:`ghc-prof-options` field: use ``-fno-prof-auto`` or one of the
1762 other ``-fprof-auto*`` flags.
1764 .. pkg-field:: ghc-shared-options: token list
1766 Additional options for GHC when the package is built as shared
1767 library. The options specified via this field are combined with the
1768 ones specified via :pkg-field:`ghc-options`, and are passed to GHC during
1769 both the compile and link phases.
1771 .. pkg-field:: ghc-prof-shared-options: token list
1773 Additional options for GHC when the package is built as shared profiling
1774 library. The options specified via this field are combined with the
1775 ones specified via :pkg-field:`ghc-options`, and are passed to GHC during
1776 both the compile and link phases.
1778 .. pkg-field:: ghcjs-options: token list
1780 Like :pkg-field:`ghc-options` but applies to GHCJS
1782 .. pkg-field:: ghcjs-prof-options: token list
1784 Like :pkg-field:`ghc-prof-options` but applies to GHCJS
1786 .. pkg-field:: ghcjs-shared-options: token list
1788 Like :pkg-field:`ghc-shared-options` but applies to GHCJS
1790 .. pkg-field:: ghcjs-prof-shared-options: token list
1792 Like :pkg-field:`ghc-prof-shared-options` but applies to GHCJS
1794 .. pkg-field:: includes: filename list
1798 From GHC 6.10.1, :pkg-field:`includes` has no effect when compiling with
1799 GHC. From Cabal 2.0, support for GHC versions before GHC 6.12 was removed.
1801 A list of header files to be included in any compilations via C.
1802 This field applies to both header files that are already installed
1803 on the system and to those coming with the package to be installed.
1804 The former files should be found in absolute paths, while the latter
1805 files should be found in paths relative to the top of the source
1806 tree or relative to one of the directories listed in
1807 :pkg-field:`include-dirs`.
1809 These files typically contain function prototypes for foreign
1810 imports used by the package. This is in contrast to
1811 :pkg-field:`install-includes`, which lists header files that are intended
1812 to be exposed to other packages that transitively depend on this
1815 .. pkg-field:: install-includes: filename list
1817 A list of header files from this package to be installed into
1818 ``$libdir/includes`` when the package is installed. Files listed in
1819 :pkg-field:`install-includes` should be found in relative to the top of the
1820 source tree or relative to one of the directories listed in
1821 :pkg-field:`include-dirs`.
1823 :pkg-field:`install-includes` is typically used to name header files that
1824 contain prototypes for foreign imports used in Haskell code in this
1825 package, for which the C implementations are also provided with the
1826 package. For example, here is a ``.cabal`` file for a hypothetical
1827 ``bindings-clib`` package that bundles the C source code for ``clib``::
1831 install-includes: clib.h
1833 Now any package that depends (directly or transitively) on the
1834 ``bindings-clib`` library can use ``clib.h``.
1836 Note that in order for files listed in :pkg-field:`install-includes` to be
1837 usable when compiling the package itself, they need to be listed in
1838 the :pkg-field:`includes` field as well.
1840 .. pkg-field:: include-dirs: directory list
1842 A list of directories to search for header files, when preprocessing
1843 with ``c2hs``, ``hsc2hs``, ``cpphs`` or the C preprocessor, and also
1844 when compiling via C. Directories can be absolute paths (e.g., for
1845 system directories) or paths that are relative to the top of the
1846 source tree. Cabal looks in these directories when attempting to
1847 locate files listed in :pkg-field:`includes` and
1848 :pkg-field:`install-includes`.
1850 Directories here will be passed as ``-I<dir>`` flags to GHC.
1852 .. pkg-field:: c-sources: filename list
1854 A list of C source files to be compiled and linked with the Haskell
1857 .. pkg-field:: cxx-sources: filename list
1860 A list of C++ source files to be compiled and linked with the Haskell
1861 files. Useful for segregating C and C++ sources when supplying different
1862 command-line arguments to the compiler via the :pkg-field:`cc-options`
1863 and the :pkg-field:`cxx-options` fields. The files listed in the
1864 :pkg-field:`cxx-sources` can reference files listed in the
1865 :pkg-field:`c-sources` field and vice-versa. The object files will be linked
1868 .. pkg-field:: asm-sources: filename list
1871 A list of assembly source files to be compiled and linked with the
1874 .. pkg-field:: cmm-sources: filename list
1877 A list of C-- source files to be compiled and linked with the Haskell
1880 .. pkg-field:: js-sources: filename list
1882 A list of JavaScript source files to be linked with the Haskell
1883 files (only for JavaScript targets).
1885 .. pkg-field:: extra-libraries: token list
1887 A list of extra libraries to link with (when not linking fully static
1888 executables). Libraries will be passed as ``-optl-l<lib>`` flags to GHC.
1890 .. pkg-field:: extra-libraries-static: token list
1892 A list of extra libraries to link with (when linking fully static
1895 .. pkg-field:: extra-ghci-libraries: token list
1897 A list of extra libraries to be used instead of 'extra-libraries'
1898 when the package is loaded with GHCi.
1900 .. pkg-field:: extra-bundled-libraries: token list
1903 A list of libraries that are supposed to be copied from the build
1904 directory alongside the produced Haskell libraries. Note that you
1905 are under the obligation to produce those libraries in the build
1906 directory (e.g. via a custom setup). Libraries listed here will
1907 be included when ``copy``-ing packages and be listed in the
1908 ``hs-libraries`` of the package configuration in the package database.
1909 Library names must either be prefixed with "HS" or "C" and corresponding
1910 library file names must match:
1912 - Libraries with name "HS<library-name>":
1913 - `libHS<library-name>.a`
1914 - `libHS<library-name>-ghc<ghc-flavour><ghc-version>.<dyn-library-extension>*`
1915 - Libraries with name "C<library-name>":
1916 - `libC<library-name>.a`
1917 - `lib<library-name>.<dyn-library-extension>*`
1919 .. pkg-field:: extra-lib-dirs: directory list
1921 A list of directories to search for libraries (when not linking fully static
1922 executables). Directories will be passed as ``-optl-L<dir>`` flags to GHC.
1924 .. pkg-field:: extra-lib-dirs-static: directory list
1926 A list of directories to search for libraries (when linking fully static
1929 .. pkg-field:: extra-library-flavours: notsure
1933 .. pkg-field:: extra-dynamic-library-flavours: notsure
1937 .. pkg-field:: cc-options: token list
1939 Command-line arguments to be passed to the Haskell compiler for the C
1940 compiling phase (as ``-optc`` flags for GHC). Since the
1941 arguments are compiler-dependent, this field is more useful with the
1942 setup described in the section on `system-dependent parameters`_.
1944 .. pkg-field:: cpp-options: token list
1946 Command-line arguments for pre-processing Haskell code. Applies to
1947 Haskell source and other pre-processed Haskell source like .hsc
1948 .chs. Does not apply to C code, that's what cc-options is for.
1949 Flags here will be passed as ``-optP`` flags to GHC.
1951 .. pkg-field:: cxx-options: token list
1954 Command-line arguments to be passed to the Haskell compiler for the C++
1955 compiling phase (as ``-optcxx`` flags for GHC).
1956 The C++ sources to which these command-line arguments
1957 should be applied can be specified with the :pkg-field:`cxx-sources`
1958 field. Command-line options for C and C++ can be passed separately to
1959 the compiler when compiling both C and C++ sources by segregating the C
1960 and C++ sources with the :pkg-field:`c-sources` and
1961 :pkg-field:`cxx-sources` fields respectively, and providing different
1962 command-line arguments with the :pkg-field:`cc-options` and the
1963 :pkg-field:`cxx-options` fields.
1965 .. pkg-field:: cmm-options: token list
1968 Command-line arguments to be passed to the Haskell compiler when compiling
1969 C-- code. See also :pkg-field:`cmm-sources`.
1971 .. pkg-field:: asm-options: token list
1974 Command-line arguments to be passed to the Haskell compiler (as ``-opta``
1975 flags for GHC) when compiling assembler code. See also :pkg-field:`asm-sources`.
1977 .. pkg-field:: ld-options: token list
1979 Command-line arguments to be passed to the Haskell compiler (as ``-optl``
1980 flags for GHC) for the linking phase. Note that only executables (including
1981 test-suites and benchmarks) are linked so this has no effect in libraries.
1982 Since the arguments are compiler-dependent, this field is more useful with
1983 the setup described in the section on `system-dependent parameters`_.
1985 .. pkg-field:: hsc2hs-options: token list
1988 Command-line arguments to be passed to ``hsc2hs``.
1990 .. pkg-field:: pkgconfig-depends: package list
1993 `pkg-config <http://www.freedesktop.org/wiki/Software/pkg-config/>`__
1994 packages, needed to build this package. They can be annotated with
1995 versions, e.g. ``gtk+-2.0 >= 2.10, cairo >= 1.0``. If no version
1996 constraint is specified, any version is assumed to be acceptable.
1997 Cabal uses ``pkg-config`` to find if the packages are available on
1998 the system and to find the extra compilation and linker options
1999 needed to use the packages.
2001 If you need to bind to a C library that supports ``pkg-config`` then
2002 it is much preferable to use this field rather than hard code options
2003 into the other fields. ``pkg-config --list-all`` will show you all
2004 supported libraries. Depending on your system you may need to adjust
2005 ``PKG_CONFIG_PATH``.
2007 .. pkg-field:: frameworks: token list
2009 On Darwin/MacOS X, a list of frameworks to link to. See Apple's
2010 developer documentation for more details on frameworks. This entry
2011 is ignored on all other platforms.
2013 .. pkg-field:: extra-framework-dirs: directory list
2016 On Darwin/MacOS X, a list of directories to search for frameworks.
2017 This entry is ignored on all other platforms.
2019 .. pkg-field:: mixins: mixin list
2022 Supported only in GHC 8.2 and later. A list of packages mentioned in the
2023 :pkg-field:`build-depends` field, each optionally accompanied by a list of
2024 module and module signature renamings. A valid mixin obeys the
2029 Mixin ::= PackageName IncludeRenaming
2030 IncludeRenaming ::= ModuleRenaming { "requires" ModuleRenaming }
2033 | "(" Renaming "," ... "," Renaming ")"
2034 | "hiding" "(" ModuleName "," ... "," ModuleName ")"
2037 | ModuleName "as" ModuleName
2039 The simplest mixin syntax is simply the name of a package mentioned in the
2040 :pkg-field:`build-depends` field. For example:
2050 But this doesn't have any effect. More interesting is to use the mixin
2051 entry to rename one or more modules from the package, like this:
2057 foo (Foo.Bar as AnotherFoo.Bar, Foo.Baz as AnotherFoo.Baz)
2059 Note that renaming a module like this will hide all the modules
2060 that are not explicitly named.
2062 Modules can also be hidden:
2068 foo hiding (Foo.Bar)
2070 Hiding modules exposes everything that is not explicitly hidden.
2074 Cabal files with :pkg-field:`cabal-version` < 3.0 suffer from an
2075 infelicity in how the entries of :pkg-field:`mixins` are parsed: an
2076 entry will fail to parse if the provided renaming clause has whitespace
2077 after the opening parenthesis.
2079 See issues :issue:`5150`, :issue:`4864`, and :issue:`5293`.
2081 There can be multiple mixin entries for a given package, in effect creating
2082 multiple copies of the dependency:
2088 foo (Foo.Bar as AnotherFoo.Bar, Foo.Baz as AnotherFoo.Baz),
2089 foo (Foo.Bar as YetAnotherFoo.Bar)
2091 The ``requires`` clause is used to rename the module signatures required by
2098 foo (Foo.Bar as AnotherFoo.Bar) requires (Foo.SomeSig as AnotherFoo.SomeSig)
2100 Signature-only packages don't have any modules, so only the signatures can
2101 be renamed, with the following syntax:
2107 sigonly requires (SigOnly.SomeSig as AnotherSigOnly.SomeSig)
2109 See the :pkg-field:`library:signatures` field for more details.
2111 Mixin packages are part of the :ref:`Backpack` extension to the
2112 Haskell module system.
2114 The matching of the module signatures required by a
2115 :pkg-field:`build-depends` dependency with the implementation modules
2116 present in another dependency is triggered by a coincidence of names. When
2117 the names of the signature and of the implementation are already the same,
2118 the matching is automatic. But when the names don't coincide, or we want to
2119 instantiate a signature in two different ways, adding mixin entries that
2120 perform renamings becomes necessary.
2124 :ref:`Backpack` has the limitation that implementation modules that instantiate
2125 signatures required by a :pkg-field:`build-depends` dependency can't
2126 reside in the same component that has the dependency. They must reside
2127 in a different package dependency, or at least in a separate internal
2133 Foreign libraries are system libraries intended to be linked against
2134 programs written in C or other "foreign" languages. They
2135 come in two primary flavours: dynamic libraries (``.so`` files on Linux,
2136 ``.dylib`` files on OSX, ``.dll`` files on Windows, etc.) are linked against
2137 executables when the executable is run (or even lazily during
2138 execution), while static libraries (``.a`` files on Linux/OSX, ``.lib``
2139 files on Windows) get linked against the executable at compile time.
2141 Foreign libraries only work with GHC 7.8 and later.
2143 A typical stanza for a foreign library looks like
2147 foreign-library myforeignlib
2149 lib-version-info: 6:3:2
2153 mod-def-file: MyForeignLib.def
2155 other-modules: MyForeignLib.SomeModule
2156 MyForeignLib.SomeOtherModule
2157 build-depends: base >=4.7 && <4.9
2159 c-sources: csrc/MyForeignLibWrapper.c
2160 default-language: Haskell2010
2163 .. pkg-section:: foreign-library name
2165 :synopsis: Foreign library build information.
2167 Build information for `foreign libraries`_.
2169 .. pkg-field:: type: foreign library type
2171 Cabal recognizes ``native-static`` and ``native-shared`` here, although
2172 we currently only support building `native-shared` libraries.
2174 .. pkg-field:: options: foreign library option list
2176 Options for building the foreign library, typically specific to the
2177 specified type of foreign library. Currently we only support
2178 ``standalone`` here. A standalone dynamic library is one that does not
2179 have any dependencies on other (Haskell) shared libraries; without
2180 the ``standalone`` option the generated library would have dependencies
2181 on the Haskell runtime library (``libHSrts``), the base library
2182 (``libHSbase``), etc. Currently, ``standalone`` *must* be used on Windows
2183 and *must not* be used on any other platform.
2185 .. pkg-field:: mod-def-file: filename
2187 This option can only be used when creating dynamic Windows libraries
2188 (that is, when using ``native-shared`` and the ``os`` is ``Windows``). If
2189 used, it must be a path to a *module definition file*. The details of
2190 module definition files are beyond the scope of this document; see the
2191 `GHC <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/win32-dlls.html>`_
2192 manual for some details and some further pointers.
2194 .. pkg-field:: lib-version-info: current:revision:age
2196 This field is currently only used on Linux.
2198 This field specifies a Libtool-style version-info field that sets
2199 an appropriate ABI version for the foreign library. Note that the
2200 three numbers specified in this field do not directly specify the
2201 actual ABI version: ``6:3:2`` results in library version ``4.2.3``.
2203 With this field set, the SONAME of the library is set, and symlinks
2206 How you should bump this field on an ABI change depends on the
2207 breakage you introduce:
2209 - Programs using the previous version may use the new version as
2210 drop-in replacement, and programs using the new version can also
2211 work with the previous one. In other words, no recompiling nor
2212 relinking is needed. In this case, bump ``revision`` only, don't
2213 touch current nor age.
2214 - Programs using the previous version may use the new version as
2215 drop-in replacement, but programs using the new version may use
2216 APIs not present in the previous one. In other words, a program
2217 linking against the new version may fail with "unresolved
2218 symbols" if linking against the old version at runtime: set
2219 revision to 0, bump current and age.
2220 - Programs may need to be changed, recompiled, and relinked in
2221 order to use the new version. Bump current, set revision and age
2224 Also refer to the Libtool documentation on the version-info field.
2226 .. pkg-field:: lib-version-linux: version
2228 This field is only used on Linux.
2230 Specifies the library ABI version directly for foreign libraries
2231 built on Linux: so specifying ``4.2.3`` causes a library
2232 ``libfoo.so.4.2.3`` to be built with SONAME ``libfoo.so.4``, and
2233 appropriate symlinks ``libfoo.so.4`` and ``libfoo.so`` to be
2236 Note that typically foreign libraries should export a way to initialize
2237 and shutdown the Haskell runtime. In the example above, this is done by
2238 the ``csrc/MyForeignLibWrapper.c`` file, which might look something like
2245 HsBool myForeignLibInit(void){
2247 char *argv[] = { "+RTS", "-A32m", NULL };
2248 char **pargv = argv;
2250 // Initialize Haskell runtime
2251 hs_init(&argc, &pargv);
2253 // do any other initialization here and
2254 // return false if there was a problem
2255 return HS_BOOL_TRUE;
2258 void myForeignLibExit(void){
2262 With modern ghc regular libraries are installed in directories that contain
2263 package keys. This isn't usually a problem because the package gets registered
2264 in ghc's package DB and so we can figure out what the location of the library
2265 is. Foreign libraries however don't get registered, which means that we'd have
2266 to have a way of finding out where a platform library got installed (other than by
2267 searching the ``lib/`` directory). Instead, we install foreign libraries in
2273 Library and executable sections may include conditional blocks, which
2274 test for various system parameters and configuration flags. The flags
2275 mechanism is rather generic, but most of the time a flag represents
2276 certain feature, that can be switched on or off by the package user.
2277 Here is an example package description file using configurations:
2279 Example: A package containing a library and executable programs
2280 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2287 License: BSD-3-Clause
2289 Synopsis: Test package to test configurations
2294 Description: Enable debug support
2299 Description: Include API for web frontend.
2304 description: Whether to build against @directory >= 1.2@
2305 -- This is an automatic flag which the solver will
2306 -- assign automatically while searching for a solution
2309 Build-Depends: base >= 4.2 && < 4.9
2310 Exposed-Modules: Testing.Test1
2311 Default-Extensions: CPP
2312 Default-Language: Haskell2010
2316 CPP-Options: -DDEBUG
2318 CC-Options: "-DDEBUG"
2320 CC-Options: "-DNDEBUG"
2322 if flag(WebFrontend)
2323 Build-Depends: cgi >= 0.42 && < 0.44
2324 Other-Modules: Testing.WebStuff
2325 CPP-Options: -DWEBFRONTEND
2327 if flag(NewDirectory)
2328 build-depends: directory >= 1.2 && < 1.4
2329 Build-Depends: time >= 1.0 && < 1.9
2331 build-depends: directory == 1.1.*
2332 Build-Depends: old-time >= 1.0 && < 1.2
2336 Other-Modules: Testing.Test1
2337 Build-Depends: base >= 4.2 && < 4.9
2338 Default-Language: Haskell2010
2341 CC-Options: "-DDEBUG"
2342 CPP-Options: -DDEBUG
2347 Flags, conditionals, library and executable sections use layout to
2348 indicate structure. This is very similar to the Haskell layout rule.
2349 Entries in a section have to all be indented to the same level which
2350 must be more than the section header. Tabs are not allowed to be used
2353 As an alternative to using layout you can also use explicit braces
2354 ``{}``. In this case the indentation of entries in a section does not
2355 matter, though different fields within a block must be on different
2356 lines. Here is a bit of the above example again, using braces:
2358 Example: Using explicit braces rather than indentation for layout
2359 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2366 License: BSD-3-Clause
2368 Synopsis: Test package to test configurations
2373 Description: Enable debug support
2379 Build-Depends: base >= 4.2 && < 4.9
2380 Exposed-Modules: Testing.Test1
2381 Default-Extensions: CPP
2382 Default-language: Haskell2010
2384 CPP-Options: -DDEBUG
2386 CC-Options: "-DDEBUG"
2388 CC-Options: "-DNDEBUG"
2396 .. pkg-section:: flag name
2397 :synopsis: Flag declaration.
2399 Flag section declares a flag which can be used in `conditional blocks`_.
2401 Flag names are case-insensitive and must match ``[[:alnum:]_][[:alnum:]_-]*``
2402 regular expression, or expressed as ABNF_:
2404 .. code-block:: abnf
2406 flag-name = (UALNUM / "_") *(UALNUM / "_" / "-")
2408 UALNUM = UALPHA / DIGIT
2409 UALPHA = ... ; set of alphabetic Unicode code-points
2413 Hackage accepts ASCII-only flags, ``[a-zA-Z0-9_][a-zA-Z0-9_-]*`` regexp.
2415 .. pkg-field:: description: freeform
2417 The description of this flag.
2419 .. pkg-field:: default: boolean
2423 The default value of this flag.
2427 This value may be :ref:`overridden in several
2428 ways <controlling flag assignments>`. The
2429 rationale for having flags default to True is that users usually
2430 want new features as soon as they are available. Flags representing
2431 features that are not (yet) recommended for most users (such as
2432 experimental features or debugging support) should therefore
2433 explicitly override the default to False.
2435 .. pkg-field:: manual: boolean
2440 By default, Cabal will first try to satisfy dependencies with the
2441 default flag value and then, if that is not possible, with the
2442 negated value. However, if the flag is manual, then the default
2443 value (which can be overridden by commandline flags) will be used.
2445 .. _conditional-blocks:
2450 Conditional blocks may appear anywhere inside a component or common
2451 section. They have to follow rather strict formatting rules. Conditional
2452 blocks must always be of the shape
2457 property-descriptions-or-conditionals
2464 property-descriptions-or-conditionals
2466 property-descriptions-or-conditionals
2468 Note that the ``if`` and the condition have to be all on the same line.
2470 Since Cabal 2.2 conditional blocks support ``elif`` construct.
2475 property-descriptions-or-conditionals
2477 property-descriptions-or-conditionals
2479 property-descriptions-or-conditionals
2486 Conditions can be formed using boolean tests and the boolean operators
2487 ``||`` (disjunction / logical "or"), ``&&`` (conjunction / logical
2488 "and"), or ``!`` (negation / logical "not"). The unary ``!`` takes
2489 highest precedence, ``||`` takes lowest. Precedence levels may be
2490 overridden through the use of parentheses. For example,
2491 ``os(darwin) && !arch(i386) || os(freebsd)`` is equivalent to
2492 ``(os(darwin) && !(arch(i386))) || os(freebsd)``.
2494 The following tests are currently supported.
2497 Tests if the current operating system is *name*. The argument is
2498 tested against ``System.Info.os`` on the target system. There is
2499 unfortunately some disagreement between Haskell implementations
2500 about the standard values of ``System.Info.os``. Cabal canonicalises
2501 it so that in particular ``os(windows)`` works on all
2502 implementations. If the canonicalised os names match, this test
2503 evaluates to true, otherwise false. The match is case-insensitive.
2504 :samp:`arch({name})`
2505 Tests if the current architecture is *name*. *name* should be the name of
2506 one of the nullary constructors of ``Distribution.System.Arch`` (e.g.
2507 ``x86_64``, ``aarch64`` or ``i386``), otherwise it will be treated as an
2508 'other architecture' of the given *name*. It will be compared with
2509 ``Distribution.System.buildArch``, which is derived from
2510 ``System.Info.arch`` (certain architectures are treated as synonymous; e.g.
2511 ``aarch64`` / ``arm64`` or ``powerpc64`` / ``powerpc64le`` are not
2512 distinguished). For a match, this test evaluates to true, otherwise false.
2513 The match is case-insensitive.
2514 :samp:`impl({compiler})`
2515 Tests for the configured Haskell implementation. An optional version
2516 constraint may be specified (for example ``impl(ghc >= 6.6.1)``). If
2517 the configured implementation is of the right type and matches the
2518 version constraint, then this evaluates to true, otherwise false.
2519 The match is case-insensitive.
2521 Note that including a version constraint in an ``impl`` test causes
2522 it to check for two properties:
2524 - The current compiler has the specified name, and
2526 - The compiler's version satisfied the specified version constraint
2528 As a result, ``!impl(ghc >= x.y.z)`` is not entirely equivalent to
2529 ``impl(ghc < x.y.z)``. The test ``!impl(ghc >= x.y.z)`` checks that:
2531 - The current compiler is not GHC, or
2533 - The version of GHC is earlier than version x.y.z.
2535 :samp:`flag({name})`
2536 Evaluates to the current assignment of the flag of the given name.
2537 Flag names are case insensitive. Testing for flags that have not
2538 been introduced with a flag section is an error.
2540 Constant value true.
2542 Constant value false.
2544 .. _resolution-of-conditions-and-flags:
2546 Resolution of Conditions and Flags
2547 """"""""""""""""""""""""""""""""""
2549 If a package descriptions specifies configuration flags the package user
2550 can :ref:`control these in several ways <controlling flag assignments>`. If the
2551 user does not fix the value of a flag, Cabal will try to find a flag
2552 assignment in the following way.
2554 - For each flag specified, it will assign its default value, evaluate
2555 all conditions with this flag assignment, and check if all
2556 dependencies can be satisfied. If this check succeeded, the package
2557 will be configured with those flag assignments.
2559 - If dependencies were missing, the last flag (as by the order in which
2560 the flags were introduced in the package description) is tried with
2561 its alternative value and so on. This continues until either an
2562 assignment is found where all dependencies can be satisfied, or all
2563 possible flag assignments have been tried.
2565 To put it another way, Cabal does a complete backtracking search to find
2566 a satisfiable package configuration. It is only the dependencies
2567 specified in the :pkg-field:`build-depends` field in conditional blocks that
2568 determine if a particular flag assignment is satisfiable
2569 (:pkg-field:`build-tools` are not considered). The order of the declaration and
2570 the default value of the flags determines the search order. Flags
2571 overridden on the command line fix the assignment of that flag, so no
2572 backtracking will be tried for that flag.
2574 If no suitable flag assignment could be found, the configuration phase
2575 will fail and a list of missing dependencies will be printed. Note that
2576 this resolution process is exponential in the worst case (i.e., in the
2577 case where dependencies cannot be satisfied). There are some
2578 optimizations applied internally, but the overall complexity remains
2581 Meaning of field values when using conditionals
2582 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2584 During the configuration phase, a flag assignment is chosen, all
2585 conditionals are evaluated, and the package description is combined into
2586 a flat package descriptions. If the same field is declared both inside
2587 a conditional and outside then they are combined using the following rules.
2589 - Boolean fields are combined using conjunction (logical "and").
2591 - List fields are combined by appending the inner items to the outer
2596 other-extensions: CPP
2598 other-extensions: MultiParamTypeClasses
2600 when compiled using GHC will be combined to
2604 other-extensions: CPP, MultiParamTypeClasses
2606 Similarly, if two conditional sections appear at the same nesting
2607 level, properties specified in the latter will come after properties
2608 specified in the former.
2610 - All other fields must not be specified in ambiguous ways. For example
2615 if flag(useothermain)
2616 Main-is: OtherMain.hs
2618 will lead to an error. Instead use
2622 if flag(useothermain)
2623 Main-is: OtherMain.hs
2632 .. pkg-section:: common name
2634 :synopsis: Common build info section
2636 Starting with Cabal-2.2 it's possible to use common build info stanzas.
2641 build-depends: base ^>= 4.18
2645 build-depends: tasty ^>= 1.4
2649 exposed-modules: Foo
2650 default-language: Haskell2010
2653 import: deps, test-deps
2654 type: exitcode-stdio-1.0
2657 default-language: Haskell2010
2659 - You can use `build information`_ fields in common stanzas.
2661 - Common stanzas must be defined before use.
2663 - Common stanzas can import other common stanzas.
2665 - You can import multiple stanzas at once. Stanza names must be separated by commas.
2667 - ``import`` must be the first field in a section. Since Cabal 3.0 imports
2668 are also allowed inside conditionals.
2672 The name `import` was chosen, because there is ``includes`` field.
2674 .. pkg-section:: None
2676 .. pkg-field:: import: token-list
2681 .. _pkg-author-source:
2683 *Source code* repository marker
2684 -------------------------------
2686 .. pkg-section:: source-repository
2689 A marker that points to the *source code* for this package within a
2690 **source code repository**.
2692 There are two kinds. You can specify one or the other or both at once:
2694 - The ``head`` kind refers to the latest development branch of the
2695 package. This may be used for example to track activity of a project
2696 or as an indication to outside developers what sources to get for
2697 making new contributions.
2699 - The ``this`` kind refers to the branch and tag of a repository that
2700 contains the sources for this version or release of a package. For most
2701 source control systems this involves specifying a tag, id or hash of some
2702 form and perhaps a branch.
2704 As an example, here are the repositories for the Cabal library. Note that the
2705 ``this`` kind of repository specifies a tag.
2709 source-repository head
2711 location: https://github.com/haskell/cabal
2713 source-repository this
2715 location: https://github.com/haskell/cabal
2718 The :ref:`cabal get<cabal-get>` command uses the kind of repository with
2719 its ``--source-repository`` option, if provided.
2721 .. _source-repository-fields:
2723 The :ref:`VCS fields<vcs-fields>` of ``source-repository`` are:
2726 data SourceRepo = SourceRepo
2727 { repoKind :: RepoKind
2728 , repoType :: Maybe RepoType
2729 , repoLocation :: Maybe String
2730 , repoModule :: Maybe String
2731 , repoBranch :: Maybe String
2732 , repoTag :: Maybe String
2733 , repoSubdir :: Maybe FilePath
2736 .. pkg-field:: type: VCS kind
2738 This field is required.
2740 .. pkg-field:: location: VCS location
2742 This field is required.
2744 .. pkg-field:: module: token
2746 CVS requires a named module, as each CVS server can host multiple
2749 This field is required for the CVS repository type and should not be
2752 .. pkg-field:: branch: VCS branch
2754 This field is optional.
2756 .. pkg-field:: tag: VCS tag
2758 This field is required for the ``this`` repository kind.
2760 This might be used to indicate what sources to get if someone needs to fix a
2761 bug in an older branch that is no longer an active head branch.
2763 .. pkg-field:: subdir: VCS subdirectory
2765 This field is optional but, if given, specifies a single subdirectory.
2772 The ``Hooks`` build type allows customising the configuration and the building
2773 of a package using a collection of **hooks** into the build system.
2775 Introduced in Cabal 3.14, this build type provides an alternative
2776 to :ref:`Custom setups <custom-setup>` which integrates better with the rest of the
2779 To use this build type in your package, you need to:
2781 * Declare a ``cabal-version`` of at least 3.14 in your ``.cabal`` file.
2782 * Declare ``build-type: Hooks`` in your ``.cabal`` file.
2783 * Include a ``custom-setup`` stanza in your ``.cabal`` file, which declares
2784 the version of the Hooks API your package is using.
2785 * Define a ``SetupHooks.hs`` module next to your ``.cabal`` file. It must
2786 export a value ``setupHooks :: SetupHooks``.
2788 More specifically, your ``.cabal`` file should resemble the following:
2790 .. code-block:: cabal
2797 base >= 4.18 && < 5,
2798 Cabal-hooks >= 0.1 && < 0.2
2800 while a basic ``SetupHooks.hs`` file might look like the following:
2802 .. code-block:: haskell
2804 module SetupHooks where
2805 import Distribution.Simple.SetupHooks ( SetupHooks, noSetupHooks )
2807 setupHooks :: SetupHooks
2810 { configureHooks = myConfigureHooks
2811 , buildHooks = myBuildHooks }
2815 Refer to the `Hackage documentation for the Distribution.Simple.SetupHooks module <https://hackage.haskell.org/package/Cabal-hooks/docs/Distribution-Simple-SetupHooks.html>`__
2816 for an overview of the ``Hooks`` API. Further motivation and a technical overview
2817 of the design is available in `Haskell Tech Proposal #60 <https://github.com/haskellfoundation/tech-proposals/blob/main/rfc/060-replacing-cabal-custom-build.md>`__ .
2821 Custom setup scripts
2822 --------------------
2824 Deprecated since Cabal 3.14: prefer using the :ref:`Hooks build type<setup-hooks>` instead.
2826 Since Cabal 1.24, custom ``Setup.hs`` are required to accurately track
2827 their dependencies by declaring them in the ``.cabal`` file rather than
2828 rely on dependencies being implicitly in scope. Please refer to
2829 `this article <https://www.well-typed.com/blog/2015/07/cabal-setup-deps/>`__
2832 As of Cabal library version 3.0, ``defaultMain*`` variants implement support
2833 for response files. Custom ``Setup.hs`` files that do not use one of these
2834 main functions are required to implement their own support, such as by using
2835 ``GHC.ResponseFile.getArgsWithResponseFiles``.
2837 Declaring a ``custom-setup`` stanza also enables the generation of
2838 ``MIN_VERSION_package_(A,B,C)`` CPP macros for the Setup component.
2840 .. pkg-section:: custom-setup
2841 :synopsis: Build information for ``Custom`` and ``Hooks`` build types
2844 A :pkg-section:`custom-setup` stanza is required for ``Custom`` and ``Hooks``
2845 :pkg-field:`build-type`, and will be ignored (with a warning)
2846 for other build types.
2848 The stanza contains information needed for the compilation
2849 of custom ``Setup.hs`` scripts, and of ``SetupHooks.hs`` hooks.
2856 base >= 4.18 && < 5,
2859 .. pkg-field:: setup-depends: package list
2862 The dependencies needed to compile ``Setup.hs`` or ``SetupHooks.hs``. See the
2863 :pkg-field:`build-depends` field for a description of the syntax expected by
2866 If the field is not specified the implicit package set will be used.
2867 The package set contains packages bundled with GHC (i.e. ``base``,
2868 ``bytestring``) and specifically ``Cabal``.
2869 The specific bounds are put on ``Cabal`` dependency:
2870 lower-bound is inferred from :pkg-field:`cabal-version`,
2871 and the upper-bound is ``< 1.25``.
2873 ``Cabal`` version is additionally restricted by GHC,
2874 with absolute minimum being ``1.20``, and for example ``Custom``
2875 builds with GHC-8.10 require at least ``Cabal-3.2``.
2878 Backward compatibility and ``custom-setup``
2879 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2881 Versions prior to Cabal 1.24 don't recognise ``custom-setup`` stanzas,
2882 and will behave agnostic to them (except for warning about an unknown
2883 'section'). Consequently, versions prior to Cabal 1.24 can't ensure the
2884 declared dependencies ``setup-depends`` are in scope, and instead
2885 whatever is registered in the current package database environment
2886 will become eligible (and resolved by the compiler) for the
2887 ``Setup.hs`` module.
2889 The availability of the
2890 ``MIN_VERSION_package_(A,B,C)`` CPP macros
2891 inside ``Setup.hs`` scripts depends on the condition that either
2893 - a ``custom-setup`` stanza has been declared (or ``cabal build`` is being used
2894 which injects an implicit hard-coded ``custom-setup`` stanza if it's missing),
2896 - GHC 8.0 or later is used (which natively injects package version CPP macros)
2898 Consequently, if you need to write backward compatible ``Setup.hs``
2899 scripts using CPP, you should declare a ``custom-setup`` stanza and
2900 use the pattern below:
2902 .. code-block:: haskell
2904 {-# LANGUAGE CPP #-}
2905 import Distribution.Simple
2907 #if defined(MIN_VERSION_Cabal)
2908 -- version macros are available and can be used as usual
2909 # if MIN_VERSION_Cabal(a,b,c)
2910 -- code specific to lib:Cabal >= a.b.c
2912 -- code specific to lib:Cabal < a.b.c
2915 # warning Enabling heuristic fall-back. Please upgrade cabal-install to 1.24 or later if Setup.hs fails to compile.
2917 -- package version macros not available; except for exotic environments,
2918 -- you can heuristically assume that lib:Cabal's version is correlated
2919 -- with __GLASGOW_HASKELL__, and specifically since we can assume that
2920 -- GHC < 8.0, we can assume that lib:Cabal is version 1.22 or older.
2925 The simplified (heuristic) CPP pattern shown below is useful if all you need
2926 is to distinguish ``Cabal < 2.0`` from ``Cabal >= 2.0``.
2928 .. code-block:: haskell
2930 {-# LANGUAGE CPP #-}
2931 import Distribution.Simple
2933 #if !defined(MIN_VERSION_Cabal)
2934 # define MIN_VERSION_Cabal(a,b,c) 0
2937 #if MIN_VERSION_Cabal(2,0,0)
2938 -- code for lib:Cabal >= 2.0
2940 -- code for lib:Cabal < 2.0
2947 Autogenerated modules and includes
2948 ----------------------------------
2950 .. pkg-section:: None
2952 Modules that are built automatically at setup, created with a custom
2953 setup script, must appear on :pkg-field:`other-modules` for the library,
2954 executable, test-suite or benchmark stanzas or also on
2955 :pkg-field:`library:exposed-modules` for libraries to be used, but are not
2956 really on the package when distributed. This makes commands like sdist fail
2957 because the file is not found.
2959 These special modules must appear again on the :pkg-field:`autogen-modules`
2960 field of the stanza that is using them, besides :pkg-field:`other-modules` or
2961 :pkg-field:`library:exposed-modules`. With this there is no need to create
2962 complex build hooks for this poweruser case.
2964 .. pkg-field:: autogen-modules: module list
2967 .. todo:: document autogen-modules field
2969 Right now :pkg-field:`executable:main-is` modules are not supported on
2970 :pkg-field:`autogen-modules`.
2975 default-language: Haskell2010
2986 default-language: Haskell2010
2995 .. pkg-field:: autogen-includes: filename list
2998 A list of header files from this package which are autogenerated
2999 (e.g. by a ``configure`` script). Autogenerated header files are not
3000 packaged by ``sdist`` command.
3003 .. _accessing-data-files:
3005 Accessing data files from package code
3006 --------------------------------------
3008 The placement on the target system of files listed in
3009 the :pkg-field:`data-files` field varies between systems, and in some cases
3010 one can even move packages around after installation
3011 (see :ref:`prefix independence`). To
3012 enable packages to find these files in a portable way, Cabal generates a
3013 module called :file:`Paths_{pkgname}` (with any hyphens in *pkgname*
3014 replaced by underscores) during building, so that it may be imported by
3015 modules of the package. This module defines a function
3017 .. code-block:: haskell
3019 getDataFileName :: FilePath -> IO FilePath
3021 If the argument is a filename listed in the :pkg-field:`data-files` field, the
3022 result is the name of the corresponding file on the system on which the
3027 If you decide to import the :file:`Paths_{pkgname}` module then it
3028 *must* be listed in the :pkg-field:`other-modules` field just like any other
3029 module in your package and on :pkg-field:`autogen-modules` as the file is
3032 The :file:`Paths_{pkgname}` module is not platform independent, as any
3033 other autogenerated module, so it does not get included in the source
3034 tarballs generated by ``sdist``.
3036 The :file:`Paths_{pkgname}` module also includes some other useful
3037 functions and values, which record the version of the package and some
3038 other directories which the package has been configured to be installed
3039 into (e.g. data files live in ``getDataDir``):
3041 .. code-block:: haskell
3045 getBinDir :: IO FilePath
3046 getLibDir :: IO FilePath
3047 getDynLibDir :: IO FilePath
3048 getDataDir :: IO FilePath
3049 getLibexecDir :: IO FilePath
3050 getSysconfDir :: IO FilePath
3052 The actual location of all these directories can be individually
3053 overridden at runtime using environment variables of the form
3054 ``pkg_name_var``, where ``pkg_name`` is the name of the package with all
3055 hyphens converted into underscores, and ``var`` is either ``bindir``,
3056 ``libdir``, ``dynlibdir``, ``datadir``, ``libexedir`` or ``sysconfdir``. For example,
3057 the configured data directory for ``pretty-show`` is controlled with the
3058 ``pretty_show_datadir`` environment variable.
3060 Accessing the package version
3061 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3063 The auto generated :file:`PackageInfo_{pkgname}` module exports the constant
3064 ``version ::`` `Version <http://hackage.haskell.org/package/base/docs/Data-Version.html>`__
3065 which is defined as the version of your package as specified in the
3068 Accessing package-related informations
3069 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3071 The auto generated :file:`PackageInfo_{pkgname}` module exports the following
3072 package-related constants:
3074 .. code-block:: haskell
3082 Unlike :file:`Paths_{pkgname}` (see <#accessing-data-files-from-package-code>),
3083 :file:`PackageInfo_{pkgname}` is system- and path-independent. It aims to be
3084 easier to work with for hash-based tools such as Nix.
3086 .. _system-dependent parameters:
3088 System-dependent parameters
3089 ---------------------------
3091 For some packages, especially those interfacing with C libraries,
3092 implementation details and the build procedure depend on the build
3093 environment. The ``build-type`` ``Configure`` can be used to handle many
3094 such situations. In this case, ``Setup.hs`` should be:
3096 .. code-block:: haskell
3098 import Distribution.Simple
3099 main = defaultMainWithHooks autoconfUserHooks
3101 Most packages, however, would probably do better using the ``Simple``
3102 build type and `configurations`_.
3104 The :pkg-field:`build-type` ``Configure`` differs from ``Simple`` in two ways:
3106 - The package root directory must contain a shell script called
3107 ``configure``. The configure step will run the script. This
3108 ``configure`` script may be produced by
3109 `autoconf <http://www.gnu.org/software/autoconf/>`__ or may be
3110 hand-written. The ``configure`` script typically discovers
3111 information about the system and records it for later steps, e.g. by
3112 generating system-dependent header files for inclusion in C source
3113 files and preprocessed Haskell source files. (Clearly this won't work
3114 for Windows without MSYS or Cygwin: other ideas are needed.)
3116 - If the package root directory contains a file called
3117 *package*\ ``.buildinfo`` after the configuration step, subsequent
3118 steps will read it to obtain additional settings for `build
3119 information`_ fields,to be merged with the ones
3120 given in the ``.cabal`` file. In particular, this file may be
3121 generated by the ``configure`` script mentioned above, allowing these
3122 settings to vary depending on the build environment.
3124 Note that the package's ``extra-source-files`` are available to the
3125 ``configure`` script when it is executed. In typical ``autoconf`` fashion,
3126 ``--host`` flag will be passed to the ``configure`` script to indicate the host
3127 platform when cross-compiling. Moreover, various bits of build configuration
3128 will be passed via environment variables:
3130 - ``CC`` will reflect the path to the C compiler
3131 - ``CFLAGS`` will reflect the path to the C compiler
3132 - ``CABAL_FLAGS`` will contain the Cabal flag assignment of the current
3133 package using traditional Cabal flag syntax (e.g. ``+flagA -flagB``)
3134 - ``CABAL_FLAG_<flag>`` will be set to either ``0`` or ``1`` depending upon
3135 whether flag ``<flag>`` is enabled. Note that any any non-alpha-numeric
3136 characters in the flag name are replaced with ``_``.
3138 The build information file should have the following structure:
3142 ``executable:`` *name* *buildinfo*
3144 ``executable:`` *name* *buildinfo* ...
3146 where each *buildinfo* consists of settings of fields listed in the
3147 section on `build information`_. The first one (if
3148 present) relates to the library, while each of the others relate to the
3149 named executable. (The names must match the package description, but you
3150 don't have to have entries for all of them.)
3152 Neither of these files is required. If they are absent, this setup
3153 script is equivalent to ``defaultMain``.
3155 Example: Using autoconf
3156 ^^^^^^^^^^^^^^^^^^^^^^^
3158 This example is for people familiar with the
3159 `autoconf <http://www.gnu.org/software/autoconf/>`__ tools.
3161 In the X11 package, the file ``configure.ac`` contains:
3163 .. code-block:: shell
3165 AC_INIT([Haskell X11 package], [1.1], [libraries@haskell.org], [X11])
3167 # Safety check: Ensure that we are in the correct source directory.
3168 AC_CONFIG_SRCDIR([X11.cabal])
3170 # Header file to place defines in
3171 AC_CONFIG_HEADERS([include/HsX11Config.h])
3173 # Check for X11 include paths and libraries
3175 AC_TRY_CPP([#include <X11/Xlib.h>],,[no_x=yes])
3177 # Build the package if we found X11 stuff
3178 if test "$no_x" = yes
3179 then BUILD_PACKAGE_BOOL=False
3180 else BUILD_PACKAGE_BOOL=True
3182 AC_SUBST([BUILD_PACKAGE_BOOL])
3184 AC_CONFIG_FILES([X11.buildinfo])
3187 Then the setup script will run the ``configure`` script, which checks
3188 for the presence of the X11 libraries and substitutes for variables in
3189 the file ``X11.buildinfo.in``:
3193 buildable: @BUILD_PACKAGE_BOOL@
3194 cc-options: @X_CFLAGS@
3195 ld-options: @X_LIBS@
3197 This generates a file ``X11.buildinfo`` supplying the parameters needed
3203 cc-options: -I/usr/X11R6/include
3204 ld-options: -L/usr/X11R6/lib
3206 The ``configure`` script also generates a header file
3207 ``include/HsX11Config.h`` containing C preprocessor defines recording
3208 the results of various tests. This file may be included by C source
3209 files and preprocessed Haskell source files in the package.
3213 Packages using these features will also need to list additional
3214 files such as ``configure``, templates for ``.buildinfo`` files, files
3215 named only in ``.buildinfo`` files, header files and so on in the
3216 :pkg-field:`extra-source-files` field to ensure that they are included in
3217 source distributions. They should also list files and directories generated
3218 by ``configure`` in the :pkg-field:`extra-tmp-files` field to ensure that
3219 they are removed by ``setup clean``.
3221 Quite often the files generated by ``configure`` need to be listed
3222 somewhere in the package description (for example, in the
3223 :pkg-field:`install-includes` field). However, we usually don't want generated
3224 files to be included in the source tarball. The solution is again
3225 provided by the ``.buildinfo`` file. In the above example, the following
3226 line should be added to ``X11.buildinfo``:
3230 install-includes: HsX11Config.h
3232 In this way, the generated ``HsX11Config.h`` file won't be included in
3233 the source tarball in addition to ``HsX11Config.h.in``, but it will be
3234 copied to the right location during the install process. Packages that
3235 use custom ``Setup.hs`` scripts can update the necessary fields
3236 programmatically instead of using the ``.buildinfo`` file.
3238 Conditional compilation
3239 -----------------------
3241 Sometimes you want to write code that works with more than one version
3242 of a dependency. You can specify a range of versions for the dependency
3243 in the :pkg-field:`build-depends`, but how do you then write the code that can
3244 use different versions of the API?
3246 Haskell lets you preprocess your code using the C preprocessor (either
3247 the real C preprocessor, or ``cpphs``). To enable this, add
3248 ``extensions: CPP`` to your package description. When using CPP, Cabal
3249 provides some pre-defined macros to let you test the version of
3250 dependent packages; for example, suppose your package works with either
3251 version 3 or version 4 of the ``base`` package, you could select the
3252 available version in your Haskell modules like this:
3256 #if MIN_VERSION_base(4,0,0)
3257 ... code that works with base-4 ...
3259 ... code that works with base-3 ...
3262 In general, Cabal supplies a macro
3263 ``MIN_VERSION_``\ *``package``*\ ``_(A,B,C)`` for each package depended
3264 on via :pkg-field:`build-depends`. This macro is true if the actual version of
3265 the package in use is greater than or equal to ``A.B.C`` (using the
3266 conventional ordering on version numbers, which is lexicographic on the
3267 sequence, but numeric on each component, so for example 1.2.0 is greater
3270 Since version 1.20, the ``MIN_TOOL_VERSION_``\ *``tool``*
3271 family of macros lets you condition on the version of build tools used to
3272 build the program (e.g. ``hsc2hs``).
3274 Since version 1.24, the macro ``CURRENT_COMPONENT_ID``, which
3275 expands to the string of the component identifier that uniquely
3276 identifies this component. Furthermore, if the package is a library,
3277 the macro ``CURRENT_PACKAGE_KEY`` records the identifier that was passed
3278 to GHC for use in symbols and for type equality.
3280 Since version 2.0, the macro ``CURRENT_PACKAGE_VERSION`` expands
3281 to the string version number of the current package.
3283 Cabal places the definitions of these macros into an
3284 automatically-generated header file, which is included when
3285 preprocessing Haskell source code by passing options to the C
3288 Cabal also allows to detect when the source code is being used for
3289 generating documentation. The ``__HADDOCK_VERSION__`` macro is defined
3290 only when compiling via Haddock_
3291 instead of a normal Haskell compiler. The value of the
3292 ``__HADDOCK_VERSION__`` macro is defined as ``A*1000 + B*10 + C``, where
3293 ``A.B.C`` is the Haddock version. This can be useful for working around
3294 bugs in Haddock or generating prettier documentation in some special
3297 .. _more-complex-packages:
3299 More complex packages
3300 ---------------------
3302 For packages that don't fit the simple schemes described above, you have
3305 - By using the :pkg-field:`build-type` ``Custom``, you can supply your own
3306 ``Setup.hs`` file, and customize the simple build infrastructure
3307 using *hooks*. These allow you to perform additional actions before
3308 and after each command is run, and also to specify additional
3309 preprocessors. A typical ``Setup.hs`` may look like this:
3311 .. code-block:: haskell
3313 import Distribution.Simple
3314 main = defaultMainWithHooks simpleUserHooks { postHaddock = posthaddock }
3316 posthaddock args flags desc info = ....
3318 See ``UserHooks`` in
3319 `Distribution.Simple <https://hackage.haskell.org/package/Cabal/docs/Distribution-Simple.html>`__
3320 for the details, but note that this interface is experimental, and
3321 likely to change in future releases.
3323 If you use a custom ``Setup.hs`` file you should strongly consider
3324 adding a :pkg-section:`custom-setup` stanza with a
3325 :pkg-field:`custom-setup:setup-depends` field to ensure that your setup
3326 script does not break with future dependency versions.
3328 - You could delegate all the work to ``make``, though this is unlikely
3329 to be very portable. Cabal supports this with the :pkg-field:`build-type`
3330 ``Make`` and a trivial setup library
3331 `Distribution.Make <https://hackage.haskell.org/package/Cabal/docs/Distribution-Make.html>`__,
3332 which simply parses the command line arguments and invokes ``make``.
3333 Here ``Setup.hs`` should look like this:
3335 .. code-block:: haskell
3337 import Distribution.Make
3340 The root directory of the package should contain a ``configure``
3341 script, and, after that has run, a ``Makefile`` with a default target
3342 that builds the package, plus targets ``install``, ``register``,
3343 ``unregister``, ``clean``, ``dist`` and ``docs``. Some options to
3344 commands are passed through as follows:
3346 - The ``--with-hc-pkg``, ``--prefix``, ``--bindir``, ``--libdir``,
3347 ``--dynlibdir``, ``--datadir``, ``--libexecdir`` and ``--sysconfdir`` options to
3348 the ``configure`` command are passed on to the ``configure``
3349 script. In addition the value of the ``--with-compiler`` option is
3350 passed in a ``--with-hc`` option and all options specified with
3351 ``--configure-option=`` are passed on.
3353 - The ``--destdir`` option to the ``copy`` command becomes a setting
3354 of a ``destdir`` variable on the invocation of ``make copy``. The
3355 supplied ``Makefile`` should provide a ``copy`` target, which will
3356 probably look like this:
3358 .. code-block:: make
3361 $(MAKE) install prefix=$(destdir)/$(prefix) \
3362 bindir=$(destdir)/$(bindir) \
3363 libdir=$(destdir)/$(libdir) \
3364 dynlibdir=$(destdir)/$(dynlibdir) \
3365 datadir=$(destdir)/$(datadir) \
3366 libexecdir=$(destdir)/$(libexecdir) \
3367 sysconfdir=$(destdir)/$(sysconfdir) \
3369 - Finally, with the :pkg-field:`build-type` ``Custom``, you can also write your
3370 own setup script from scratch, and you may use the Cabal
3371 library for all or part of the work. One option is to copy the source
3372 of ``Distribution.Simple``, and alter it for your needs. Good luck.
3374 .. include:: references.inc
3376 .. rubric:: Footnotes
3378 .. [#old-style-build-tool-depends]
3380 Some packages (ab)use :pkg-field:`build-depends` on old-style builds, but this has a few major drawbacks:
3382 - using Nix-style builds it's considered an error if you depend on a exe-only package via build-depends: the solver will refuse it.
3383 - it may or may not place the executable on ``PATH``.
3384 - it does not ensure the correct version of the package is installed, so you might end up overwriting versions with each other.