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:: ghc-prof-shared-options: token list
1935 Additional options for GHC when the package is built as shared profiling
1936 library. The options specified via this field are combined with the
1937 ones specified via :pkg-field:`ghc-options`, and are passed to GHC during
1938 both the compile and link phases.
1940 .. pkg-field:: ghcjs-options: token list
1942 Like :pkg-field:`ghc-options` but applies to GHCJS
1944 .. pkg-field:: ghcjs-prof-options: token list
1946 Like :pkg-field:`ghc-prof-options` but applies to GHCJS
1948 .. pkg-field:: ghcjs-shared-options: token list
1950 Like :pkg-field:`ghc-shared-options` but applies to GHCJS
1952 .. pkg-field:: ghcjs-prof-shared-options: token list
1954 Like :pkg-field:`ghc-prof-shared-options` but applies to GHCJS
1956 .. pkg-field:: includes: filename list
1960 From GHC 6.10.1, :pkg-field:`includes` has no effect when compiling with
1961 GHC. From Cabal 2.0, support for GHC versions before GHC 6.12 was removed.
1963 A list of header files to be included in any compilations via C.
1964 This field applies to both header files that are already installed
1965 on the system and to those coming with the package to be installed.
1966 The former files should be found in absolute paths, while the latter
1967 files should be found in paths relative to the top of the source
1968 tree or relative to one of the directories listed in
1969 :pkg-field:`include-dirs`.
1971 These files typically contain function prototypes for foreign
1972 imports used by the package. This is in contrast to
1973 :pkg-field:`install-includes`, which lists header files that are intended
1974 to be exposed to other packages that transitively depend on this
1977 .. pkg-field:: install-includes: filename list
1979 A list of header files from this package to be installed into
1980 ``$libdir/includes`` when the package is installed. Files listed in
1981 :pkg-field:`install-includes` should be found in relative to the top of the
1982 source tree or relative to one of the directories listed in
1983 :pkg-field:`include-dirs`.
1985 :pkg-field:`install-includes` is typically used to name header files that
1986 contain prototypes for foreign imports used in Haskell code in this
1987 package, for which the C implementations are also provided with the
1988 package. For example, here is a ``.cabal`` file for a hypothetical
1989 ``bindings-clib`` package that bundles the C source code for ``clib``::
1993 install-includes: clib.h
1995 Now any package that depends (directly or transitively) on the
1996 ``bindings-clib`` library can use ``clib.h``.
1998 Note that in order for files listed in :pkg-field:`install-includes` to be
1999 usable when compiling the package itself, they need to be listed in
2000 the :pkg-field:`includes` field as well.
2002 .. pkg-field:: include-dirs: directory list
2004 A list of directories to search for header files, when preprocessing
2005 with ``c2hs``, ``hsc2hs``, ``cpphs`` or the C preprocessor, and also
2006 when compiling via C. Directories can be absolute paths (e.g., for
2007 system directories) or paths that are relative to the top of the
2008 source tree. Cabal looks in these directories when attempting to
2009 locate files listed in :pkg-field:`includes` and
2010 :pkg-field:`install-includes`.
2012 .. pkg-field:: c-sources: filename list
2014 A list of C source files to be compiled and linked with the Haskell
2017 .. pkg-field:: cxx-sources: filename list
2020 A list of C++ source files to be compiled and linked with the Haskell
2021 files. Useful for segregating C and C++ sources when supplying different
2022 command-line arguments to the compiler via the :pkg-field:`cc-options`
2023 and the :pkg-field:`cxx-options` fields. The files listed in the
2024 :pkg-field:`cxx-sources` can reference files listed in the
2025 :pkg-field:`c-sources` field and vice-versa. The object files will be linked
2028 .. pkg-field:: asm-sources: filename list
2031 A list of assembly source files to be compiled and linked with the
2034 .. pkg-field:: cmm-sources: filename list
2037 A list of C-- source files to be compiled and linked with the Haskell
2040 .. pkg-field:: js-sources: filename list
2042 A list of JavaScript source files to be linked with the Haskell
2043 files (only for JavaScript targets).
2045 .. pkg-field:: extra-libraries: token list
2047 A list of extra libraries to link with (when not linking fully static
2050 .. pkg-field:: extra-libraries-static: token list
2052 A list of extra libraries to link with (when linking fully static
2055 .. pkg-field:: extra-ghci-libraries: token list
2057 A list of extra libraries to be used instead of 'extra-libraries'
2058 when the package is loaded with GHCi.
2060 .. pkg-field:: extra-bundled-libraries: token list
2063 A list of libraries that are supposed to be copied from the build
2064 directory alongside the produced Haskell libraries. Note that you
2065 are under the obligation to produce those libraries in the build
2066 directory (e.g. via a custom setup). Libraries listed here will
2067 be included when ``copy``-ing packages and be listed in the
2068 ``hs-libraries`` of the package configuration in the package database.
2069 Library names must either be prefixed with "HS" or "C" and corresponding
2070 library file names must match:
2072 - Libraries with name "HS<library-name>":
2073 - `libHS<library-name>.a`
2074 - `libHS<library-name>-ghc<ghc-flavour><ghc-version>.<dyn-library-extension>*`
2075 - Libraries with name "C<library-name>":
2076 - `libC<library-name>.a`
2077 - `lib<library-name>.<dyn-library-extension>*`
2079 .. pkg-field:: extra-lib-dirs: directory list
2081 A list of directories to search for libraries (when not linking fully static
2084 .. pkg-field:: extra-lib-dirs-static: directory list
2086 A list of directories to search for libraries (when linking fully static
2089 .. pkg-field:: extra-library-flavours: notsure
2093 .. pkg-field:: extra-dynamic-library-flavours: notsure
2097 .. pkg-field:: cc-options: token list
2099 Command-line arguments to be passed to the C compiler. Since the
2100 arguments are compiler-dependent, this field is more useful with the
2101 setup described in the section on `system-dependent parameters`_.
2103 .. pkg-field:: cpp-options: token list
2105 Command-line arguments for pre-processing Haskell code. Applies to
2106 Haskell source and other pre-processed Haskell source like .hsc
2107 .chs. Does not apply to C code, that's what cc-options is for.
2109 .. pkg-field:: cxx-options: token list
2112 Command-line arguments to be passed to the compiler when compiling
2113 C++ code. The C++ sources to which these command-line arguments
2114 should be applied can be specified with the :pkg-field:`cxx-sources`
2115 field. Command-line options for C and C++ can be passed separately to
2116 the compiler when compiling both C and C++ sources by segregating the C
2117 and C++ sources with the :pkg-field:`c-sources` and
2118 :pkg-field:`cxx-sources` fields respectively, and providing different
2119 command-line arguments with the :pkg-field:`cc-options` and the
2120 :pkg-field:`cxx-options` fields.
2122 .. pkg-field:: cmm-options: token list
2125 Command-line arguments to be passed to the compiler when compiling
2126 C-- code. See also :pkg-field:`cmm-sources`.
2128 .. pkg-field:: asm-options: token list
2131 Command-line arguments to be passed to the assembler when compiling
2132 assembler code. See also :pkg-field:`asm-sources`.
2134 .. pkg-field:: ld-options: token list
2136 Command-line arguments to be passed to the linker. Since the
2137 arguments are compiler-dependent, this field is more useful with the
2138 setup described in the section on `system-dependent parameters`_.
2140 .. pkg-field:: hsc2hs-options: token list
2143 Command-line arguments to be passed to ``hsc2hs``.
2145 .. pkg-field:: pkgconfig-depends: package list
2148 `pkg-config <http://www.freedesktop.org/wiki/Software/pkg-config/>`__
2149 packages, needed to build this package. They can be annotated with
2150 versions, e.g. ``gtk+-2.0 >= 2.10, cairo >= 1.0``. If no version
2151 constraint is specified, any version is assumed to be acceptable.
2152 Cabal uses ``pkg-config`` to find if the packages are available on
2153 the system and to find the extra compilation and linker options
2154 needed to use the packages.
2156 If you need to bind to a C library that supports ``pkg-config`` then
2157 it is much preferable to use this field rather than hard code options
2158 into the other fields. ``pkg-config --list-all`` will show you all
2159 supported libraries. Depending on your system you may need to adjust
2160 ``PKG_CONFIG_PATH``.
2162 .. pkg-field:: frameworks: token list
2164 On Darwin/MacOS X, a list of frameworks to link to. See Apple's
2165 developer documentation for more details on frameworks. This entry
2166 is ignored on all other platforms.
2168 .. pkg-field:: extra-framework-dirs: directory list
2171 On Darwin/MacOS X, a list of directories to search for frameworks.
2172 This entry is ignored on all other platforms.
2174 .. pkg-field:: mixins: mixin list
2177 Supported only in GHC 8.2 and later. A list of packages mentioned in the
2178 :pkg-field:`build-depends` field, each optionally accompanied by a list of
2179 module and module signature renamings. A valid mixin obeys the
2184 Mixin ::= PackageName IncludeRenaming
2185 IncludeRenaming ::= ModuleRenaming { "requires" ModuleRenaming }
2188 | "(" Renaming "," ... "," Renaming ")"
2189 | "hiding" "(" ModuleName "," ... "," ModuleName ")"
2192 | ModuleName "as" ModuleName
2194 The simplest mixin syntax is simply the name of a package mentioned in the
2195 :pkg-field:`build-depends` field. For example:
2205 But this doesn't have any effect. More interesting is to use the mixin
2206 entry to rename one or more modules from the package, like this:
2212 foo (Foo.Bar as AnotherFoo.Bar, Foo.Baz as AnotherFoo.Baz)
2214 Note that renaming a module like this will hide all the modules
2215 that are not explicitly named.
2217 Modules can also be hidden:
2223 foo hiding (Foo.Bar)
2225 Hiding modules exposes everything that is not explicitly hidden.
2229 Cabal files with :pkg-field:`cabal-version` < 3.0 suffer from an
2230 infelicity in how the entries of :pkg-field:`mixins` are parsed: an
2231 entry will fail to parse if the provided renaming clause has whitespace
2232 after the opening parenthesis.
2234 See issues :issue:`5150`, :issue:`4864`, and :issue:`5293`.
2236 There can be multiple mixin entries for a given package, in effect creating
2237 multiple copies of the dependency:
2243 foo (Foo.Bar as AnotherFoo.Bar, Foo.Baz as AnotherFoo.Baz),
2244 foo (Foo.Bar as YetAnotherFoo.Bar)
2246 The ``requires`` clause is used to rename the module signatures required by
2253 foo (Foo.Bar as AnotherFoo.Bar) requires (Foo.SomeSig as AnotherFoo.SomeSig)
2255 Signature-only packages don't have any modules, so only the signatures can
2256 be renamed, with the following syntax:
2262 sigonly requires (SigOnly.SomeSig as AnotherSigOnly.SomeSig)
2264 See the :pkg-field:`library:signatures` field for more details.
2266 Mixin packages are part of the :ref:`Backpack` extension to the
2267 Haskell module system.
2269 The matching of the module signatures required by a
2270 :pkg-field:`build-depends` dependency with the implementation modules
2271 present in another dependency is triggered by a coincidence of names. When
2272 the names of the signature and of the implementation are already the same,
2273 the matching is automatic. But when the names don't coincide, or we want to
2274 instantiate a signature in two different ways, adding mixin entries that
2275 perform renamings becomes necessary.
2279 :ref:`Backpack` has the limitation that implementation modules that instantiate
2280 signatures required by a :pkg-field:`build-depends` dependency can't
2281 reside in the same component that has the dependency. They must reside
2282 in a different package dependency, or at least in a separate internal
2288 Library and executable sections may include conditional blocks, which
2289 test for various system parameters and configuration flags. The flags
2290 mechanism is rather generic, but most of the time a flag represents
2291 certain feature, that can be switched on or off by the package user.
2292 Here is an example package description file using configurations:
2294 Example: A package containing a library and executable programs
2295 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2302 License: BSD-3-Clause
2304 Synopsis: Test package to test configurations
2309 Description: Enable debug support
2314 Description: Include API for web frontend.
2319 description: Whether to build against @directory >= 1.2@
2320 -- This is an automatic flag which the solver will
2321 -- assign automatically while searching for a solution
2324 Build-Depends: base >= 4.2 && < 4.9
2325 Exposed-Modules: Testing.Test1
2326 Default-Extensions: CPP
2327 Default-Language: Haskell2010
2331 CPP-Options: -DDEBUG
2333 CC-Options: "-DDEBUG"
2335 CC-Options: "-DNDEBUG"
2337 if flag(WebFrontend)
2338 Build-Depends: cgi >= 0.42 && < 0.44
2339 Other-Modules: Testing.WebStuff
2340 CPP-Options: -DWEBFRONTEND
2342 if flag(NewDirectory)
2343 build-depends: directory >= 1.2 && < 1.4
2344 Build-Depends: time >= 1.0 && < 1.9
2346 build-depends: directory == 1.1.*
2347 Build-Depends: old-time >= 1.0 && < 1.2
2351 Other-Modules: Testing.Test1
2352 Build-Depends: base >= 4.2 && < 4.9
2353 Default-Language: Haskell2010
2356 CC-Options: "-DDEBUG"
2357 CPP-Options: -DDEBUG
2362 Flags, conditionals, library and executable sections use layout to
2363 indicate structure. This is very similar to the Haskell layout rule.
2364 Entries in a section have to all be indented to the same level which
2365 must be more than the section header. Tabs are not allowed to be used
2368 As an alternative to using layout you can also use explicit braces
2369 ``{}``. In this case the indentation of entries in a section does not
2370 matter, though different fields within a block must be on different
2371 lines. Here is a bit of the above example again, using braces:
2373 Example: Using explicit braces rather than indentation for layout
2374 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2381 License: BSD-3-Clause
2383 Synopsis: Test package to test configurations
2388 Description: Enable debug support
2394 Build-Depends: base >= 4.2 && < 4.9
2395 Exposed-Modules: Testing.Test1
2396 Default-Extensions: CPP
2397 Default-language: Haskell2010
2399 CPP-Options: -DDEBUG
2401 CC-Options: "-DDEBUG"
2403 CC-Options: "-DNDEBUG"
2411 .. pkg-section:: flag name
2412 :synopsis: Flag declaration.
2414 Flag section declares a flag which can be used in `conditional blocks`_.
2416 Flag names are case-insensitive and must match ``[[:alnum:]_][[:alnum:]_-]*``
2417 regular expression, or expressed as ABNF_:
2419 .. code-block:: abnf
2421 flag-name = (UALNUM / "_") *(UALNUM / "_" / "-")
2423 UALNUM = UALPHA / DIGIT
2424 UALPHA = ... ; set of alphabetic Unicode code-points
2428 Hackage accepts ASCII-only flags, ``[a-zA-Z0-9_][a-zA-Z0-9_-]*`` regexp.
2430 .. pkg-field:: description: freeform
2432 The description of this flag.
2434 .. pkg-field:: default: boolean
2438 The default value of this flag.
2442 This value may be :ref:`overridden in several
2443 ways <controlling flag assignments>`. The
2444 rationale for having flags default to True is that users usually
2445 want new features as soon as they are available. Flags representing
2446 features that are not (yet) recommended for most users (such as
2447 experimental features or debugging support) should therefore
2448 explicitly override the default to False.
2450 .. pkg-field:: manual: boolean
2455 By default, Cabal will first try to satisfy dependencies with the
2456 default flag value and then, if that is not possible, with the
2457 negated value. However, if the flag is manual, then the default
2458 value (which can be overridden by commandline flags) will be used.
2460 .. _conditional-blocks:
2465 Conditional blocks may appear anywhere inside a component or common
2466 section. They have to follow rather strict formatting rules. Conditional
2467 blocks must always be of the shape
2472 property-descriptions-or-conditionals
2479 property-descriptions-or-conditionals
2481 property-descriptions-or-conditionals
2483 Note that the ``if`` and the condition have to be all on the same line.
2485 Since Cabal 2.2 conditional blocks support ``elif`` construct.
2490 property-descriptions-or-conditionals
2492 property-descriptions-or-conditionals
2494 property-descriptions-or-conditionals
2501 Conditions can be formed using boolean tests and the boolean operators
2502 ``||`` (disjunction / logical "or"), ``&&`` (conjunction / logical
2503 "and"), or ``!`` (negation / logical "not"). The unary ``!`` takes
2504 highest precedence, ``||`` takes lowest. Precedence levels may be
2505 overridden through the use of parentheses. For example,
2506 ``os(darwin) && !arch(i386) || os(freebsd)`` is equivalent to
2507 ``(os(darwin) && !(arch(i386))) || os(freebsd)``.
2509 The following tests are currently supported.
2512 Tests if the current operating system is *name*. The argument is
2513 tested against ``System.Info.os`` on the target system. There is
2514 unfortunately some disagreement between Haskell implementations
2515 about the standard values of ``System.Info.os``. Cabal canonicalises
2516 it so that in particular ``os(windows)`` works on all
2517 implementations. If the canonicalised os names match, this test
2518 evaluates to true, otherwise false. The match is case-insensitive.
2519 :samp:`arch({name})`
2520 Tests if the current architecture is *name*. *name* should be the name of
2521 one of the nullary constructors of ``Distribution.System.Arch`` (e.g.
2522 ``x86_64``, ``aarch64`` or ``i386``), otherwise it will be treated as an
2523 'other architecture' of the given *name*. It will be compared with
2524 ``Distribution.System.buildArch``, which is derived from
2525 ``System.Info.arch`` (certain architectures are treated as synonymous; e.g.
2526 ``aarch64`` / ``arm64`` or ``powerpc64`` / ``powerpc64le`` are not
2527 distinguished). For a match, this test evaluates to true, otherwise false.
2528 The match is case-insensitive.
2529 :samp:`impl({compiler})`
2530 Tests for the configured Haskell implementation. An optional version
2531 constraint may be specified (for example ``impl(ghc >= 6.6.1)``). If
2532 the configured implementation is of the right type and matches the
2533 version constraint, then this evaluates to true, otherwise false.
2534 The match is case-insensitive.
2536 Note that including a version constraint in an ``impl`` test causes
2537 it to check for two properties:
2539 - The current compiler has the specified name, and
2541 - The compiler's version satisfied the specified version constraint
2543 As a result, ``!impl(ghc >= x.y.z)`` is not entirely equivalent to
2544 ``impl(ghc < x.y.z)``. The test ``!impl(ghc >= x.y.z)`` checks that:
2546 - The current compiler is not GHC, or
2548 - The version of GHC is earlier than version x.y.z.
2550 :samp:`flag({name})`
2551 Evaluates to the current assignment of the flag of the given name.
2552 Flag names are case insensitive. Testing for flags that have not
2553 been introduced with a flag section is an error.
2555 Constant value true.
2557 Constant value false.
2559 .. _resolution-of-conditions-and-flags:
2561 Resolution of Conditions and Flags
2562 """"""""""""""""""""""""""""""""""
2564 If a package descriptions specifies configuration flags the package user
2565 can :ref:`control these in several ways <controlling flag assignments>`. If the
2566 user does not fix the value of a flag, Cabal will try to find a flag
2567 assignment in the following way.
2569 - For each flag specified, it will assign its default value, evaluate
2570 all conditions with this flag assignment, and check if all
2571 dependencies can be satisfied. If this check succeeded, the package
2572 will be configured with those flag assignments.
2574 - If dependencies were missing, the last flag (as by the order in which
2575 the flags were introduced in the package description) is tried with
2576 its alternative value and so on. This continues until either an
2577 assignment is found where all dependencies can be satisfied, or all
2578 possible flag assignments have been tried.
2580 To put it another way, Cabal does a complete backtracking search to find
2581 a satisfiable package configuration. It is only the dependencies
2582 specified in the :pkg-field:`build-depends` field in conditional blocks that
2583 determine if a particular flag assignment is satisfiable
2584 (:pkg-field:`build-tools` are not considered). The order of the declaration and
2585 the default value of the flags determines the search order. Flags
2586 overridden on the command line fix the assignment of that flag, so no
2587 backtracking will be tried for that flag.
2589 If no suitable flag assignment could be found, the configuration phase
2590 will fail and a list of missing dependencies will be printed. Note that
2591 this resolution process is exponential in the worst case (i.e., in the
2592 case where dependencies cannot be satisfied). There are some
2593 optimizations applied internally, but the overall complexity remains
2596 Meaning of field values when using conditionals
2597 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2599 During the configuration phase, a flag assignment is chosen, all
2600 conditionals are evaluated, and the package description is combined into
2601 a flat package descriptions. If the same field is declared both inside
2602 a conditional and outside then they are combined using the following rules.
2604 - Boolean fields are combined using conjunction (logical "and").
2606 - List fields are combined by appending the inner items to the outer
2611 other-extensions: CPP
2613 other-extensions: MultiParamTypeClasses
2615 when compiled using GHC will be combined to
2619 other-extensions: CPP, MultiParamTypeClasses
2621 Similarly, if two conditional sections appear at the same nesting
2622 level, properties specified in the latter will come after properties
2623 specified in the former.
2625 - All other fields must not be specified in ambiguous ways. For example
2630 if flag(useothermain)
2631 Main-is: OtherMain.hs
2633 will lead to an error. Instead use
2637 if flag(useothermain)
2638 Main-is: OtherMain.hs
2647 .. pkg-section:: common name
2649 :synopsis: Common build info section
2651 Starting with Cabal-2.2 it's possible to use common build info stanzas.
2656 build-depends: base ^>= 4.11
2660 build-depends: tasty ^>= 0.12.0.1
2664 exposed-modules: Foo
2665 default-language: Haskell2010
2668 import: deps, test-deps
2669 type: exitcode-stdio-1.0
2672 default-language: Haskell2010
2674 - You can use `build information`_ fields in common stanzas.
2676 - Common stanzas must be defined before use.
2678 - Common stanzas can import other common stanzas.
2680 - You can import multiple stanzas at once. Stanza names must be separated by commas.
2682 - ``import`` must be the first field in a section. Since Cabal 3.0 imports
2683 are also allowed inside conditionals.
2687 The name `import` was chosen, because there is ``includes`` field.
2689 .. pkg-section:: None
2691 .. pkg-field:: import: token-list
2696 .. _pkg-author-source:
2698 *Source code* repository marker
2699 -------------------------------
2701 .. pkg-section:: source-repository
2704 A marker that points to the *source code* for this package within a
2705 **source code repository**.
2707 There are two kinds. You can specify one or the other or both at once:
2709 - The ``head`` kind refers to the latest development branch of the
2710 package. This may be used for example to track activity of a project
2711 or as an indication to outside developers what sources to get for
2712 making new contributions.
2714 - The ``this`` kind refers to the branch and tag of a repository that
2715 contains the sources for this version or release of a package. For most
2716 source control systems this involves specifying a tag, id or hash of some
2717 form and perhaps a branch.
2719 As an example, here are the repositories for the Cabal library. Note that the
2720 ``this`` kind of repository specifies a tag.
2724 source-repository head
2726 location: https://github.com/haskell/cabal
2728 source-repository this
2730 location: https://github.com/haskell/cabal
2733 The :ref:`cabal get<cabal-get>` command uses the kind of repository with
2734 its ``--source-repository`` option, if provided.
2736 .. _source-repository-fields:
2738 The :ref:`VCS fields<vcs-fields>` of ``source-repository`` are:
2741 data SourceRepo = SourceRepo
2742 { repoKind :: RepoKind
2743 , repoType :: Maybe RepoType
2744 , repoLocation :: Maybe String
2745 , repoModule :: Maybe String
2746 , repoBranch :: Maybe String
2747 , repoTag :: Maybe String
2748 , repoSubdir :: Maybe FilePath
2751 .. pkg-field:: type: VCS kind
2753 This field is required.
2755 .. pkg-field:: location: VCS location
2757 This field is required.
2759 .. pkg-field:: module: token
2761 CVS requires a named module, as each CVS server can host multiple
2764 This field is required for the CVS repository type and should not be
2767 .. pkg-field:: branch: VCS branch
2769 This field is optional.
2771 .. pkg-field:: tag: VCS tag
2773 This field is required for the ``this`` repository kind.
2775 This might be used to indicate what sources to get if someone needs to fix a
2776 bug in an older branch that is no longer an active head branch.
2778 .. pkg-field:: subdir: VCS subdirectory
2780 This field is optional but, if given, specifies a single subdirectory.
2787 The ``Hooks`` build type allows customising the configuration and the building
2788 of a package using a collection of **hooks** into the build system.
2790 Introduced in Cabal 3.14, this build type provides an alternative
2791 to :ref:`Custom setups <custom-setup>` which integrates better with the rest of the
2794 To use this build type in your package, you need to:
2796 * Declare a ``cabal-version`` of at least 3.14 in your ``.cabal`` file.
2797 * Declare ``build-type: Hooks`` in your ``.cabal`` file.
2798 * Include a ``custom-setup`` stanza in your ``.cabal`` file, which declares
2799 the version of the Hooks API your package is using.
2800 * Define a ``SetupHooks.hs`` module next to your ``.cabal`` file. It must
2801 export a value ``setupHooks :: SetupHooks``.
2803 More specifically, your ``.cabal`` file should resemble the following:
2805 .. code-block:: cabal
2812 base >= 4.18 && < 5,
2813 Cabal-hooks >= 0.1 && < 0.2
2815 while a basic ``SetupHooks.hs`` file might look like the following:
2817 .. code-block:: haskell
2819 module SetupHooks where
2820 import Distribution.Simple.SetupHooks ( SetupHooks, noSetupHooks )
2822 setupHooks :: SetupHooks
2825 { configureHooks = myConfigureHooks
2826 , buildHooks = myBuildHooks }
2830 Refer to the `Hackage documentation for the Distribution.Simple.SetupHooks module <https://hackage.haskell.org/package/Cabal-hooks/docs/Distribution-Simple-SetupHooks.html>`__
2831 for an overview of the ``Hooks`` API. Further motivation and a technical overview
2832 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>`__ .
2836 Custom setup scripts
2837 --------------------
2839 Deprecated since Cabal 3.14: prefer using the :ref:`Hooks build type<setup-hooks>` instead.
2841 Since Cabal 1.24, custom ``Setup.hs`` are required to accurately track
2842 their dependencies by declaring them in the ``.cabal`` file rather than
2843 rely on dependencies being implicitly in scope. Please refer to
2844 `this article <https://www.well-typed.com/blog/2015/07/cabal-setup-deps/>`__
2847 As of Cabal library version 3.0, ``defaultMain*`` variants implement support
2848 for response files. Custom ``Setup.hs`` files that do not use one of these
2849 main functions are required to implement their own support, such as by using
2850 ``GHC.ResponseFile.getArgsWithResponseFiles``.
2852 Declaring a ``custom-setup`` stanza also enables the generation of
2853 ``MIN_VERSION_package_(A,B,C)`` CPP macros for the Setup component.
2855 .. pkg-section:: custom-setup
2856 :synopsis: Build information for ``Custom`` and ``Hooks`` build types
2859 A :pkg-section:`custom-setup` stanza is required for ``Custom`` and ``Hooks``
2860 :pkg-field:`build-type`, and will be ignored (with a warning)
2861 for other build types.
2863 The stanza contains information needed for the compilation
2864 of custom ``Setup.hs`` scripts, and of ``SetupHooks.hs`` hooks.
2871 base >= 4.5 && < 4.11,
2872 Cabal >= 1.14 && < 1.25
2874 .. pkg-field:: setup-depends: package list
2877 The dependencies needed to compile ``Setup.hs`` or ``SetupHooks.hs``. See the
2878 :pkg-field:`build-depends` field for a description of the syntax expected by
2881 If the field is not specified the implicit package set will be used.
2882 The package set contains packages bundled with GHC (i.e. ``base``,
2883 ``bytestring``) and specifically ``Cabal``.
2884 The specific bounds are put on ``Cabal`` dependency:
2885 lower-bound is inferred from :pkg-field:`cabal-version`,
2886 and the upper-bound is ``< 1.25``.
2888 ``Cabal`` version is additionally restricted by GHC,
2889 with absolute minimum being ``1.20``, and for example ``Custom``
2890 builds with GHC-8.10 require at least ``Cabal-3.2``.
2893 Backward compatibility and ``custom-setup``
2894 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2896 Versions prior to Cabal 1.24 don't recognise ``custom-setup`` stanzas,
2897 and will behave agnostic to them (except for warning about an unknown
2898 'section'). Consequently, versions prior to Cabal 1.24 can't ensure the
2899 declared dependencies ``setup-depends`` are in scope, and instead
2900 whatever is registered in the current package database environment
2901 will become eligible (and resolved by the compiler) for the
2902 ``Setup.hs`` module.
2904 The availability of the
2905 ``MIN_VERSION_package_(A,B,C)`` CPP macros
2906 inside ``Setup.hs`` scripts depends on the condition that either
2908 - a ``custom-setup`` stanza has been declared (or ``cabal build`` is being used
2909 which injects an implicit hard-coded ``custom-setup`` stanza if it's missing),
2911 - GHC 8.0 or later is used (which natively injects package version CPP macros)
2913 Consequently, if you need to write backward compatible ``Setup.hs``
2914 scripts using CPP, you should declare a ``custom-setup`` stanza and
2915 use the pattern below:
2917 .. code-block:: haskell
2919 {-# LANGUAGE CPP #-}
2920 import Distribution.Simple
2922 #if defined(MIN_VERSION_Cabal)
2923 -- version macros are available and can be used as usual
2924 # if MIN_VERSION_Cabal(a,b,c)
2925 -- code specific to lib:Cabal >= a.b.c
2927 -- code specific to lib:Cabal < a.b.c
2930 # warning Enabling heuristic fall-back. Please upgrade cabal-install to 1.24 or later if Setup.hs fails to compile.
2932 -- package version macros not available; except for exotic environments,
2933 -- you can heuristically assume that lib:Cabal's version is correlated
2934 -- with __GLASGOW_HASKELL__, and specifically since we can assume that
2935 -- GHC < 8.0, we can assume that lib:Cabal is version 1.22 or older.
2940 The simplified (heuristic) CPP pattern shown below is useful if all you need
2941 is to distinguish ``Cabal < 2.0`` from ``Cabal >= 2.0``.
2943 .. code-block:: haskell
2945 {-# LANGUAGE CPP #-}
2946 import Distribution.Simple
2948 #if !defined(MIN_VERSION_Cabal)
2949 # define MIN_VERSION_Cabal(a,b,c) 0
2952 #if MIN_VERSION_Cabal(2,0,0)
2953 -- code for lib:Cabal >= 2.0
2955 -- code for lib:Cabal < 2.0
2962 Autogenerated modules and includes
2963 ----------------------------------
2965 .. pkg-section:: None
2967 Modules that are built automatically at setup, created with a custom
2968 setup script, must appear on :pkg-field:`other-modules` for the library,
2969 executable, test-suite or benchmark stanzas or also on
2970 :pkg-field:`library:exposed-modules` for libraries to be used, but are not
2971 really on the package when distributed. This makes commands like sdist fail
2972 because the file is not found.
2974 These special modules must appear again on the :pkg-field:`autogen-modules`
2975 field of the stanza that is using them, besides :pkg-field:`other-modules` or
2976 :pkg-field:`library:exposed-modules`. With this there is no need to create
2977 complex build hooks for this poweruser case.
2979 .. pkg-field:: autogen-modules: module list
2982 .. todo:: document autogen-modules field
2984 Right now :pkg-field:`executable:main-is` modules are not supported on
2985 :pkg-field:`autogen-modules`.
2990 default-language: Haskell2010
3001 default-language: Haskell2010
3010 .. pkg-field:: autogen-includes: filename list
3013 A list of header files from this package which are autogenerated
3014 (e.g. by a ``configure`` script). Autogenerated header files are not
3015 packaged by ``sdist`` command.
3018 .. _accessing-data-files:
3020 Accessing data files from package code
3021 --------------------------------------
3023 The placement on the target system of files listed in
3024 the :pkg-field:`data-files` field varies between systems, and in some cases
3025 one can even move packages around after installation
3026 (see :ref:`prefix independence`). To
3027 enable packages to find these files in a portable way, Cabal generates a
3028 module called :file:`Paths_{pkgname}` (with any hyphens in *pkgname*
3029 replaced by underscores) during building, so that it may be imported by
3030 modules of the package. This module defines a function
3032 .. code-block:: haskell
3034 getDataFileName :: FilePath -> IO FilePath
3036 If the argument is a filename listed in the :pkg-field:`data-files` field, the
3037 result is the name of the corresponding file on the system on which the
3042 If you decide to import the :file:`Paths_{pkgname}` module then it
3043 *must* be listed in the :pkg-field:`other-modules` field just like any other
3044 module in your package and on :pkg-field:`autogen-modules` as the file is
3047 The :file:`Paths_{pkgname}` module is not platform independent, as any
3048 other autogenerated module, so it does not get included in the source
3049 tarballs generated by ``sdist``.
3051 The :file:`Paths_{pkgname}` module also includes some other useful
3052 functions and values, which record the version of the package and some
3053 other directories which the package has been configured to be installed
3054 into (e.g. data files live in ``getDataDir``):
3056 .. code-block:: haskell
3060 getBinDir :: IO FilePath
3061 getLibDir :: IO FilePath
3062 getDynLibDir :: IO FilePath
3063 getDataDir :: IO FilePath
3064 getLibexecDir :: IO FilePath
3065 getSysconfDir :: IO FilePath
3067 The actual location of all these directories can be individually
3068 overridden at runtime using environment variables of the form
3069 ``pkg_name_var``, where ``pkg_name`` is the name of the package with all
3070 hyphens converted into underscores, and ``var`` is either ``bindir``,
3071 ``libdir``, ``dynlibdir``, ``datadir``, ``libexedir`` or ``sysconfdir``. For example,
3072 the configured data directory for ``pretty-show`` is controlled with the
3073 ``pretty_show_datadir`` environment variable.
3075 Accessing the package version
3076 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3078 The auto generated :file:`PackageInfo_{pkgname}` module exports the constant
3079 ``version ::`` `Version <http://hackage.haskell.org/package/base/docs/Data-Version.html>`__
3080 which is defined as the version of your package as specified in the
3083 Accessing package-related informations
3084 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3086 The auto generated :file:`PackageInfo_{pkgname}` module exports the following
3087 package-related constants:
3089 .. code-block:: haskell
3097 Unlike :file:`Paths_{pkgname}` (see <#accessing-data-files-from-package-code>),
3098 :file:`PackageInfo_{pkgname}` is system- and path-independent. It aims to be
3099 easier to work with for hash-based tools such as Nix.
3101 .. _system-dependent parameters:
3103 System-dependent parameters
3104 ---------------------------
3106 For some packages, especially those interfacing with C libraries,
3107 implementation details and the build procedure depend on the build
3108 environment. The ``build-type`` ``Configure`` can be used to handle many
3109 such situations. In this case, ``Setup.hs`` should be:
3111 .. code-block:: haskell
3113 import Distribution.Simple
3114 main = defaultMainWithHooks autoconfUserHooks
3116 Most packages, however, would probably do better using the ``Simple``
3117 build type and `configurations`_.
3119 The :pkg-field:`build-type` ``Configure`` differs from ``Simple`` in two ways:
3121 - The package root directory must contain a shell script called
3122 ``configure``. The configure step will run the script. This
3123 ``configure`` script may be produced by
3124 `autoconf <http://www.gnu.org/software/autoconf/>`__ or may be
3125 hand-written. The ``configure`` script typically discovers
3126 information about the system and records it for later steps, e.g. by
3127 generating system-dependent header files for inclusion in C source
3128 files and preprocessed Haskell source files. (Clearly this won't work
3129 for Windows without MSYS or Cygwin: other ideas are needed.)
3131 - If the package root directory contains a file called
3132 *package*\ ``.buildinfo`` after the configuration step, subsequent
3133 steps will read it to obtain additional settings for `build
3134 information`_ fields,to be merged with the ones
3135 given in the ``.cabal`` file. In particular, this file may be
3136 generated by the ``configure`` script mentioned above, allowing these
3137 settings to vary depending on the build environment.
3139 Note that the package's ``extra-source-files`` are available to the
3140 ``configure`` script when it is executed. In typical ``autoconf`` fashion,
3141 ``--host`` flag will be passed to the ``configure`` script to indicate the host
3142 platform when cross-compiling. Moreover, various bits of build configuration
3143 will be passed via environment variables:
3145 - ``CC`` will reflect the path to the C compiler
3146 - ``CFLAGS`` will reflect the path to the C compiler
3147 - ``CABAL_FLAGS`` will contain the Cabal flag assignment of the current
3148 package using traditional Cabal flag syntax (e.g. ``+flagA -flagB``)
3149 - ``CABAL_FLAG_<flag>`` will be set to either ``0`` or ``1`` depending upon
3150 whether flag ``<flag>`` is enabled. Note that any any non-alpha-numeric
3151 characters in the flag name are replaced with ``_``.
3153 The build information file should have the following structure:
3157 ``executable:`` *name* *buildinfo*
3159 ``executable:`` *name* *buildinfo* ...
3161 where each *buildinfo* consists of settings of fields listed in the
3162 section on `build information`_. The first one (if
3163 present) relates to the library, while each of the others relate to the
3164 named executable. (The names must match the package description, but you
3165 don't have to have entries for all of them.)
3167 Neither of these files is required. If they are absent, this setup
3168 script is equivalent to ``defaultMain``.
3170 Example: Using autoconf
3171 ^^^^^^^^^^^^^^^^^^^^^^^
3173 This example is for people familiar with the
3174 `autoconf <http://www.gnu.org/software/autoconf/>`__ tools.
3176 In the X11 package, the file ``configure.ac`` contains:
3178 .. code-block:: shell
3180 AC_INIT([Haskell X11 package], [1.1], [libraries@haskell.org], [X11])
3182 # Safety check: Ensure that we are in the correct source directory.
3183 AC_CONFIG_SRCDIR([X11.cabal])
3185 # Header file to place defines in
3186 AC_CONFIG_HEADERS([include/HsX11Config.h])
3188 # Check for X11 include paths and libraries
3190 AC_TRY_CPP([#include <X11/Xlib.h>],,[no_x=yes])
3192 # Build the package if we found X11 stuff
3193 if test "$no_x" = yes
3194 then BUILD_PACKAGE_BOOL=False
3195 else BUILD_PACKAGE_BOOL=True
3197 AC_SUBST([BUILD_PACKAGE_BOOL])
3199 AC_CONFIG_FILES([X11.buildinfo])
3202 Then the setup script will run the ``configure`` script, which checks
3203 for the presence of the X11 libraries and substitutes for variables in
3204 the file ``X11.buildinfo.in``:
3208 buildable: @BUILD_PACKAGE_BOOL@
3209 cc-options: @X_CFLAGS@
3210 ld-options: @X_LIBS@
3212 This generates a file ``X11.buildinfo`` supplying the parameters needed
3218 cc-options: -I/usr/X11R6/include
3219 ld-options: -L/usr/X11R6/lib
3221 The ``configure`` script also generates a header file
3222 ``include/HsX11Config.h`` containing C preprocessor defines recording
3223 the results of various tests. This file may be included by C source
3224 files and preprocessed Haskell source files in the package.
3228 Packages using these features will also need to list additional
3229 files such as ``configure``, templates for ``.buildinfo`` files, files
3230 named only in ``.buildinfo`` files, header files and so on in the
3231 :pkg-field:`extra-source-files` field to ensure that they are included in
3232 source distributions. They should also list files and directories generated
3233 by ``configure`` in the :pkg-field:`extra-tmp-files` field to ensure that
3234 they are removed by ``setup clean``.
3236 Quite often the files generated by ``configure`` need to be listed
3237 somewhere in the package description (for example, in the
3238 :pkg-field:`install-includes` field). However, we usually don't want generated
3239 files to be included in the source tarball. The solution is again
3240 provided by the ``.buildinfo`` file. In the above example, the following
3241 line should be added to ``X11.buildinfo``:
3245 install-includes: HsX11Config.h
3247 In this way, the generated ``HsX11Config.h`` file won't be included in
3248 the source tarball in addition to ``HsX11Config.h.in``, but it will be
3249 copied to the right location during the install process. Packages that
3250 use custom ``Setup.hs`` scripts can update the necessary fields
3251 programmatically instead of using the ``.buildinfo`` file.
3253 Conditional compilation
3254 -----------------------
3256 Sometimes you want to write code that works with more than one version
3257 of a dependency. You can specify a range of versions for the dependency
3258 in the :pkg-field:`build-depends`, but how do you then write the code that can
3259 use different versions of the API?
3261 Haskell lets you preprocess your code using the C preprocessor (either
3262 the real C preprocessor, or ``cpphs``). To enable this, add
3263 ``extensions: CPP`` to your package description. When using CPP, Cabal
3264 provides some pre-defined macros to let you test the version of
3265 dependent packages; for example, suppose your package works with either
3266 version 3 or version 4 of the ``base`` package, you could select the
3267 available version in your Haskell modules like this:
3271 #if MIN_VERSION_base(4,0,0)
3272 ... code that works with base-4 ...
3274 ... code that works with base-3 ...
3277 In general, Cabal supplies a macro
3278 ``MIN_VERSION_``\ *``package``*\ ``_(A,B,C)`` for each package depended
3279 on via :pkg-field:`build-depends`. This macro is true if the actual version of
3280 the package in use is greater than or equal to ``A.B.C`` (using the
3281 conventional ordering on version numbers, which is lexicographic on the
3282 sequence, but numeric on each component, so for example 1.2.0 is greater
3285 Since version 1.20, the ``MIN_TOOL_VERSION_``\ *``tool``*
3286 family of macros lets you condition on the version of build tools used to
3287 build the program (e.g. ``hsc2hs``).
3289 Since version 1.24, the macro ``CURRENT_COMPONENT_ID``, which
3290 expands to the string of the component identifier that uniquely
3291 identifies this component. Furthermore, if the package is a library,
3292 the macro ``CURRENT_PACKAGE_KEY`` records the identifier that was passed
3293 to GHC for use in symbols and for type equality.
3295 Since version 2.0, the macro ``CURRENT_PACKAGE_VERSION`` expands
3296 to the string version number of the current package.
3298 Cabal places the definitions of these macros into an
3299 automatically-generated header file, which is included when
3300 preprocessing Haskell source code by passing options to the C
3303 Cabal also allows to detect when the source code is being used for
3304 generating documentation. The ``__HADDOCK_VERSION__`` macro is defined
3305 only when compiling via Haddock_
3306 instead of a normal Haskell compiler. The value of the
3307 ``__HADDOCK_VERSION__`` macro is defined as ``A*1000 + B*10 + C``, where
3308 ``A.B.C`` is the Haddock version. This can be useful for working around
3309 bugs in Haddock or generating prettier documentation in some special
3312 .. _more-complex-packages:
3314 More complex packages
3315 ---------------------
3317 For packages that don't fit the simple schemes described above, you have
3320 - By using the :pkg-field:`build-type` ``Custom``, you can supply your own
3321 ``Setup.hs`` file, and customize the simple build infrastructure
3322 using *hooks*. These allow you to perform additional actions before
3323 and after each command is run, and also to specify additional
3324 preprocessors. A typical ``Setup.hs`` may look like this:
3326 .. code-block:: haskell
3328 import Distribution.Simple
3329 main = defaultMainWithHooks simpleUserHooks { postHaddock = posthaddock }
3331 posthaddock args flags desc info = ....
3333 See ``UserHooks`` in
3334 `Distribution.Simple <https://hackage.haskell.org/package/Cabal/docs/Distribution-Simple.html>`__
3335 for the details, but note that this interface is experimental, and
3336 likely to change in future releases.
3338 If you use a custom ``Setup.hs`` file you should strongly consider
3339 adding a :pkg-section:`custom-setup` stanza with a
3340 :pkg-field:`custom-setup:setup-depends` field to ensure that your setup
3341 script does not break with future dependency versions.
3343 - You could delegate all the work to ``make``, though this is unlikely
3344 to be very portable. Cabal supports this with the :pkg-field:`build-type`
3345 ``Make`` and a trivial setup library
3346 `Distribution.Make <https://hackage.haskell.org/package/Cabal/docs/Distribution-Make.html>`__,
3347 which simply parses the command line arguments and invokes ``make``.
3348 Here ``Setup.hs`` should look like this:
3350 .. code-block:: haskell
3352 import Distribution.Make
3355 The root directory of the package should contain a ``configure``
3356 script, and, after that has run, a ``Makefile`` with a default target
3357 that builds the package, plus targets ``install``, ``register``,
3358 ``unregister``, ``clean``, ``dist`` and ``docs``. Some options to
3359 commands are passed through as follows:
3361 - The ``--with-hc-pkg``, ``--prefix``, ``--bindir``, ``--libdir``,
3362 ``--dynlibdir``, ``--datadir``, ``--libexecdir`` and ``--sysconfdir`` options to
3363 the ``configure`` command are passed on to the ``configure``
3364 script. In addition the value of the ``--with-compiler`` option is
3365 passed in a ``--with-hc`` option and all options specified with
3366 ``--configure-option=`` are passed on.
3368 - The ``--destdir`` option to the ``copy`` command becomes a setting
3369 of a ``destdir`` variable on the invocation of ``make copy``. The
3370 supplied ``Makefile`` should provide a ``copy`` target, which will
3371 probably look like this:
3373 .. code-block:: make
3376 $(MAKE) install prefix=$(destdir)/$(prefix) \
3377 bindir=$(destdir)/$(bindir) \
3378 libdir=$(destdir)/$(libdir) \
3379 dynlibdir=$(destdir)/$(dynlibdir) \
3380 datadir=$(destdir)/$(datadir) \
3381 libexecdir=$(destdir)/$(libexecdir) \
3382 sysconfdir=$(destdir)/$(sysconfdir) \
3384 - Finally, with the :pkg-field:`build-type` ``Custom``, you can also write your
3385 own setup script from scratch, and you may use the Cabal
3386 library for all or part of the work. One option is to copy the source
3387 of ``Distribution.Simple``, and alter it for your needs. Good luck.
3389 .. include:: references.inc
3391 .. rubric:: Footnotes
3393 .. [#old-style-build-tool-depends]
3395 Some packages (ab)use :pkg-field:`build-depends` on old-style builds, but this has a few major drawbacks:
3397 - 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.
3398 - it may or may not place the executable on ``PATH``.
3399 - it does not ensure the correct version of the package is installed, so you might end up overwriting versions with each other.