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.0.1, GHC == 8.10.4, GHC == 8.8.4,
650 GHC == 8.6.5, GHC == 8.4.4, GHC == 8.2.2, GHC == 8.0.2,
651 GHC == 7.10.3, GHC == 7.8.4, GHC == 7.6.3, GHC == 7.4.2
653 The same can be spread over several lines, for instance:
657 tested-with: GHC == 9.0.1
669 The separating comma can also be dropped altogether:
686 However, this alternative might
687 `disappear <https://github.com/haskell/cabal/issues/4894#issuecomment-909008657>`__
690 Starting with :pkg-field:`cabal-version` 3.0,
691 there are further conveniences.
693 1. A preceding ``,`` is allowed, so a bullet-list style
694 is possible (recommended):
712 2. A concise set notation syntax is available:
716 tested-with: GHC == { 9.0.1, 8.10.4, 8.8.4, 8.6.5, 8.4.4, 8.2.2, 8.0.2, 7.10.3, 7.8.4, 7.6.3, 7.4.2 }
718 .. pkg-field:: data-files: filename list
720 A list of files to be installed for run-time use by the package.
721 This is useful for packages that use a large amount of static data,
722 such as tables of values or code templates. Cabal provides a way to
723 `find these files at run-time <#accessing-data-files-from-package-code>`_.
725 A limited form of ``*`` wildcards in file names, for example
726 ``data-files: images/*.png`` matches all the ``.png`` files in the
727 ``images`` directory. ``data-files: audio/**/*.mp3`` matches all
728 the ``.mp3`` files in the ``audio`` directory, including
731 The specific limitations of this wildcard syntax are
733 - ``*`` wildcards are only allowed in place of the file name, not
734 in the directory name or file extension. It must replace the
735 whole file name (e.g., ``*.html`` is allowed, but
736 ``chapter-*.html`` is not). If a wildcard is used, it must be
737 used with an extension, so ``data-files: data/*`` is not
740 - Prior to Cabal 2.4, when matching a wildcard plus extension, a
741 file's full extension must match exactly, so ``*.gz`` matches
742 ``foo.gz`` but not ``foo.tar.gz``. This restriction has been
743 lifted when ``cabal-version: 2.4`` or greater so that ``*.gz``
744 does match ``foo.tar.gz``
746 - ``*`` wildcards will not match if the file name is empty (e.g.,
747 ``*.html`` will not match ``foo/.html``).
749 - ``**`` wildcards can only appear as the final path component
750 before the file name (e.g., ``data/**/images/*.jpg`` is not
753 - Prior to Cabal 3.8, if a ``**`` wildcard is used, then
754 the file name must include a ``*`` wildcard (e.g.,
755 ``data/**/README.rst`` was not allowed). As of ``cabal-version:
756 3.8`` or greater, this restriction is lifted.
758 - A wildcard that does not match any files is an error.
760 The reason for providing only a very limited form of wildcard is to
761 concisely express the common case of a large number of related files
762 of the same file type without making it too easy to accidentally
763 include unwanted files.
765 On efficiency: if you use ``**`` patterns, the directory tree will
766 be walked starting with the parent directory of the ``**``. If
767 that's the root of the project, this might include ``.git/``,
768 ``dist-newstyle/``, or other large directories! To avoid this
769 behaviour, put the files that wildcards will match against in
772 ``**`` wildcards are available starting in Cabal 2.4
773 and `bug-free since Cabal 3.0 <https://github.com/haskell/cabal/issues/6125#issuecomment-1379878419>`_.
775 .. pkg-field:: data-dir: directory
777 The directory where Cabal looks for data files to install, relative
778 to the source directory. By default, Cabal will look in the source
781 .. pkg-field:: extra-source-files: filename list
783 A list of additional files to be included in source distributions built with :ref:`setup-sdist`.
784 As with :pkg-field:`data-files` it can use a limited form of ``*`` wildcards in file names.
785 Files listed here are tracked by ``cabal build``; changes in these files cause (partial) rebuilds.
787 .. pkg-field:: extra-doc-files: filename list
790 A list of additional files to be included in source distributions,
791 and also copied to the html directory when Haddock documentation is
792 generated. As with :pkg-field:`data-files` it can use a limited form of
793 ``*`` wildcards in file names.
795 .. pkg-field:: extra-tmp-files: filename list
797 A list of additional files or directories to be removed by
798 :ref:`setup-clean`. These would typically be additional files created by
799 additional hooks, such as the scheme described in the section on
800 `system-dependent parameters`_.
805 .. pkg-section:: library name
806 :synopsis: Library build information.
808 Build information for libraries.
810 A package can include zero or more library components. A library can be
811 unnamed or named (using the ``name`` argument). It can also be depended upon
812 only by components in the same package (private) or by those components and
813 components in other packages (public). A package can have no more than one
818 The 'cabal' executable provided by the 'cabal-install' package will not
819 accept dependencies on sublibraries of packages with no unnamed library.
821 This guide refers to an unnamed library as the main library and a named
822 library as a sublibrary (such components may be considered as subidiary, or
823 ancillary, to the main library). It refers to a private sublibrary as an
826 A sublibrary cannot have the same name as its package.
830 Before version 3.4 of the Cabal specification, a private sublibrary could
831 shadow a dependency on the main library of another package, if their
834 A main library is always public and a sublibrary is private by default.
835 See the :pkg-field:`library:visibility` field for setting a sublibrary as
838 Being able to include more than one public library in a package allows the
839 separation of the unit of distribution (the package) from the unit of
840 buildable code (the library). This is useful for Haskell projects with many
841 libraries that are distributed together as it avoids duplication and
842 potential inconsistencies.
846 Before version 3.0 of the Cabal specification, all sublibraries were
847 internal libraries. Before version 2.0, a package could not include
850 See :ref:`Sublibraries - Examples <sublibs>` for examples.
852 A library section should contain the following fields:
854 .. pkg-field:: visibility: visibility specifiers
859 ``private`` for sublibraries. Cannot be set for the main library, which
862 Can be set to ``private`` or ``public``. A ``private`` library component can
863 only be depended on by other components of the same package. A ``public``
864 component can be depended on by those components and by components of other
867 See the :pkg-field:`build-depends` field for the syntax to specify a
868 dependency on a library component.
870 .. pkg-field:: exposed-modules: identifier list
872 :required: if this package contains a library
874 A list of modules added by this package.
876 .. pkg-field:: virtual-modules: identifier list
879 A list of virtual modules provided by this package. Virtual modules
880 are modules without a source file. See for example the ``GHC.Prim``
881 module from the ``ghc-prim`` package. Modules listed here will not be
882 built, but still end up in the list of ``exposed-modules`` in the
883 installed package info when the package is registered in the package
886 .. pkg-field:: exposed: boolean
890 Some Haskell compilers (notably GHC) support the notion of packages
891 being "exposed" or "hidden" which means the modules they provide can
892 be easily imported without always having to specify which package
893 they come from. However this only works effectively if the modules
894 provided by all exposed packages do not overlap (otherwise a module
895 import would be ambiguous).
897 Almost all new libraries use hierarchical module names that do not
898 clash, so it is very uncommon to have to use this field. However it
899 may be necessary to set ``exposed: False`` for some old libraries
900 that use a flat module namespace or where it is known that the
901 exposed modules would clash with other common modules.
903 .. pkg-field:: reexported-modules: exportlist
906 Supported only in GHC 7.10 and later. A list of modules to
907 *reexport* from this package. The syntax of this field is
908 ``orig-pkg:Name as NewName`` to reexport module ``Name`` from
909 ``orig-pkg`` with the new name ``NewName``. We also support
910 abbreviated versions of the syntax: if you omit ``as NewName``,
911 we'll reexport without renaming; if you omit ``orig-pkg``, then we
912 will automatically figure out which package to reexport from, if
915 Reexported modules are useful for compatibility shims when a package
916 has been split into multiple packages, and they have the useful
917 property that if a package provides a module, and another package
918 reexports it under the same name, these are not considered a
919 conflict (as would be the case with a stub module.) They can also be
920 used to resolve name conflicts.
922 .. pkg-field:: signatures: signature list
925 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.
927 Module signatures are part of the :ref:`Backpack` extension to
928 the Haskell module system.
930 Packages that do not export any modules and only export required signatures
931 are called "signature-only packages", and their signatures are subjected to
933 <https://wiki.haskell.org/Module_signature#How_to_use_a_signature_package>`__.
937 The library section may also contain build information fields (see the
938 section on `build information`_).
942 **Sublibraries - Examples**
944 An example of the use of a private sublibrary (an internal library) is a test
945 suite that needs access to some internal modules in the package's main library,
946 which you do not otherwise want to expose. You could put those modules in an
947 internal library, which the main library and the test suite
948 :pkg-field:`build-depends` upon. Your Cabal file might then look something like
956 license: BSD-3-Clause
957 license-file: LICENSE
961 exposed-modules: Foo.Internal
962 -- NOTE: no explicit constraints on base needed
963 -- as they're inherited from the 'library' stanza
965 default-language: Haskell2010
968 exposed-modules: Foo.Public
969 build-depends: foo:foo-internal, base >= 4.3 && < 5
970 default-language: Haskell2010
973 type: exitcode-stdio-1.0
975 -- NOTE: no constraints on 'foo-internal' as same-package
976 -- dependencies implicitly refer to the same package instance
977 build-depends: foo:foo-internal, base
978 default-language: Haskell2010
980 Another example of the use of internal libraries is a package that includes one
981 or more executables but does not include a public library.
983 Internal libraries can be used to incorporate (vendor or bundle) an external
984 dependency into a package, effectively simulating *private dependencies*. Below
990 name: haddock-library
992 license: BSD-3-Clause
997 , bytestring ^>= 0.10.2.0
998 , containers ^>= 0.4.2.1 || ^>= 0.5.0.0
999 , transformers ^>= 0.5.0.0
1004 build-depends: haddock-library:attoparsec
1007 Documentation.Haddock
1009 default-language: Haskell2010
1014 , bytestring ^>= 0.10.2.0
1015 , deepseq ^>= 1.4.0.0
1017 hs-source-dirs: vendor/attoparsec-0.13.1.0
1019 -- NB: haddock-library needs only small part of lib:attoparsec
1020 -- internally, so we only bundle that subset here
1022 Data.Attoparsec.ByteString
1023 Data.Attoparsec.Combinator
1026 Data.Attoparsec.Internal
1028 ghc-options: -funbox-strict-fields -Wall -fwarn-tabs -O2
1030 default-language: Haskell2010
1035 A package description can contain multiple executable sections.
1036 The documentation of the `cabal run <cabal-commands.html#cabal-run>`__ command
1037 contains detailed information on how to run an executable.
1039 .. pkg-section:: executable name
1040 :synopsis: Executable build info section.
1042 Executable sections (if present) describe executable programs contained
1043 in the package and must have an argument after the section label, which
1044 defines the name of the executable. This is a freeform argument but may
1047 The executable may be described using the following fields, as well as
1048 build information fields (see the section on `build information`_).
1050 .. pkg-field:: main-is: filename (required)
1052 The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
1053 module. Note that it is the ``.hs`` filename that must be listed,
1054 even if that file is generated using a preprocessor. The source file
1055 must be relative to one of the directories listed in
1056 :pkg-field:`hs-source-dirs`. Further, while the name of the file may
1057 vary, the module itself must be named ``Main``.
1059 Starting with ``cabal-version: 1.18`` this field supports
1060 specifying a C, C++, or objC source file as the main entry point.
1062 .. pkg-field:: scope: token
1065 Whether the executable is ``public`` (default) or ``private``, i.e. meant to
1066 be run by other programs rather than the user. Private executables are
1067 installed into `$libexecdir/$libexecsubdir`.
1073 A package description can contain multiple test suite sections.
1074 The documentation of the `cabal test <cabal-commands.html#cabal-test>`__ command
1075 contains detailed information on how to run test suites.
1077 .. pkg-section:: test-suite name
1078 :synopsis: Test suite build information.
1080 Test suite sections (if present) describe package test suites and must
1081 have an argument after the section label, which defines the name of the
1082 test suite. This is a freeform argument, but may not contain spaces. It
1083 should be unique among the names of the package's other test suites, the
1084 package's executables, and the package itself. Using test suite sections
1085 requires at least Cabal version 1.9.2.
1087 The test suite may be described using the following fields, as well as
1088 build information fields (see the section on `build information`_).
1090 .. pkg-field:: type: interface (required until ``cabal-version`` 3.8)
1092 The interface type and version of the test suite. Cabal supports two
1093 test suite interfaces, called ``exitcode-stdio-1.0`` (default since ``cabal-version`` 3.8) and
1094 ``detailed-0.9``. Each of these types may require or disallow other
1095 fields as described below.
1097 Test suites using the ``exitcode-stdio-1.0`` (default since ``cabal-version`` 3.8) interface are executables
1098 that indicate test failure with a non-zero exit code when run; they may
1099 provide human-readable log information through the standard output and
1100 error channels. The ``exitcode-stdio-1.0`` type requires the ``main-is``
1103 .. pkg-field:: main-is: filename
1104 :synopsis: Module containing tests main function.
1106 :required: ``exitcode-stdio-1.0``
1107 :disallowed: ``detailed-0.9``
1109 The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
1110 module. Note that it is the ``.hs`` filename that must be listed,
1111 even if that file is generated using a preprocessor. The source file
1112 must be relative to one of the directories listed in
1113 :pkg-field:`hs-source-dirs`. This field is analogous to the ``main-is`` field
1114 of an executable section.
1116 Test suites using the ``detailed-0.9`` interface are modules exporting
1117 the symbol ``tests :: IO [Test]``. The ``Test`` type is exported by the
1118 module ``Distribution.TestSuite`` provided by Cabal. For more details,
1119 see the example below.
1121 The ``detailed-0.9`` interface allows Cabal and other test agents to
1122 inspect a test suite's results case by case, producing detailed human-
1123 and machine-readable log files. The ``detailed-0.9`` interface requires
1124 the :pkg-field:`test-module` field.
1126 .. pkg-field:: test-module: identifier
1128 :required: ``detailed-0.9``
1129 :disallowed: ``exitcode-stdio-1.0``
1131 The module exporting the ``tests`` symbol.
1133 .. pkg-field:: code-generators
1135 An optional list of preprocessors which can generate new modules
1136 for use in the test-suite.
1138 A list of executabes (possibly brought into scope by
1139 :pkg-field:`build-tool-depends`) that are run after all other
1140 preprocessors. These executables are invoked as so: ``exe-name
1141 TARGETDIR [SOURCEDIRS] -- [GHCOPTIONS]``. The arguments are, in order a target dir for
1142 output, a sequence of all source directories with source files of
1143 local lib components that the given test stanza depends on, and
1144 following a double dash, all options cabal would pass to ghc for a
1145 build. They are expected to output a newline-seperated list of
1146 generated modules which have been written to the targetdir
1147 (excepting, if written, the main module). This can
1148 be used for driving doctests and other discover-style tests generated
1152 Example: Package using ``exitcode-stdio-1.0`` interface
1153 """""""""""""""""""""""""""""""""""""""""""""""""""""""
1155 The example package description and executable source file below
1156 demonstrate the use of the ``exitcode-stdio-1.0`` interface.
1158 .. code-block:: cabal
1164 License: BSD-3-Clause
1168 type: exitcode-stdio-1.0
1169 main-is: test-foo.hs
1170 build-depends: base >= 4 && < 5
1171 default-language: Haskell2010
1173 .. code-block:: haskell
1174 :caption: test-foo.hs
1178 import System.Exit (exitFailure)
1181 putStrLn "This test always fails!"
1184 Example: Package using ``detailed-0.9`` interface
1185 """""""""""""""""""""""""""""""""""""""""""""""""
1187 The example package description and test module source file below
1188 demonstrate the use of the ``detailed-0.9`` interface. The test module
1189 also develops a simple implementation of the interface set by
1190 ``Distribution.TestSuite``, but in actual usage the implementation would
1191 be provided by the library that provides the testing facility.
1193 .. code-block:: cabal
1199 License: BSD-3-Clause
1205 build-depends: base >= 4 && < 5, Cabal >= 1.9.2 && < 2
1206 default-language: Haskell2010
1209 .. code-block:: haskell
1212 module Bar ( tests ) where
1214 import Distribution.TestSuite
1217 tests = return [ Test succeeds, Test fails ]
1219 succeeds = TestInstance
1220 { run = return $ Finished Pass
1224 , setOption = \_ _ -> Right succeeds
1226 fails = TestInstance
1227 { run = return $ Finished $ Fail "Always fails!"
1231 , setOption = \_ _ -> Right fails
1237 A package description can contain multiple benchmark sections.
1238 The documentation of the `cabal bench <cabal-commands.html#cabal-bench>`__ command
1239 contains detailed information on how to run benchmarks.
1241 .. pkg-section:: benchmark name
1243 :synopsis: Benchmark build information.
1245 Benchmark sections (if present) describe benchmarks contained in the
1246 package and must have an argument after the section label, which defines
1247 the name of the benchmark. This is a freeform argument, but may not
1248 contain spaces. It should be unique among the names of the package's
1249 other benchmarks, the package's test suites, the package's executables,
1250 and the package itself. Using benchmark sections requires at least Cabal
1253 The benchmark may be described using the following fields, as well as
1254 build information fields (see the section on `build information`_).
1256 .. pkg-field:: type: interface (required until ``cabal-version`` 3.8)
1258 The interface type and version of the benchmark. At the moment Cabal
1259 only support one benchmark interface, called ``exitcode-stdio-1.0``.
1261 Benchmarks using the ``exitcode-stdio-1.0`` (default since ``cabal-version`` 3.8) interface are executables
1262 that indicate failure to run the benchmark with a non-zero exit code
1263 when run; they may provide human-readable information through the
1264 standard output and error channels.
1266 .. pkg-field:: main-is: filename
1268 The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
1269 module. Note that it is the ``.hs`` filename that must be listed,
1270 even if that file is generated using a preprocessor. The source file
1271 must be relative to one of the directories listed in
1272 :pkg-field:`hs-source-dirs`. This field is analogous to the ``main-is``
1273 field of an executable section. Further, while the name of the file may
1274 vary, the module itself must be named ``Main``.
1277 """""""""""""""""""""""""""""""""""""""""""""""""""""""
1279 .. code-block:: cabal
1281 :name: foo-bench.cabal
1286 License: BSD-3-Clause
1290 type: exitcode-stdio-1.0
1291 main-is: bench-foo.hs
1292 build-depends: base >= 4 && < 5, time >= 1.1 && < 1.7
1293 default-language: Haskell2010
1295 .. code-block:: haskell
1296 :caption: bench-foo.hs
1298 {-# LANGUAGE BangPatterns #-}
1301 import Data.Time.Clock
1305 fib n = fib (n-1) + fib (n-2)
1308 start <- getCurrentTime
1310 end <- getCurrentTime
1311 putStrLn $ "fib 20 took " ++ show (diffUTCTime end start)
1317 Foreign libraries are system libraries intended to be linked against
1318 programs written in C or other "foreign" languages. They
1319 come in two primary flavours: dynamic libraries (``.so`` files on Linux,
1320 ``.dylib`` files on OSX, ``.dll`` files on Windows, etc.) are linked against
1321 executables when the executable is run (or even lazily during
1322 execution), while static libraries (``.a`` files on Linux/OSX, ``.lib``
1323 files on Windows) get linked against the executable at compile time.
1325 Foreign libraries only work with GHC 7.8 and later.
1327 A typical stanza for a foreign library looks like
1331 foreign-library myforeignlib
1333 lib-version-info: 6:3:2
1337 mod-def-file: MyForeignLib.def
1339 other-modules: MyForeignLib.SomeModule
1340 MyForeignLib.SomeOtherModule
1341 build-depends: base >=4.7 && <4.9
1343 c-sources: csrc/MyForeignLibWrapper.c
1344 default-language: Haskell2010
1347 .. pkg-section:: foreign-library name
1349 :synopsis: Foreign library build information.
1351 Build information for `foreign libraries`_.
1353 .. pkg-field:: type: foreign library type
1355 Cabal recognizes ``native-static`` and ``native-shared`` here, although
1356 we currently only support building `native-shared` libraries.
1358 .. pkg-field:: options: foreign library option list
1360 Options for building the foreign library, typically specific to the
1361 specified type of foreign library. Currently we only support
1362 ``standalone`` here. A standalone dynamic library is one that does not
1363 have any dependencies on other (Haskell) shared libraries; without
1364 the ``standalone`` option the generated library would have dependencies
1365 on the Haskell runtime library (``libHSrts``), the base library
1366 (``libHSbase``), etc. Currently, ``standalone`` *must* be used on Windows
1367 and *must not* be used on any other platform.
1369 .. pkg-field:: mod-def-file: filename
1371 This option can only be used when creating dynamic Windows libraries
1372 (that is, when using ``native-shared`` and the ``os`` is ``Windows``). If
1373 used, it must be a path to a *module definition file*. The details of
1374 module definition files are beyond the scope of this document; see the
1375 `GHC <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/win32-dlls.html>`_
1376 manual for some details and some further pointers.
1378 .. pkg-field:: lib-version-info: current:revision:age
1380 This field is currently only used on Linux.
1382 This field specifies a Libtool-style version-info field that sets
1383 an appropriate ABI version for the foreign library. Note that the
1384 three numbers specified in this field do not directly specify the
1385 actual ABI version: ``6:3:2`` results in library version ``4.2.3``.
1387 With this field set, the SONAME of the library is set, and symlinks
1390 How you should bump this field on an ABI change depends on the
1391 breakage you introduce:
1393 - Programs using the previous version may use the new version as
1394 drop-in replacement, and programs using the new version can also
1395 work with the previous one. In other words, no recompiling nor
1396 relinking is needed. In this case, bump ``revision`` only, don't
1397 touch current nor age.
1398 - Programs using the previous version may use the new version as
1399 drop-in replacement, but programs using the new version may use
1400 APIs not present in the previous one. In other words, a program
1401 linking against the new version may fail with "unresolved
1402 symbols" if linking against the old version at runtime: set
1403 revision to 0, bump current and age.
1404 - Programs may need to be changed, recompiled, and relinked in
1405 order to use the new version. Bump current, set revision and age
1408 Also refer to the Libtool documentation on the version-info field.
1410 .. pkg-field:: lib-version-linux: version
1412 This field is only used on Linux.
1414 Specifies the library ABI version directly for foreign libraries
1415 built on Linux: so specifying ``4.2.3`` causes a library
1416 ``libfoo.so.4.2.3`` to be built with SONAME ``libfoo.so.4``, and
1417 appropriate symlinks ``libfoo.so.4`` and ``libfoo.so`` to be
1420 Note that typically foreign libraries should export a way to initialize
1421 and shutdown the Haskell runtime. In the example above, this is done by
1422 the ``csrc/MyForeignLibWrapper.c`` file, which might look something like
1429 HsBool myForeignLibInit(void){
1431 char *argv[] = { "+RTS", "-A32m", NULL };
1432 char **pargv = argv;
1434 // Initialize Haskell runtime
1435 hs_init(&argc, &pargv);
1437 // do any other initialization here and
1438 // return false if there was a problem
1439 return HS_BOOL_TRUE;
1442 void myForeignLibExit(void){
1446 With modern ghc regular libraries are installed in directories that contain
1447 package keys. This isn't usually a problem because the package gets registered
1448 in ghc's package DB and so we can figure out what the location of the library
1449 is. Foreign libraries however don't get registered, which means that we'd have
1450 to have a way of finding out where a platform library got installed (other than by
1451 searching the ``lib/`` directory). Instead, we install foreign libraries in
1456 .. pkg-section:: None
1458 The following fields may be optionally present in a library, executable,
1459 test suite or benchmark section, and give information for the building
1460 of the corresponding library or executable. See also the sections on
1461 `system-dependent parameters`_ and `configurations`_ for a way to supply
1462 system-dependent values for these fields.
1464 .. pkg-field:: build-depends: library list
1466 Declares the dependencies on *library* components required to build the
1467 current package component. See :pkg-field:`build-tool-depends` for declaring
1468 dependencies on build-time *tools*. Dependencies on libraries from another
1469 package should be annotated with a version constraint.
1473 A library is identified by the name of its package, optionally followed by a
1474 colon and the library's name (for example, ``my-package:my-library``). If a
1475 library name is omitted, the package's main library will be used. To refer
1476 expressly to a package's main library, use the name of the package as the
1477 library name (for example, ``my-package:my-package``). More than one library
1478 from the same package can be specified with the shorthand syntax
1479 ``my-package:{my-library1,my-library2}``.
1483 Before version 3.4 of the Cabal specification, from version 2.0, a
1484 private sublibrary (an internal library) was identified by only the name
1485 of the sublibrary. An internal library could shadow a dependency on the
1486 main library of another package, if the names clashed.
1488 See the section on :pkg-section:`library` for information about how a
1489 package can specify library components.
1491 **Version Constraints**
1493 Version constraints use the operators ``==, >=, >, <, <=`` and a
1494 version number. Multiple constraints can be combined using ``&&`` or
1499 Even though there is no ``/=`` operator, by combining operators we can
1500 skip over one or more versions, to skip a deprecated version or to skip
1501 versions that narrow the constraint solving more than we'd like.
1503 For example, the ``time =1.12.*`` series depends on ``base >=4.13 && <5``
1504 but ``time-1.12.3`` bumps the lower bound on base to ``>=4.14``. If we
1505 still want to compile with a ``ghc-8.8.*`` version of GHC that ships with
1506 ``base-4.13`` and with later GHC versions, then we can use ``time >=1.12
1507 && (time <1.12.3 || time >1.12.3)``.
1509 Hackage shows deprecated and preferred versions for packages, such as for
1510 `containers <https://hackage.haskell.org/package/containers/preferred>`_
1511 and `aeson <https://hackage.haskell.org/package/aeson/preferred>`_ for
1512 example. Deprecating package versions is not the same deprecating a
1513 package as a whole, for which Hackage keeps a `deprecated packages list
1514 <https://hackage.haskell.org/packages/deprecated>`_.
1516 If no version constraint is specified, any version is assumed to be
1517 acceptable. For example:
1524 foo >= 1.2.3 && < 1.3,
1527 Dependencies like ``foo >= 1.2.3 && < 1.3`` turn out to be very
1528 common because it is recommended practice for package versions to
1529 correspond to API versions (see PVP_).
1531 Since Cabal 1.6, there is a special wildcard syntax to help with
1536 build-depends: foo ==1.2.*
1538 It is only syntactic sugar. It is exactly equivalent to
1539 ``foo >= 1.2 && < 1.3``.
1543 A potential pitfall of the wildcard syntax is that the
1544 constraint ``nats == 1.0.*`` doesn't match the release
1545 ``nats-1`` because the version ``1`` is lexicographically less
1546 than ``1.0``. This is not an issue with the caret-operator
1547 ``^>=`` described below.
1549 Starting with Cabal 2.0, there's a new version operator to express
1550 PVP_-style major upper bounds conveniently, and is inspired by similar
1551 syntactic sugar found in other language ecosystems where it's often
1552 called the "Caret" operator:
1560 This allows to assert the positive knowledge that this package is
1561 *known* to be semantically compatible with the releases
1562 ``foo-1.2.3.4`` and ``bar-1`` respectively. The information
1563 encoded via such ``^>=``-assertions is used by the cabal solver to
1564 infer version constraints describing semantically compatible
1565 version ranges according to the PVP_ contract (see below).
1567 Another way to say this is that ``foo < 1.3`` expresses *negative*
1568 information, i.e. "``foo-1.3`` or ``foo-1.4.2`` will *not* be
1569 compatible"; whereas ``foo ^>= 1.2.3.4`` asserts the *positive*
1570 information that "``foo-1.2.3.4`` is *known* to be compatible" and (in
1571 the absence of additional information) according to the PVP_
1572 contract we can (positively) infer right away that all versions
1573 satisfying ``foo >= 1.2.3.4 && < 1.3`` will be compatible as well.
1577 More generally, the PVP_ contract implies that we can safely
1578 relax the lower bound to ``>= 1.2``, because if we know that
1579 ``foo-1.2.3.4`` is semantically compatible, then so is
1580 ``foo-1.2`` (if it typechecks). But we'd need to perform
1581 additional static analysis (i.e. perform typechecking) in order
1582 to know if our package in the role of an API consumer will
1583 successfully typecheck against the dependency ``foo-1.2``. But
1584 since we cannot do this analysis during constraint solving and
1585 to keep things simple, we pragmatically use ``foo >= 1.2.3.4``
1586 as the initially inferred approximation for the lower bound
1587 resulting from the assertion ``foo ^>= 1.2.3.4``. If further
1588 evidence becomes available that e.g. ``foo-1.2`` typechecks,
1589 one can simply revise the dependency specification to include
1590 the assertion ``foo ^>= 1.2``.
1592 The subtle but important difference in signaling allows tooling to
1593 treat explicitly expressed ``<``-style constraints and inferred
1594 (``^>=``-style) upper bounds differently. For instance,
1595 :cfg-field:`allow-newer`'s ``^``-modifier allows to relax only
1596 ``^>=``-style bounds while leaving explicitly stated
1597 ``<``-constraints unaffected.
1599 Ignoring the signaling intent, the default syntactic desugaring rules are
1601 - ``^>= x`` == ``>= x && < x.1``
1602 - ``^>= x.y`` == ``>= x.y && < x.(y+1)``
1603 - ``^>= x.y.z`` == ``>= x.y.z && < x.(y+1)``
1604 - ``^>= x.y.z.u`` == ``>= x.y.z.u && < x.(y+1)``
1609 One might expect the desugaring to truncate all version
1610 components below (and including) the patch-level, i.e.
1611 ``^>= x.y.z.u`` == ``>= x.y.z && < x.(y+1)``,
1612 as the major and minor version components alone are supposed to
1613 uniquely identify the API according to the PVP_. However, by
1614 designing ``^>=`` to be closer to the ``>=`` operator, we avoid
1615 the potentially confusing effect of ``^>=`` being more liberal
1616 than ``>=`` in the presence of patch-level versions.
1618 Consequently, the example declaration above is equivalent to
1623 foo >= 1.2.3.4 && < 1.3,
1628 Prior to Cabal 1.8, ``build-depends`` specified in each
1629 section were global to all sections. This was unintentional, but
1630 some packages were written to depend on it, so if you need your
1631 :pkg-field:`build-depends` to be local to each section, you must specify
1632 at least ``Cabal-Version: >= 1.8`` in your ``.cabal`` file.
1636 Cabal 1.20 experimentally supported module thinning and
1637 renaming in ``build-depends``; however, this support has since been
1638 removed and should not be used.
1640 Starting with Cabal 3.0, a set notation for the ``==`` and ``^>=`` operator
1641 is available. For instance,
1645 tested-with: GHC == 8.6.3, GHC == 8.4.4, GHC == 8.2.2, GHC == 8.0.2,
1646 GHC == 7.10.3, GHC == 7.8.4, GHC == 7.6.3, GHC == 7.4.2
1648 build-depends: network ^>= 2.6.3.6 || ^>= 2.7.0.2 || ^>= 2.8.0.0 || ^>= 3.0.1.0
1650 can be then written in a more convenient and concise form
1654 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 }
1656 build-depends: network ^>= { 2.6.3.6, 2.7.0.2, 2.8.0.0, 3.0.1.0 }
1659 .. pkg-field:: other-modules: identifier list
1661 A list of modules used by the component but not exposed to users.
1662 For a library component, these would be hidden modules of the
1663 library. For an executable, these would be auxiliary modules to be
1664 linked with the file named in the ``main-is`` field.
1668 Every module in the package *must* be listed in one of
1669 :pkg-field:`other-modules`, :pkg-field:`library:exposed-modules` or
1670 :pkg-field:`executable:main-is` fields.
1672 .. pkg-field:: hs-source-dir: directory list
1678 Root directories for the module hierarchy.
1680 Deprecated in favor of :pkg-field:`hs-source-dirs`.
1682 .. pkg-field:: hs-source-dirs: directory list
1686 Root directories for the module hierarchy.
1690 Components can share source directories but modules found there will be
1691 recompiled even if other components already built them, i.e., if a
1692 library and an executable share a source directory and the executable
1693 depends on the library and imports its ``Foo`` module, ``Foo`` will be
1694 compiled twice, once as part of the library and again for the executable.
1696 .. pkg-field:: default-extensions: identifier list
1699 A list of Haskell extensions used by every module. These determine
1700 corresponding compiler options enabled for all files. Extension
1701 names are the constructors of the
1702 `Extension <https://hackage.haskell.org/package/Cabal-syntax/docs/Language-Haskell-Extension.html#t:Extension>`__
1703 type. For example, ``CPP`` specifies that Haskell source files are
1704 to be preprocessed with a C preprocessor.
1706 .. pkg-field:: other-extensions: identifier list
1709 A list of Haskell extensions used by some (but not necessarily all)
1710 modules. From GHC version 6.6 onward, these may be specified by
1711 placing a ``LANGUAGE`` pragma in the source files affected e.g.
1713 .. code-block:: haskell
1715 {-# LANGUAGE CPP, MultiParamTypeClasses #-}
1717 In Cabal-1.24 the dependency solver will use this and
1718 :pkg-field:`default-extensions` information. Cabal prior to 1.24 will abort
1719 compilation if the current compiler doesn't provide the extensions.
1721 If you use some extensions conditionally, using CPP or conditional
1722 module lists, it is good to replicate the condition in
1723 :pkg-field:`other-extensions` declarations:
1727 other-extensions: CPP
1729 other-extensions: PolyKinds
1731 You could also omit the conditionally used extensions, as they are
1732 for information only, but it is recommended to replicate them in
1733 :pkg-field:`other-extensions` declarations.
1735 .. pkg-field:: default-language: identifier
1738 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>`__.
1740 The possible values are:
1742 - ``GHC2024`` (only available for GHC version ``9.10`` or later)
1743 - ``GHC2021`` (only available for GHC version ``9.2`` or later)
1747 .. pkg-field:: other-languages: identifier
1752 .. pkg-field:: extensions: identifier list
1756 Deprecated in favor of :pkg-field:`default-extensions`.
1758 .. pkg-field:: build-tool-depends: package:executable list
1761 A list of Haskell executables needed to build this component. Executables are provided
1762 during the whole duration of the component, so this field can be used for executables
1763 needed during :pkg-section:`test-suite` as well.
1765 Each is specified by the package containing the executable and the name of the
1766 executable itself, separated by a colon, and optionally followed by a version bound.
1768 All executables defined in the given Cabal file are termed as *internal* dependencies
1769 as opposed to the rest which are *external* dependencies.
1771 Each of the two is handled differently:
1773 1. External dependencies can (and should) contain a version bound like conventional
1774 :pkg-field:`build-depends` dependencies.
1775 2. Internal dependencies should not contain a version bound, as they will be always
1776 resolved within the same configuration of the package in the build plan.
1777 Specifically, version bounds that include the package's version will be warned for
1778 being extraneous, and version bounds that exclude the package's version will raise
1779 an error for being impossible to follow.
1781 For example (1) using a test-suite to make sure README.md Haskell snippets are tested using
1782 `markdown-unlit <http://hackage.haskell.org/package/markdown-unlit>`__:
1786 build-tool-depends: markdown-unlit:markdown-unlit >= 0.5.0 && < 0.6
1788 For example (2) using a test-suite to test executable behaviour in the same package:
1792 build-tool-depends: mypackage:executable
1794 Cabal tries to make sure that all specified programs are atomically built and prepended
1795 on the ``PATH`` shell variable before building the component in question, but can only do
1796 so for Nix-style builds. Specifically:
1798 a) For Nix-style local builds, both internal and external dependencies.
1799 b) For old-style builds, only for internal dependencies [#old-style-build-tool-depends]_.
1800 It's up to the user to provide needed executables in this case under ``PATH``.
1805 :pkg-field:`build-tool-depends` was added in Cabal 2.0, and it will
1806 be ignored (with a warning) with old versions of Cabal. See
1807 :pkg-field:`build-tools` for more information about backwards
1810 .. pkg-field:: build-tools: program list
1814 Deprecated in favor of :pkg-field:`build-tool-depends`, but :ref:`see below for backwards compatibility information <buildtoolsbc>`.
1816 A list of Haskell programs needed to build this component.
1817 Each may be followed by an optional version bound.
1818 Confusingly, each program in the list either refer to one of three things:
1820 1. Another executables in the same package (supported since Cabal 1.12)
1822 2. Tool name contained in Cabal's :ref:`hard-coded set of common tools <buildtoolsmap>`
1824 3. A pre-built executable that should already be on the ``PATH``
1825 (supported since Cabal 2.0)
1827 These cases are listed in order of priority:
1828 an executable in the package will override any of the hard-coded packages with the same name,
1829 and a hard-coded package will override any executable on the ``PATH``.
1831 In the first two cases, the list entry is desugared into a :pkg-field:`build-tool-depends` entry.
1832 In the first case, the entry is desugared into a :pkg-field:`build-tool-depends` entry by prefixing with ``$pkg:``.
1833 In the second case, it is desugared by looking up the package and executable name in a hard-coded table.
1834 In either case, the optional version bound is passed through unchanged.
1835 Refer to the documentation for :pkg-field:`build-tool-depends` to understand the desugared field's meaning, along with restrictions on version bounds.
1839 **Backward Compatibility**
1841 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.
1842 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.
1843 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``.
1847 **Set of Known Tool Names**
1849 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::
1851 build-tools: alex >= 3.2.1 && < 3.3, happy >= 1.19.5 && < 1.20
1853 is simply desugared into the equivalent specification::
1855 build-tool-depends: alex:alex >= 3.2.1 && < 3.3, happy:happy >= 1.19.5 && < 1.20
1857 +--------------------------+-----------------------------------+-----------------+
1858 | :pkg-field:`build-tools` | desugared | Note |
1859 | identifier | :pkg-field:`build-tool-depends` | |
1861 +==========================+===================================+=================+
1862 | ``alex`` | ``alex:alex`` | |
1863 +--------------------------+-----------------------------------+-----------------+
1864 | ``c2hs`` | ``c2hs:c2hs`` | |
1865 +--------------------------+-----------------------------------+-----------------+
1866 | ``cpphs`` | ``cpphs:cpphs`` | |
1867 +--------------------------+-----------------------------------+-----------------+
1868 | ``greencard`` | ``greencard:greencard`` | |
1869 +--------------------------+-----------------------------------+-----------------+
1870 | ``haddock`` | ``haddock:haddock`` | |
1871 +--------------------------+-----------------------------------+-----------------+
1872 | ``happy`` | ``happy:happy`` | |
1873 +--------------------------+-----------------------------------+-----------------+
1874 | ``hsc2hs`` | ``hsc2hs:hsc2hs`` | |
1875 +--------------------------+-----------------------------------+-----------------+
1876 | ``hscolour`` | ``hscolour:hscolour`` | |
1877 +--------------------------+-----------------------------------+-----------------+
1878 | ``hspec-discover`` | ``hspec-discover:hspec-discover`` | since Cabal 2.0 |
1879 +--------------------------+-----------------------------------+-----------------+
1881 This built-in set can be programmatically extended via use of the
1882 :ref:`Hooks build type<setup-hooks>` .
1884 .. pkg-field:: buildable: boolean
1888 Is the component buildable? Like some of the other fields below,
1889 this field is more useful with the slightly more elaborate form of
1890 the simple build infrastructure described in the section on
1891 `system-dependent parameters`_.
1893 .. pkg-field:: ghc-options: token list
1895 Additional options for GHC. You can often achieve the same effect
1896 using the :pkg-field:`default-extensions` field, which is preferred.
1898 Options required only by one module may be specified by placing an
1899 ``OPTIONS_GHC`` pragma in the source file affected.
1901 As with many other fields, whitespace can be escaped by using
1902 Haskell string syntax. Example:
1903 ``ghc-options: -Wcompat "-with-rtsopts=-T -I1" -Wall``.
1905 .. pkg-field:: ghc-prof-options: token list
1907 Additional options for GHC when the package is built with profiling
1910 Note that as of Cabal-1.24, the default profiling detail level
1911 defaults to ``exported-functions`` for libraries and
1912 ``toplevel-functions`` for executables. For GHC these correspond to
1913 the flags ``-fprof-auto-exported`` and ``-fprof-auto-top``. Prior to
1914 Cabal-1.24 the level defaulted to ``none``. These levels can be
1915 adjusted by the person building the package with the
1916 ``--profiling-detail`` and ``--library-profiling-detail`` flags.
1918 It is typically better for the person building the package to pick
1919 the profiling detail level rather than for the package author. So
1920 unless you have special needs it is probably better not to specify
1921 any of the GHC ``-fprof-auto*`` flags here. However if you wish to
1922 override the profiling detail level, you can do so using the
1923 :pkg-field:`ghc-prof-options` field: use ``-fno-prof-auto`` or one of the
1924 other ``-fprof-auto*`` flags.
1926 .. pkg-field:: ghc-shared-options: token list
1928 Additional options for GHC when the package is built as shared
1929 library. The options specified via this field are combined with the
1930 ones specified via :pkg-field:`ghc-options`, and are passed to GHC during
1931 both the compile and link phases.
1933 .. pkg-field:: ghcjs-options: token list
1935 Like :pkg-field:`ghc-options` but applies to GHCJS
1937 .. pkg-field:: ghcjs-prof-options: token list
1939 Like :pkg-field:`ghc-prof-options` but applies to GHCJS
1941 .. pkg-field:: ghcjs-shared-options: token list
1943 Like :pkg-field:`ghc-shared-options` but applies to GHCJS
1945 .. pkg-field:: includes: filename list
1947 A list of header files to be included in any compilations via C.
1948 This field applies to both header files that are already installed
1949 on the system and to those coming with the package to be installed.
1950 The former files should be found in absolute paths, while the latter
1951 files should be found in paths relative to the top of the source
1952 tree or relative to one of the directories listed in
1953 :pkg-field:`include-dirs`.
1955 These files typically contain function prototypes for foreign
1956 imports used by the package. This is in contrast to
1957 :pkg-field:`install-includes`, which lists header files that are intended
1958 to be exposed to other packages that transitively depend on this
1961 .. pkg-field:: install-includes: filename list
1963 A list of header files from this package to be installed into
1964 ``$libdir/includes`` when the package is installed. Files listed in
1965 :pkg-field:`install-includes` should be found in relative to the top of the
1966 source tree or relative to one of the directories listed in
1967 :pkg-field:`include-dirs`.
1969 :pkg-field:`install-includes` is typically used to name header files that
1970 contain prototypes for foreign imports used in Haskell code in this
1971 package, for which the C implementations are also provided with the
1972 package. For example, here is a ``.cabal`` file for a hypothetical
1973 ``bindings-clib`` package that bundles the C source code for ``clib``::
1977 install-includes: clib.h
1979 Now any package that depends (directly or transitively) on the
1980 ``bindings-clib`` library can use ``clib.h``.
1982 Note that in order for files listed in :pkg-field:`install-includes` to be
1983 usable when compiling the package itself, they need to be listed in
1984 the :pkg-field:`includes` field as well.
1986 .. pkg-field:: include-dirs: directory list
1988 A list of directories to search for header files, when preprocessing
1989 with ``c2hs``, ``hsc2hs``, ``cpphs`` or the C preprocessor, and also
1990 when compiling via C. Directories can be absolute paths (e.g., for
1991 system directories) or paths that are relative to the top of the
1992 source tree. Cabal looks in these directories when attempting to
1993 locate files listed in :pkg-field:`includes` and
1994 :pkg-field:`install-includes`.
1996 .. pkg-field:: c-sources: filename list
1998 A list of C source files to be compiled and linked with the Haskell
2001 .. pkg-field:: cxx-sources: filename list
2004 A list of C++ source files to be compiled and linked with the Haskell
2005 files. Useful for segregating C and C++ sources when supplying different
2006 command-line arguments to the compiler via the :pkg-field:`cc-options`
2007 and the :pkg-field:`cxx-options` fields. The files listed in the
2008 :pkg-field:`cxx-sources` can reference files listed in the
2009 :pkg-field:`c-sources` field and vice-versa. The object files will be linked
2012 .. pkg-field:: asm-sources: filename list
2015 A list of assembly source files to be compiled and linked with the
2018 .. pkg-field:: cmm-sources: filename list
2021 A list of C-- source files to be compiled and linked with the Haskell
2024 .. pkg-field:: js-sources: filename list
2026 A list of JavaScript source files to be linked with the Haskell
2027 files (only for JavaScript targets).
2029 .. pkg-field:: extra-libraries: token list
2031 A list of extra libraries to link with (when not linking fully static
2034 .. pkg-field:: extra-libraries-static: token list
2036 A list of extra libraries to link with (when linking fully static
2039 .. pkg-field:: extra-ghci-libraries: token list
2041 A list of extra libraries to be used instead of 'extra-libraries'
2042 when the package is loaded with GHCi.
2044 .. pkg-field:: extra-bundled-libraries: token list
2047 A list of libraries that are supposed to be copied from the build
2048 directory alongside the produced Haskell libraries. Note that you
2049 are under the obligation to produce those libraries in the build
2050 directory (e.g. via a custom setup). Libraries listed here will
2051 be included when ``copy``-ing packages and be listed in the
2052 ``hs-libraries`` of the package configuration in the package database.
2053 Library names must either be prefixed with "HS" or "C" and corresponding
2054 library file names must match:
2056 - Libraries with name "HS<library-name>":
2057 - `libHS<library-name>.a`
2058 - `libHS<library-name>-ghc<ghc-flavour><ghc-version>.<dyn-library-extension>*`
2059 - Libraries with name "C<library-name>":
2060 - `libC<library-name>.a`
2061 - `lib<library-name>.<dyn-library-extension>*`
2063 .. pkg-field:: extra-lib-dirs: directory list
2065 A list of directories to search for libraries (when not linking fully static
2068 .. pkg-field:: extra-lib-dirs-static: directory list
2070 A list of directories to search for libraries (when linking fully static
2073 .. pkg-field:: extra-library-flavours: notsure
2077 .. pkg-field:: extra-dynamic-library-flavours: notsure
2081 .. pkg-field:: cc-options: token list
2083 Command-line arguments to be passed to the C compiler. Since the
2084 arguments are compiler-dependent, this field is more useful with the
2085 setup described in the section on `system-dependent parameters`_.
2087 .. pkg-field:: cpp-options: token list
2089 Command-line arguments for pre-processing Haskell code. Applies to
2090 Haskell source and other pre-processed Haskell source like .hsc
2091 .chs. Does not apply to C code, that's what cc-options is for.
2093 .. pkg-field:: cxx-options: token list
2096 Command-line arguments to be passed to the compiler when compiling
2097 C++ code. The C++ sources to which these command-line arguments
2098 should be applied can be specified with the :pkg-field:`cxx-sources`
2099 field. Command-line options for C and C++ can be passed separately to
2100 the compiler when compiling both C and C++ sources by segregating the C
2101 and C++ sources with the :pkg-field:`c-sources` and
2102 :pkg-field:`cxx-sources` fields respectively, and providing different
2103 command-line arguments with the :pkg-field:`cc-options` and the
2104 :pkg-field:`cxx-options` fields.
2106 .. pkg-field:: cmm-options: token list
2109 Command-line arguments to be passed to the compiler when compiling
2110 C-- code. See also :pkg-field:`cmm-sources`.
2112 .. pkg-field:: asm-options: token list
2115 Command-line arguments to be passed to the assembler when compiling
2116 assembler code. See also :pkg-field:`asm-sources`.
2118 .. pkg-field:: ld-options: token list
2120 Command-line arguments to be passed to the linker. Since the
2121 arguments are compiler-dependent, this field is more useful with the
2122 setup described in the section on `system-dependent parameters`_.
2124 .. pkg-field:: hsc2hs-options: token list
2127 Command-line arguments to be passed to ``hsc2hs``.
2129 .. pkg-field:: pkgconfig-depends: package list
2132 `pkg-config <http://www.freedesktop.org/wiki/Software/pkg-config/>`__
2133 packages, needed to build this package. They can be annotated with
2134 versions, e.g. ``gtk+-2.0 >= 2.10, cairo >= 1.0``. If no version
2135 constraint is specified, any version is assumed to be acceptable.
2136 Cabal uses ``pkg-config`` to find if the packages are available on
2137 the system and to find the extra compilation and linker options
2138 needed to use the packages.
2140 If you need to bind to a C library that supports ``pkg-config`` then
2141 it is much preferable to use this field rather than hard code options
2142 into the other fields. ``pkg-config --list-all`` will show you all
2143 supported libraries. Depending on your system you may need to adjust
2144 ``PKG_CONFIG_PATH``.
2146 .. pkg-field:: frameworks: token list
2148 On Darwin/MacOS X, a list of frameworks to link to. See Apple's
2149 developer documentation for more details on frameworks. This entry
2150 is ignored on all other platforms.
2152 .. pkg-field:: extra-framework-dirs: directory list
2155 On Darwin/MacOS X, a list of directories to search for frameworks.
2156 This entry is ignored on all other platforms.
2158 .. pkg-field:: mixins: mixin list
2161 Supported only in GHC 8.2 and later. A list of packages mentioned in the
2162 :pkg-field:`build-depends` field, each optionally accompanied by a list of
2163 module and module signature renamings. A valid mixin obeys the
2168 Mixin ::= PackageName IncludeRenaming
2169 IncludeRenaming ::= ModuleRenaming { "requires" ModuleRenaming }
2172 | "(" Renaming "," ... "," Renaming ")"
2173 | "hiding" "(" ModuleName "," ... "," ModuleName ")"
2176 | ModuleName "as" ModuleName
2178 The simplest mixin syntax is simply the name of a package mentioned in the
2179 :pkg-field:`build-depends` field. For example:
2189 But this doesn't have any effect. More interesting is to use the mixin
2190 entry to rename one or more modules from the package, like this:
2196 foo (Foo.Bar as AnotherFoo.Bar, Foo.Baz as AnotherFoo.Baz)
2198 Note that renaming a module like this will hide all the modules
2199 that are not explicitly named.
2201 Modules can also be hidden:
2207 foo hiding (Foo.Bar)
2209 Hiding modules exposes everything that is not explicitly hidden.
2213 Cabal files with :pkg-field:`cabal-version` < 3.0 suffer from an
2214 infelicity in how the entries of :pkg-field:`mixins` are parsed: an
2215 entry will fail to parse if the provided renaming clause has whitespace
2216 after the opening parenthesis.
2218 See issues :issue:`5150`, :issue:`4864`, and :issue:`5293`.
2220 There can be multiple mixin entries for a given package, in effect creating
2221 multiple copies of the dependency:
2227 foo (Foo.Bar as AnotherFoo.Bar, Foo.Baz as AnotherFoo.Baz),
2228 foo (Foo.Bar as YetAnotherFoo.Bar)
2230 The ``requires`` clause is used to rename the module signatures required by
2237 foo (Foo.Bar as AnotherFoo.Bar) requires (Foo.SomeSig as AnotherFoo.SomeSig)
2239 Signature-only packages don't have any modules, so only the signatures can
2240 be renamed, with the following syntax:
2246 sigonly requires (SigOnly.SomeSig as AnotherSigOnly.SomeSig)
2248 See the :pkg-field:`library:signatures` field for more details.
2250 Mixin packages are part of the :ref:`Backpack` extension to the
2251 Haskell module system.
2253 The matching of the module signatures required by a
2254 :pkg-field:`build-depends` dependency with the implementation modules
2255 present in another dependency is triggered by a coincidence of names. When
2256 the names of the signature and of the implementation are already the same,
2257 the matching is automatic. But when the names don't coincide, or we want to
2258 instantiate a signature in two different ways, adding mixin entries that
2259 perform renamings becomes necessary.
2263 :ref:`Backpack` has the limitation that implementation modules that instantiate
2264 signatures required by a :pkg-field:`build-depends` dependency can't
2265 reside in the same component that has the dependency. They must reside
2266 in a different package dependency, or at least in a separate internal
2272 Library and executable sections may include conditional blocks, which
2273 test for various system parameters and configuration flags. The flags
2274 mechanism is rather generic, but most of the time a flag represents
2275 certain feature, that can be switched on or off by the package user.
2276 Here is an example package description file using configurations:
2278 Example: A package containing a library and executable programs
2279 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2286 License: BSD-3-Clause
2288 Synopsis: Test package to test configurations
2293 Description: Enable debug support
2298 Description: Include API for web frontend.
2303 description: Whether to build against @directory >= 1.2@
2304 -- This is an automatic flag which the solver will
2305 -- assign automatically while searching for a solution
2308 Build-Depends: base >= 4.2 && < 4.9
2309 Exposed-Modules: Testing.Test1
2310 Default-Extensions: CPP
2311 Default-Language: Haskell2010
2315 CPP-Options: -DDEBUG
2317 CC-Options: "-DDEBUG"
2319 CC-Options: "-DNDEBUG"
2321 if flag(WebFrontend)
2322 Build-Depends: cgi >= 0.42 && < 0.44
2323 Other-Modules: Testing.WebStuff
2324 CPP-Options: -DWEBFRONTEND
2326 if flag(NewDirectory)
2327 build-depends: directory >= 1.2 && < 1.4
2328 Build-Depends: time >= 1.0 && < 1.9
2330 build-depends: directory == 1.1.*
2331 Build-Depends: old-time >= 1.0 && < 1.2
2335 Other-Modules: Testing.Test1
2336 Build-Depends: base >= 4.2 && < 4.9
2337 Default-Language: Haskell2010
2340 CC-Options: "-DDEBUG"
2341 CPP-Options: -DDEBUG
2346 Flags, conditionals, library and executable sections use layout to
2347 indicate structure. This is very similar to the Haskell layout rule.
2348 Entries in a section have to all be indented to the same level which
2349 must be more than the section header. Tabs are not allowed to be used
2352 As an alternative to using layout you can also use explicit braces
2353 ``{}``. In this case the indentation of entries in a section does not
2354 matter, though different fields within a block must be on different
2355 lines. Here is a bit of the above example again, using braces:
2357 Example: Using explicit braces rather than indentation for layout
2358 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2365 License: BSD-3-Clause
2367 Synopsis: Test package to test configurations
2372 Description: Enable debug support
2378 Build-Depends: base >= 4.2 && < 4.9
2379 Exposed-Modules: Testing.Test1
2380 Default-Extensions: CPP
2381 Default-language: Haskell2010
2383 CPP-Options: -DDEBUG
2385 CC-Options: "-DDEBUG"
2387 CC-Options: "-DNDEBUG"
2395 .. pkg-section:: flag name
2396 :synopsis: Flag declaration.
2398 Flag section declares a flag which can be used in `conditional blocks`_.
2400 Flag names are case-insensitive and must match ``[[:alnum:]_][[:alnum:]_-]*``
2401 regular expression, or expressed as ABNF_:
2403 .. code-block:: abnf
2405 flag-name = (UALNUM / "_") *(UALNUM / "_" / "-")
2407 UALNUM = UALPHA / DIGIT
2408 UALPHA = ... ; set of alphabetic Unicode code-points
2412 Hackage accepts ASCII-only flags, ``[a-zA-Z0-9_][a-zA-Z0-9_-]*`` regexp.
2414 .. pkg-field:: description: freeform
2416 The description of this flag.
2418 .. pkg-field:: default: boolean
2422 The default value of this flag.
2426 This value may be :ref:`overridden in several
2427 ways <controlling flag assignments>`. The
2428 rationale for having flags default to True is that users usually
2429 want new features as soon as they are available. Flags representing
2430 features that are not (yet) recommended for most users (such as
2431 experimental features or debugging support) should therefore
2432 explicitly override the default to False.
2434 .. pkg-field:: manual: boolean
2439 By default, Cabal will first try to satisfy dependencies with the
2440 default flag value and then, if that is not possible, with the
2441 negated value. However, if the flag is manual, then the default
2442 value (which can be overridden by commandline flags) will be used.
2444 .. _conditional-blocks:
2449 Conditional blocks may appear anywhere inside a component or common
2450 section. They have to follow rather strict formatting rules. Conditional
2451 blocks must always be of the shape
2456 property-descriptions-or-conditionals
2463 property-descriptions-or-conditionals
2465 property-descriptions-or-conditionals
2467 Note that the ``if`` and the condition have to be all on the same line.
2469 Since Cabal 2.2 conditional blocks support ``elif`` construct.
2474 property-descriptions-or-conditionals
2476 property-descriptions-or-conditionals
2478 property-descriptions-or-conditionals
2485 Conditions can be formed using boolean tests and the boolean operators
2486 ``||`` (disjunction / logical "or"), ``&&`` (conjunction / logical
2487 "and"), or ``!`` (negation / logical "not"). The unary ``!`` takes
2488 highest precedence, ``||`` takes lowest. Precedence levels may be
2489 overridden through the use of parentheses. For example,
2490 ``os(darwin) && !arch(i386) || os(freebsd)`` is equivalent to
2491 ``(os(darwin) && !(arch(i386))) || os(freebsd)``.
2493 The following tests are currently supported.
2496 Tests if the current operating system is *name*. The argument is
2497 tested against ``System.Info.os`` on the target system. There is
2498 unfortunately some disagreement between Haskell implementations
2499 about the standard values of ``System.Info.os``. Cabal canonicalises
2500 it so that in particular ``os(windows)`` works on all
2501 implementations. If the canonicalised os names match, this test
2502 evaluates to true, otherwise false. The match is case-insensitive.
2503 :samp:`arch({name})`
2504 Tests if the current architecture is *name*. *name* should be the name of
2505 one of the nullary constructors of ``Distribution.System.Arch`` (e.g.
2506 ``x86_64``, ``aarch64`` or ``i386``), otherwise it will be treated as an
2507 'other architecture' of the given *name*. It will be compared with
2508 ``Distribution.System.buildArch``, which is derived from
2509 ``System.Info.arch`` (certain architectures are treated as synonymous; e.g.
2510 ``aarch64`` / ``arm64`` or ``powerpc64`` / ``powerpc64le`` are not
2511 distinguished). For a match, this test evaluates to true, otherwise false.
2512 The match is case-insensitive.
2513 :samp:`impl({compiler})`
2514 Tests for the configured Haskell implementation. An optional version
2515 constraint may be specified (for example ``impl(ghc >= 6.6.1)``). If
2516 the configured implementation is of the right type and matches the
2517 version constraint, then this evaluates to true, otherwise false.
2518 The match is case-insensitive.
2520 Note that including a version constraint in an ``impl`` test causes
2521 it to check for two properties:
2523 - The current compiler has the specified name, and
2525 - The compiler's version satisfied the specified version constraint
2527 As a result, ``!impl(ghc >= x.y.z)`` is not entirely equivalent to
2528 ``impl(ghc < x.y.z)``. The test ``!impl(ghc >= x.y.z)`` checks that:
2530 - The current compiler is not GHC, or
2532 - The version of GHC is earlier than version x.y.z.
2534 :samp:`flag({name})`
2535 Evaluates to the current assignment of the flag of the given name.
2536 Flag names are case insensitive. Testing for flags that have not
2537 been introduced with a flag section is an error.
2539 Constant value true.
2541 Constant value false.
2543 .. _resolution-of-conditions-and-flags:
2545 Resolution of Conditions and Flags
2546 """"""""""""""""""""""""""""""""""
2548 If a package descriptions specifies configuration flags the package user
2549 can :ref:`control these in several ways <controlling flag assignments>`. If the
2550 user does not fix the value of a flag, Cabal will try to find a flag
2551 assignment in the following way.
2553 - For each flag specified, it will assign its default value, evaluate
2554 all conditions with this flag assignment, and check if all
2555 dependencies can be satisfied. If this check succeeded, the package
2556 will be configured with those flag assignments.
2558 - If dependencies were missing, the last flag (as by the order in which
2559 the flags were introduced in the package description) is tried with
2560 its alternative value and so on. This continues until either an
2561 assignment is found where all dependencies can be satisfied, or all
2562 possible flag assignments have been tried.
2564 To put it another way, Cabal does a complete backtracking search to find
2565 a satisfiable package configuration. It is only the dependencies
2566 specified in the :pkg-field:`build-depends` field in conditional blocks that
2567 determine if a particular flag assignment is satisfiable
2568 (:pkg-field:`build-tools` are not considered). The order of the declaration and
2569 the default value of the flags determines the search order. Flags
2570 overridden on the command line fix the assignment of that flag, so no
2571 backtracking will be tried for that flag.
2573 If no suitable flag assignment could be found, the configuration phase
2574 will fail and a list of missing dependencies will be printed. Note that
2575 this resolution process is exponential in the worst case (i.e., in the
2576 case where dependencies cannot be satisfied). There are some
2577 optimizations applied internally, but the overall complexity remains
2580 Meaning of field values when using conditionals
2581 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2583 During the configuration phase, a flag assignment is chosen, all
2584 conditionals are evaluated, and the package description is combined into
2585 a flat package descriptions. If the same field is declared both inside
2586 a conditional and outside then they are combined using the following rules.
2588 - Boolean fields are combined using conjunction (logical "and").
2590 - List fields are combined by appending the inner items to the outer
2595 other-extensions: CPP
2597 other-extensions: MultiParamTypeClasses
2599 when compiled using GHC will be combined to
2603 other-extensions: CPP, MultiParamTypeClasses
2605 Similarly, if two conditional sections appear at the same nesting
2606 level, properties specified in the latter will come after properties
2607 specified in the former.
2609 - All other fields must not be specified in ambiguous ways. For example
2614 if flag(useothermain)
2615 Main-is: OtherMain.hs
2617 will lead to an error. Instead use
2621 if flag(useothermain)
2622 Main-is: OtherMain.hs
2631 .. pkg-section:: common name
2633 :synopsis: Common build info section
2635 Starting with Cabal-2.2 it's possible to use common build info stanzas.
2640 build-depends: base ^>= 4.11
2644 build-depends: tasty ^>= 0.12.0.1
2648 exposed-modules: Foo
2649 default-language: Haskell2010
2652 import: deps, test-deps
2653 type: exitcode-stdio-1.0
2656 default-language: Haskell2010
2658 - You can use `build information`_ fields in common stanzas.
2660 - Common stanzas must be defined before use.
2662 - Common stanzas can import other common stanzas.
2664 - You can import multiple stanzas at once. Stanza names must be separated by commas.
2666 - ``import`` must be the first field in a section. Since Cabal 3.0 imports
2667 are also allowed inside conditionals.
2671 The name `import` was chosen, because there is ``includes`` field.
2673 .. pkg-section:: None
2675 .. pkg-field:: import: token-list
2680 .. _pkg-author-source:
2682 *Source code* repository marker
2683 -------------------------------
2685 .. pkg-section:: source-repository
2688 A marker that points to the *source code* for this package within a
2689 **source code repository**.
2691 There are two kinds. You can specify one or the other or both at once:
2693 - The ``head`` kind refers to the latest development branch of the
2694 package. This may be used for example to track activity of a project
2695 or as an indication to outside developers what sources to get for
2696 making new contributions.
2698 - The ``this`` kind refers to the branch and tag of a repository that
2699 contains the sources for this version or release of a package. For most
2700 source control systems this involves specifying a tag, id or hash of some
2701 form and perhaps a branch.
2703 As an example, here are the repositories for the Cabal library. Note that the
2704 ``this`` kind of repository specifies a tag.
2708 source-repository head
2710 location: https://github.com/haskell/cabal
2712 source-repository this
2714 location: https://github.com/haskell/cabal
2717 The :ref:`cabal get<cabal-get>` command uses the kind of repository with
2718 its ``--source-repository`` option, if provided.
2720 .. _source-repository-fields:
2722 The :ref:`VCS fields<vcs-fields>` of ``source-repository`` are:
2725 data SourceRepo = SourceRepo
2726 { repoKind :: RepoKind
2727 , repoType :: Maybe RepoType
2728 , repoLocation :: Maybe String
2729 , repoModule :: Maybe String
2730 , repoBranch :: Maybe String
2731 , repoTag :: Maybe String
2732 , repoSubdir :: Maybe FilePath
2735 .. pkg-field:: type: VCS kind
2737 This field is required.
2739 .. pkg-field:: location: VCS location
2741 This field is required.
2743 .. pkg-field:: module: token
2745 CVS requires a named module, as each CVS server can host multiple
2748 This field is required for the CVS repository type and should not be
2751 .. pkg-field:: branch: VCS branch
2753 This field is optional.
2755 .. pkg-field:: tag: VCS tag
2757 This field is required for the ``this`` repository kind.
2759 This might be used to indicate what sources to get if someone needs to fix a
2760 bug in an older branch that is no longer an active head branch.
2762 .. pkg-field:: subdir: VCS subdirectory
2764 This field is optional but, if given, specifies a single subdirectory.
2771 The ``Hooks`` build type allows customising the configuration and the building
2772 of a package using a collection of **hooks** into the build system.
2774 Introduced in Cabal 3.14, this build type provides an alternative
2775 to :ref:`Custom setups <custom-setup>` which integrates better with the rest of the
2778 To use this build type in your package, you need to:
2780 * Declare a ``cabal-version`` of at least 3.14 in your ``.cabal`` file.
2781 * Declare ``build-type: Hooks`` in your ``.cabal`` file.
2782 * Include a ``custom-setup`` stanza in your ``.cabal`` file, which declares
2783 the version of the Hooks API your package is using.
2784 * Define a ``SetupHooks.hs`` module next to your ``.cabal`` file. It must
2785 export a value ``setupHooks :: SetupHooks``.
2787 More specifically, your ``.cabal`` file should resemble the following:
2789 .. code-block:: cabal
2796 base >= 4.18 && < 5,
2797 Cabal-hooks >= 0.1 && < 0.2
2799 while a basic ``SetupHooks.hs`` file might look like the following:
2801 .. code-block:: haskell
2803 module SetupHooks where
2804 import Distribution.Simple.SetupHooks ( SetupHooks, noSetupHooks )
2806 setupHooks :: SetupHooks
2809 { configureHooks = myConfigureHooks
2810 , buildHooks = myBuildHooks }
2814 Refer to the `Hackage documentation for the Distribution.Simple.SetupHooks module <https://hackage.haskell.org/package/Cabal-hooks/docs/Distribution-Simple-SetupHooks.html>`__
2815 for an overview of the ``Hooks`` API. Further motivation and a technical overview
2816 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>`__ .
2820 Custom setup scripts
2821 --------------------
2823 Deprecated since Cabal 3.14: prefer using the :ref:`Hooks build type<setup-hooks>` instead.
2825 Since Cabal 1.24, custom ``Setup.hs`` are required to accurately track
2826 their dependencies by declaring them in the ``.cabal`` file rather than
2827 rely on dependencies being implicitly in scope. Please refer to
2828 `this article <https://www.well-typed.com/blog/2015/07/cabal-setup-deps/>`__
2831 As of Cabal library version 3.0, ``defaultMain*`` variants implement support
2832 for response files. Custom ``Setup.hs`` files that do not use one of these
2833 main functions are required to implement their own support, such as by using
2834 ``GHC.ResponseFile.getArgsWithResponseFiles``.
2836 Declaring a ``custom-setup`` stanza also enables the generation of
2837 ``MIN_VERSION_package_(A,B,C)`` CPP macros for the Setup component.
2839 .. pkg-section:: custom-setup
2840 :synopsis: Build information for ``Custom`` and ``Hooks`` build types
2843 A :pkg-section:`custom-setup` stanza is required for ``Custom`` and ``Hooks``
2844 :pkg-field:`build-type`, and will be ignored (with a warning)
2845 for other build types.
2847 The stanza contains information needed for the compilation
2848 of custom ``Setup.hs`` scripts, and of ``SetupHooks.hs`` hooks.
2855 base >= 4.5 && < 4.11,
2856 Cabal >= 1.14 && < 1.25
2858 .. pkg-field:: setup-depends: package list
2861 The dependencies needed to compile ``Setup.hs`` or ``SetupHooks.hs``. See the
2862 :pkg-field:`build-depends` field for a description of the syntax expected by
2865 If the field is not specified the implicit package set will be used.
2866 The package set contains packages bundled with GHC (i.e. ``base``,
2867 ``bytestring``) and specifically ``Cabal``.
2868 The specific bounds are put on ``Cabal`` dependency:
2869 lower-bound is inferred from :pkg-field:`cabal-version`,
2870 and the upper-bound is ``< 1.25``.
2872 ``Cabal`` version is additionally restricted by GHC,
2873 with absolute minimum being ``1.20``, and for example ``Custom``
2874 builds with GHC-8.10 require at least ``Cabal-3.2``.
2877 Backward compatibility and ``custom-setup``
2878 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2880 Versions prior to Cabal 1.24 don't recognise ``custom-setup`` stanzas,
2881 and will behave agnostic to them (except for warning about an unknown
2882 'section'). Consequently, versions prior to Cabal 1.24 can't ensure the
2883 declared dependencies ``setup-depends`` are in scope, and instead
2884 whatever is registered in the current package database environment
2885 will become eligible (and resolved by the compiler) for the
2886 ``Setup.hs`` module.
2888 The availability of the
2889 ``MIN_VERSION_package_(A,B,C)`` CPP macros
2890 inside ``Setup.hs`` scripts depends on the condition that either
2892 - a ``custom-setup`` stanza has been declared (or ``cabal build`` is being used
2893 which injects an implicit hard-coded ``custom-setup`` stanza if it's missing),
2895 - GHC 8.0 or later is used (which natively injects package version CPP macros)
2897 Consequently, if you need to write backward compatible ``Setup.hs``
2898 scripts using CPP, you should declare a ``custom-setup`` stanza and
2899 use the pattern below:
2901 .. code-block:: haskell
2903 {-# LANGUAGE CPP #-}
2904 import Distribution.Simple
2906 #if defined(MIN_VERSION_Cabal)
2907 -- version macros are available and can be used as usual
2908 # if MIN_VERSION_Cabal(a,b,c)
2909 -- code specific to lib:Cabal >= a.b.c
2911 -- code specific to lib:Cabal < a.b.c
2914 # warning Enabling heuristic fall-back. Please upgrade cabal-install to 1.24 or later if Setup.hs fails to compile.
2916 -- package version macros not available; except for exotic environments,
2917 -- you can heuristically assume that lib:Cabal's version is correlated
2918 -- with __GLASGOW_HASKELL__, and specifically since we can assume that
2919 -- GHC < 8.0, we can assume that lib:Cabal is version 1.22 or older.
2924 The simplified (heuristic) CPP pattern shown below is useful if all you need
2925 is to distinguish ``Cabal < 2.0`` from ``Cabal >= 2.0``.
2927 .. code-block:: haskell
2929 {-# LANGUAGE CPP #-}
2930 import Distribution.Simple
2932 #if !defined(MIN_VERSION_Cabal)
2933 # define MIN_VERSION_Cabal(a,b,c) 0
2936 #if MIN_VERSION_Cabal(2,0,0)
2937 -- code for lib:Cabal >= 2.0
2939 -- code for lib:Cabal < 2.0
2946 Autogenerated modules and includes
2947 ----------------------------------
2949 .. pkg-section:: None
2951 Modules that are built automatically at setup, created with a custom
2952 setup script, must appear on :pkg-field:`other-modules` for the library,
2953 executable, test-suite or benchmark stanzas or also on
2954 :pkg-field:`library:exposed-modules` for libraries to be used, but are not
2955 really on the package when distributed. This makes commands like sdist fail
2956 because the file is not found.
2958 These special modules must appear again on the :pkg-field:`autogen-modules`
2959 field of the stanza that is using them, besides :pkg-field:`other-modules` or
2960 :pkg-field:`library:exposed-modules`. With this there is no need to create
2961 complex build hooks for this poweruser case.
2963 .. pkg-field:: autogen-modules: module list
2966 .. todo:: document autogen-modules field
2968 Right now :pkg-field:`executable:main-is` modules are not supported on
2969 :pkg-field:`autogen-modules`.
2974 default-language: Haskell2010
2985 default-language: Haskell2010
2994 .. pkg-field:: autogen-includes: filename list
2997 A list of header files from this package which are autogenerated
2998 (e.g. by a ``configure`` script). Autogenerated header files are not
2999 packaged by ``sdist`` command.
3002 .. _accessing-data-files:
3004 Accessing data files from package code
3005 --------------------------------------
3007 The placement on the target system of files listed in
3008 the :pkg-field:`data-files` field varies between systems, and in some cases
3009 one can even move packages around after installation
3010 (see :ref:`prefix independence`). To
3011 enable packages to find these files in a portable way, Cabal generates a
3012 module called :file:`Paths_{pkgname}` (with any hyphens in *pkgname*
3013 replaced by underscores) during building, so that it may be imported by
3014 modules of the package. This module defines a function
3016 .. code-block:: haskell
3018 getDataFileName :: FilePath -> IO FilePath
3020 If the argument is a filename listed in the :pkg-field:`data-files` field, the
3021 result is the name of the corresponding file on the system on which the
3026 If you decide to import the :file:`Paths_{pkgname}` module then it
3027 *must* be listed in the :pkg-field:`other-modules` field just like any other
3028 module in your package and on :pkg-field:`autogen-modules` as the file is
3031 The :file:`Paths_{pkgname}` module is not platform independent, as any
3032 other autogenerated module, so it does not get included in the source
3033 tarballs generated by ``sdist``.
3035 The :file:`Paths_{pkgname}` module also includes some other useful
3036 functions and values, which record the version of the package and some
3037 other directories which the package has been configured to be installed
3038 into (e.g. data files live in ``getDataDir``):
3040 .. code-block:: haskell
3044 getBinDir :: IO FilePath
3045 getLibDir :: IO FilePath
3046 getDynLibDir :: IO FilePath
3047 getDataDir :: IO FilePath
3048 getLibexecDir :: IO FilePath
3049 getSysconfDir :: IO FilePath
3051 The actual location of all these directories can be individually
3052 overridden at runtime using environment variables of the form
3053 ``pkg_name_var``, where ``pkg_name`` is the name of the package with all
3054 hyphens converted into underscores, and ``var`` is either ``bindir``,
3055 ``libdir``, ``dynlibdir``, ``datadir``, ``libexedir`` or ``sysconfdir``. For example,
3056 the configured data directory for ``pretty-show`` is controlled with the
3057 ``pretty_show_datadir`` environment variable.
3059 Accessing the package version
3060 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3062 The auto generated :file:`PackageInfo_{pkgname}` module exports the constant
3063 ``version ::`` `Version <http://hackage.haskell.org/package/base/docs/Data-Version.html>`__
3064 which is defined as the version of your package as specified in the
3067 Accessing package-related informations
3068 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3070 The auto generated :file:`PackageInfo_{pkgname}` module exports the following
3071 package-related constants:
3073 .. code-block:: haskell
3081 Unlike :file:`Paths_{pkgname}` (see <#accessing-data-files-from-package-code>),
3082 :file:`PackageInfo_{pkgname}` is system- and path-independent. It aims to be
3083 easier to work with for hash-based tools such as Nix.
3085 .. _system-dependent parameters:
3087 System-dependent parameters
3088 ---------------------------
3090 For some packages, especially those interfacing with C libraries,
3091 implementation details and the build procedure depend on the build
3092 environment. The ``build-type`` ``Configure`` can be used to handle many
3093 such situations. In this case, ``Setup.hs`` should be:
3095 .. code-block:: haskell
3097 import Distribution.Simple
3098 main = defaultMainWithHooks autoconfUserHooks
3100 Most packages, however, would probably do better using the ``Simple``
3101 build type and `configurations`_.
3103 The :pkg-field:`build-type` ``Configure`` differs from ``Simple`` in two ways:
3105 - The package root directory must contain a shell script called
3106 ``configure``. The configure step will run the script. This
3107 ``configure`` script may be produced by
3108 `autoconf <http://www.gnu.org/software/autoconf/>`__ or may be
3109 hand-written. The ``configure`` script typically discovers
3110 information about the system and records it for later steps, e.g. by
3111 generating system-dependent header files for inclusion in C source
3112 files and preprocessed Haskell source files. (Clearly this won't work
3113 for Windows without MSYS or Cygwin: other ideas are needed.)
3115 - If the package root directory contains a file called
3116 *package*\ ``.buildinfo`` after the configuration step, subsequent
3117 steps will read it to obtain additional settings for `build
3118 information`_ fields,to be merged with the ones
3119 given in the ``.cabal`` file. In particular, this file may be
3120 generated by the ``configure`` script mentioned above, allowing these
3121 settings to vary depending on the build environment.
3123 Note that the package's ``extra-source-files`` are available to the
3124 ``configure`` script when it is executed. In typical ``autoconf`` fashion,
3125 ``--host`` flag will be passed to the ``configure`` script to indicate the host
3126 platform when cross-compiling. Moreover, various bits of build configuration
3127 will be passed via environment variables:
3129 - ``CC`` will reflect the path to the C compiler
3130 - ``CFLAGS`` will reflect the path to the C compiler
3131 - ``CABAL_FLAGS`` will contain the Cabal flag assignment of the current
3132 package using traditional Cabal flag syntax (e.g. ``+flagA -flagB``)
3133 - ``CABAL_FLAG_<flag>`` will be set to either ``0`` or ``1`` depending upon
3134 whether flag ``<flag>`` is enabled. Note that any any non-alpha-numeric
3135 characters in the flag name are replaced with ``_``.
3137 The build information file should have the following structure:
3141 ``executable:`` *name* *buildinfo*
3143 ``executable:`` *name* *buildinfo* ...
3145 where each *buildinfo* consists of settings of fields listed in the
3146 section on `build information`_. The first one (if
3147 present) relates to the library, while each of the others relate to the
3148 named executable. (The names must match the package description, but you
3149 don't have to have entries for all of them.)
3151 Neither of these files is required. If they are absent, this setup
3152 script is equivalent to ``defaultMain``.
3154 Example: Using autoconf
3155 ^^^^^^^^^^^^^^^^^^^^^^^
3157 This example is for people familiar with the
3158 `autoconf <http://www.gnu.org/software/autoconf/>`__ tools.
3160 In the X11 package, the file ``configure.ac`` contains:
3162 .. code-block:: shell
3164 AC_INIT([Haskell X11 package], [1.1], [libraries@haskell.org], [X11])
3166 # Safety check: Ensure that we are in the correct source directory.
3167 AC_CONFIG_SRCDIR([X11.cabal])
3169 # Header file to place defines in
3170 AC_CONFIG_HEADERS([include/HsX11Config.h])
3172 # Check for X11 include paths and libraries
3174 AC_TRY_CPP([#include <X11/Xlib.h>],,[no_x=yes])
3176 # Build the package if we found X11 stuff
3177 if test "$no_x" = yes
3178 then BUILD_PACKAGE_BOOL=False
3179 else BUILD_PACKAGE_BOOL=True
3181 AC_SUBST([BUILD_PACKAGE_BOOL])
3183 AC_CONFIG_FILES([X11.buildinfo])
3186 Then the setup script will run the ``configure`` script, which checks
3187 for the presence of the X11 libraries and substitutes for variables in
3188 the file ``X11.buildinfo.in``:
3192 buildable: @BUILD_PACKAGE_BOOL@
3193 cc-options: @X_CFLAGS@
3194 ld-options: @X_LIBS@
3196 This generates a file ``X11.buildinfo`` supplying the parameters needed
3202 cc-options: -I/usr/X11R6/include
3203 ld-options: -L/usr/X11R6/lib
3205 The ``configure`` script also generates a header file
3206 ``include/HsX11Config.h`` containing C preprocessor defines recording
3207 the results of various tests. This file may be included by C source
3208 files and preprocessed Haskell source files in the package.
3212 Packages using these features will also need to list additional
3213 files such as ``configure``, templates for ``.buildinfo`` files, files
3214 named only in ``.buildinfo`` files, header files and so on in the
3215 :pkg-field:`extra-source-files` field to ensure that they are included in
3216 source distributions. They should also list files and directories generated
3217 by ``configure`` in the :pkg-field:`extra-tmp-files` field to ensure that
3218 they are removed by ``setup clean``.
3220 Quite often the files generated by ``configure`` need to be listed
3221 somewhere in the package description (for example, in the
3222 :pkg-field:`install-includes` field). However, we usually don't want generated
3223 files to be included in the source tarball. The solution is again
3224 provided by the ``.buildinfo`` file. In the above example, the following
3225 line should be added to ``X11.buildinfo``:
3229 install-includes: HsX11Config.h
3231 In this way, the generated ``HsX11Config.h`` file won't be included in
3232 the source tarball in addition to ``HsX11Config.h.in``, but it will be
3233 copied to the right location during the install process. Packages that
3234 use custom ``Setup.hs`` scripts can update the necessary fields
3235 programmatically instead of using the ``.buildinfo`` file.
3237 Conditional compilation
3238 -----------------------
3240 Sometimes you want to write code that works with more than one version
3241 of a dependency. You can specify a range of versions for the dependency
3242 in the :pkg-field:`build-depends`, but how do you then write the code that can
3243 use different versions of the API?
3245 Haskell lets you preprocess your code using the C preprocessor (either
3246 the real C preprocessor, or ``cpphs``). To enable this, add
3247 ``extensions: CPP`` to your package description. When using CPP, Cabal
3248 provides some pre-defined macros to let you test the version of
3249 dependent packages; for example, suppose your package works with either
3250 version 3 or version 4 of the ``base`` package, you could select the
3251 available version in your Haskell modules like this:
3255 #if MIN_VERSION_base(4,0,0)
3256 ... code that works with base-4 ...
3258 ... code that works with base-3 ...
3261 In general, Cabal supplies a macro
3262 ``MIN_VERSION_``\ *``package``*\ ``_(A,B,C)`` for each package depended
3263 on via :pkg-field:`build-depends`. This macro is true if the actual version of
3264 the package in use is greater than or equal to ``A.B.C`` (using the
3265 conventional ordering on version numbers, which is lexicographic on the
3266 sequence, but numeric on each component, so for example 1.2.0 is greater
3269 Since version 1.20, the ``MIN_TOOL_VERSION_``\ *``tool``*
3270 family of macros lets you condition on the version of build tools used to
3271 build the program (e.g. ``hsc2hs``).
3273 Since version 1.24, the macro ``CURRENT_COMPONENT_ID``, which
3274 expands to the string of the component identifier that uniquely
3275 identifies this component. Furthermore, if the package is a library,
3276 the macro ``CURRENT_PACKAGE_KEY`` records the identifier that was passed
3277 to GHC for use in symbols and for type equality.
3279 Since version 2.0, the macro ``CURRENT_PACKAGE_VERSION`` expands
3280 to the string version number of the current package.
3282 Cabal places the definitions of these macros into an
3283 automatically-generated header file, which is included when
3284 preprocessing Haskell source code by passing options to the C
3287 Cabal also allows to detect when the source code is being used for
3288 generating documentation. The ``__HADDOCK_VERSION__`` macro is defined
3289 only when compiling via Haddock_
3290 instead of a normal Haskell compiler. The value of the
3291 ``__HADDOCK_VERSION__`` macro is defined as ``A*1000 + B*10 + C``, where
3292 ``A.B.C`` is the Haddock version. This can be useful for working around
3293 bugs in Haddock or generating prettier documentation in some special
3296 .. _more-complex-packages:
3298 More complex packages
3299 ---------------------
3301 For packages that don't fit the simple schemes described above, you have
3304 - By using the :pkg-field:`build-type` ``Custom``, you can supply your own
3305 ``Setup.hs`` file, and customize the simple build infrastructure
3306 using *hooks*. These allow you to perform additional actions before
3307 and after each command is run, and also to specify additional
3308 preprocessors. A typical ``Setup.hs`` may look like this:
3310 .. code-block:: haskell
3312 import Distribution.Simple
3313 main = defaultMainWithHooks simpleUserHooks { postHaddock = posthaddock }
3315 posthaddock args flags desc info = ....
3317 See ``UserHooks`` in
3318 `Distribution.Simple <https://hackage.haskell.org/package/Cabal/docs/Distribution-Simple.html>`__
3319 for the details, but note that this interface is experimental, and
3320 likely to change in future releases.
3322 If you use a custom ``Setup.hs`` file you should strongly consider
3323 adding a :pkg-section:`custom-setup` stanza with a
3324 :pkg-field:`custom-setup:setup-depends` field to ensure that your setup
3325 script does not break with future dependency versions.
3327 - You could delegate all the work to ``make``, though this is unlikely
3328 to be very portable. Cabal supports this with the :pkg-field:`build-type`
3329 ``Make`` and a trivial setup library
3330 `Distribution.Make <https://hackage.haskell.org/package/Cabal/docs/Distribution-Make.html>`__,
3331 which simply parses the command line arguments and invokes ``make``.
3332 Here ``Setup.hs`` should look like this:
3334 .. code-block:: haskell
3336 import Distribution.Make
3339 The root directory of the package should contain a ``configure``
3340 script, and, after that has run, a ``Makefile`` with a default target
3341 that builds the package, plus targets ``install``, ``register``,
3342 ``unregister``, ``clean``, ``dist`` and ``docs``. Some options to
3343 commands are passed through as follows:
3345 - The ``--with-hc-pkg``, ``--prefix``, ``--bindir``, ``--libdir``,
3346 ``--dynlibdir``, ``--datadir``, ``--libexecdir`` and ``--sysconfdir`` options to
3347 the ``configure`` command are passed on to the ``configure``
3348 script. In addition the value of the ``--with-compiler`` option is
3349 passed in a ``--with-hc`` option and all options specified with
3350 ``--configure-option=`` are passed on.
3352 - The ``--destdir`` option to the ``copy`` command becomes a setting
3353 of a ``destdir`` variable on the invocation of ``make copy``. The
3354 supplied ``Makefile`` should provide a ``copy`` target, which will
3355 probably look like this:
3357 .. code-block:: make
3360 $(MAKE) install prefix=$(destdir)/$(prefix) \
3361 bindir=$(destdir)/$(bindir) \
3362 libdir=$(destdir)/$(libdir) \
3363 dynlibdir=$(destdir)/$(dynlibdir) \
3364 datadir=$(destdir)/$(datadir) \
3365 libexecdir=$(destdir)/$(libexecdir) \
3366 sysconfdir=$(destdir)/$(sysconfdir) \
3368 - Finally, with the :pkg-field:`build-type` ``Custom``, you can also write your
3369 own setup script from scratch, and you may use the Cabal
3370 library for all or part of the work. One option is to copy the source
3371 of ``Distribution.Simple``, and alter it for your needs. Good luck.
3373 .. include:: references.inc
3375 .. rubric:: Footnotes
3377 .. [#old-style-build-tool-depends]
3379 Some packages (ab)use :pkg-field:`build-depends` on old-style builds, but this has a few major drawbacks:
3381 - 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.
3382 - it may or may not place the executable on ``PATH``.
3383 - it does not ensure the correct version of the package is installed, so you might end up overwriting versions with each other.