developing-packages.rst 136 KB
Newer Older
1 2 3 4 5 6 7 8
Quickstart
==========

Lets assume we have created a project directory and already have a
Haskell module or two.

Every project needs a name, we'll call this example "proglet".

9 10
.. highlight:: console

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
::

    $ cd proglet/
    $ ls
    Proglet.hs

It is assumed that (apart from external dependencies) all the files that
make up a package live under a common project root directory. This
simple example has all the project files in one directory, but most
packages will use one or more subdirectories.

To turn this into a Cabal package we need two extra files in the
project's root directory:

-  ``proglet.cabal``: containing package metadata and build information.

-  ``Setup.hs``: usually containing a few standardized lines of code,
   but can be customized if necessary.

We can create both files manually or we can use ``cabal init`` to create
them for us.

Using "cabal init"
34
------------------
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

The ``cabal init`` command is interactive. It asks us a number of
questions starting with the package name and version.

::

    $ cabal init
    Package name [default "proglet"]?
    Package version [default "0.1"]?
    ...

It also asks questions about various other bits of package metadata. For
a package that you never intend to distribute to others, these fields
can be left blank.

One of the important questions is whether the package contains a library
or an executable. Libraries are collections of Haskell modules that can
be re-used by other Haskell libraries and programs, while executables
are standalone programs.

::

    What does the package build:
       1) Library
       2) Executable
    Your choice?

For the moment these are the only choices. For more complex packages
(e.g. a library and multiple executables or test suites) the ``.cabal``
file can be edited afterwards.

Finally, ``cabal init`` creates the initial ``proglet.cabal`` and
``Setup.hs`` files, and depending on your choice of license, a
``LICENSE`` file as well.

::

    Generating LICENSE...
    Generating Setup.hs...
    Generating proglet.cabal...

    You may want to edit the .cabal file and add a Description field.

As this stage the ``proglet.cabal`` is not quite complete and before you
are able to build the package you will need to edit the file and add
some build information about the library or executable.

Editing the .cabal file
83
-----------------------
84

85 86
.. highlight:: cabal

87 88
Load up the ``.cabal`` file in a text editor. The first part of the
``.cabal`` file has the package metadata and towards the end of the file
89
you will find the :pkg-section:`executable` or :pkg-section:`library` section.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

You will see that the fields that have yet to be filled in are commented
out. Cabal files use "``--``" Haskell-style comment syntax. (Note that
comments are only allowed on lines on their own. Trailing comments on
other lines are not allowed because they could be confused with program
options.)

If you selected earlier to create a library package then your ``.cabal``
file will have a section that looks like this:

::

    library
      exposed-modules:     Proglet
      -- other-modules:
      -- build-depends:

Alternatively, if you selected an executable then there will be a
section like:

::

    executable proglet
      -- main-is:
      -- other-modules:
      -- build-depends:

The build information fields listed (but commented out) are just the few
most important and common fields. There are many others that are covered
later in this chapter.

Most of the build information fields are the same between libraries and
executables. The difference is that libraries have a number of "exposed"
modules that make up the public interface of the library, while
executables have a file containing a ``Main`` module.

The name of a library always matches the name of the package, so it is
not specified in the library section. Executables often follow the name
of the package too, but this is not required and the name is given
explicitly.

Modules included in the package
132
-------------------------------
133 134 135

For a library, ``cabal init`` looks in the project directory for files
that look like Haskell modules and adds all the modules to the
136 137 138 139
:pkg-field:`library:exposed-modules` field. For modules that do not form part
of your package's public interface, you can move those modules to the
:pkg-field:`other-modules` field. Either way, all modules in the library need
to be listed.
140 141 142

For an executable, ``cabal init`` does not try to guess which file
contains your program's ``Main`` module. You will need to fill in the
143 144 145 146
:pkg-field:`executable:main-is` field with the file name of your program's
``Main`` module (including ``.hs`` or ``.lhs`` extension). Other modules
included in the executable should be listed in the :pkg-field:`other-modules`
field.
147 148

Modules imported from other packages
149
------------------------------------
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179

While your library or executable may include a number of modules, it
almost certainly also imports a number of external modules from the
standard libraries or other pre-packaged libraries. (These other
libraries are of course just Cabal packages that contain a library.)

You have to list all of the library packages that your library or
executable imports modules from. Or to put it another way: you have to
list all the other packages that your package depends on.

For example, suppose the example ``Proglet`` module imports the module
``Data.Map``. The ``Data.Map`` module comes from the ``containers``
package, so we must list it:

::

    library
      exposed-modules:     Proglet
      other-modules:
      build-depends:       containers, base == 4.*

In addition, almost every package also depends on the ``base`` library
package because it exports the standard ``Prelude`` module plus other
basic modules like ``Data.List``.

You will notice that we have listed ``base == 4.*``. This gives a
constraint on the version of the base package that our package will work
with. The most common kinds of constraints are:

-  ``pkgname >= n``
180
-  ``pkgname ^>= n`` (since Cabal 2.0)
181
-  ``pkgname >= n && < m``
182
-  ``pkgname == n.*`` (since Cabal 1.6)
183 184

The last is just shorthand, for example ``base == 4.*`` means exactly
185 186
the same thing as ``base >= 4 && < 5``. Please refer to the documentation
on the :pkg-field:`build-depends` field for more information.
187 188

Building the package
189
--------------------
190 191 192 193

For simple packages that's it! We can now try configuring and building
the package:

194
.. code-block:: console
195

196 197
    $ cabal configure
    $ cabal build
198 199 200

Assuming those two steps worked then you can also install the package:

201
.. code-block:: console
202

203
    $ cabal install
204 205 206 207 208 209

For libraries this makes them available for use in GHCi or to be used by
other packages. For executables it installs the program so that you can
run it (though you may first need to adjust your system's ``$PATH``).

Next steps
210
----------
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228

What we have covered so far should be enough for very simple packages
that you use on your own system.

The next few sections cover more details needed for more complex
packages and details needed for distributing packages to other people.

The previous chapter covers building and installing packages -- your own
packages or ones developed by other people.

Package concepts
================

Before diving into the details of writing packages it helps to
understand a bit about packages in the Haskell world and the particular
approach that Cabal takes.

The point of packages
229
---------------------
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260

Packages are a mechanism for organising and distributing code. Packages
are particularly suited for "programming in the large", that is building
big systems by using and re-using code written by different people at
different times.

People organise code into packages based on functionality and
dependencies. Social factors are also important: most packages have a
single author, or a relatively small team of authors.

Packages are also used for distribution: the idea is that a package can
be created in one place and be moved to a different computer and be
usable in that different environment. There are a surprising number of
details that have to be got right for this to work, and a good package
system helps to simply this process and make it reliable.

Packages come in two main flavours: libraries of reusable code, and
complete programs. Libraries present a code interface, an API, while
programs can be run directly. In the Haskell world, library packages
expose a set of Haskell modules as their public interface. Cabal
packages can contain a library or executables or both.

Some programming languages have packages as a builtin language concept.
For example in Java, a package provides a local namespace for types and
other definitions. In the Haskell world, packages are not a part of the
language itself. Haskell programs consist of a number of modules, and
packages just provide a way to partition the modules into sets of
related functionality. Thus the choice of module names in Haskell is
still important, even when using packages.

Package names and versions
261
--------------------------
262 263 264 265 266 267 268 269 270 271 272 273 274

All packages have a name, e.g. "HUnit". Package names are assumed to be
unique. Cabal package names may contain letters, numbers and hyphens,
but not spaces and may also not contain a hyphened section consisting of
only numbers. The namespace for Cabal packages is flat, not
hierarchical.

Packages also have a version, e.g "1.1". This matches the typical way in
which packages are developed. Strictly speaking, each version of a
package is independent, but usually they are very similar. Cabal package
versions follow the conventional numeric style, consisting of a sequence
of digits such as "1.0.1" or "2.0". There are a range of common
conventions for "versioning" packages, that is giving some meaning to
275 276 277 278
the version number in terms of changes in the package, such as
e.g. `SemVer <http://semver.org>`__; however, for packages intended to be
distributed via Hackage Haskell's `Package Versioning Policy`_ applies
(see also the `PVP/SemVer FAQ section <https://pvp.haskell.org/faq/#semver>`__).
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294

The combination of package name and version is called the *package ID*
and is written with a hyphen to separate the name and version, e.g.
"HUnit-1.1".

For Cabal packages, the combination of the package name and version
*uniquely* identifies each package. Or to put it another way: two
packages with the same name and version are considered to *be* the same.

Strictly speaking, the package ID only identifies each Cabal *source*
package; the same Cabal source package can be configured and built in
different ways. There is a separate installed package ID that uniquely
identifies each installed package instance. Most of the time however,
users need not be aware of this detail.

Kinds of package: Cabal vs GHC vs system
295
----------------------------------------
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339

It can be slightly confusing at first because there are various
different notions of package floating around. Fortunately the details
are not very complicated.

Cabal packages
    Cabal packages are really source packages. That is they contain
    Haskell (and sometimes C) source code.

    Cabal packages can be compiled to produce GHC packages. They can
    also be translated into operating system packages.

GHC packages
    This is GHC's view on packages. GHC only cares about library
    packages, not executables. Library packages have to be registered
    with GHC for them to be available in GHCi or to be used when
    compiling other programs or packages.

    The low-level tool ``ghc-pkg`` is used to register GHC packages and
    to get information on what packages are currently registered.

    You never need to make GHC packages manually. When you build and
    install a Cabal package containing a library then it gets registered
    with GHC automatically.

    Haskell implementations other than GHC have essentially the same
    concept of registered packages. For the most part, Cabal hides the
    slight differences.

Operating system packages
    On operating systems like Linux and Mac OS X, the system has a
    specific notion of a package and there are tools for installing and
    managing packages.

    The Cabal package format is designed to allow Cabal packages to be
    translated, mostly-automatically, into operating system packages.
    They are usually translated 1:1, that is a single Cabal package
    becomes a single system package.

    It is also possible to make Windows installers from Cabal packages,
    though this is typically done for a program together with all of its
    library dependencies, rather than packaging each library separately.

Unit of distribution
340
--------------------
341 342 343 344 345 346 347

The Cabal package is the unit of distribution. What this means is that
each Cabal package can be distributed on its own in source or binary
form. Of course there may dependencies between packages, but there is
usually a degree of flexibility in which versions of packages can work
together so distributing them independently makes sense.

348
It is perhaps easiest to see what being "the unit of distribution"
349 350 351 352 353 354 355 356 357 358 359 360 361
means by contrast to an alternative approach. Many projects are made up
of several interdependent packages and during development these might
all be kept under one common directory tree and be built and tested
together. When it comes to distribution however, rather than
distributing them all together in a single tarball, it is required that
they each be distributed independently in their own tarballs.

Cabal's approach is to say that if you can specify a dependency on a
package then that package should be able to be distributed
independently. Or to put it the other way round, if you want to
distribute it as a single unit, then it should be a single package.

Explicit dependencies and automatic package management
362
------------------------------------------------------
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411

Cabal takes the approach that all packages dependencies are specified
explicitly and specified in a declarative way. The point is to enable
automatic package management. This means tools like ``cabal`` can
resolve dependencies and install a package plus all of its dependencies
automatically. Alternatively, it is possible to mechanically (or mostly
mechanically) translate Cabal packages into system packages and let the
system package manager install dependencies automatically.

It is important to track dependencies accurately so that packages can
reliably be moved from one system to another system and still be able to
build it there. Cabal is therefore relatively strict about specifying
dependencies. For example Cabal's default build system will not even let
code build if it tries to import a module from a package that isn't
listed in the ``.cabal`` file, even if that package is actually
installed. This helps to ensure that there are no "untracked
dependencies" that could cause the code to fail to build on some other
system.

The explicit dependency approach is in contrast to the traditional
"./configure" approach where instead of specifying dependencies
declaratively, the ``./configure`` script checks if the dependencies are
present on the system. Some manual work is required to transform a
``./configure`` based package into a Linux distribution package (or
similar). This conversion work is usually done by people other than the
package author(s). The practical effect of this is that only the most
popular packages will benefit from automatic package management.
Instead, Cabal forces the original author to specify the dependencies
but the advantage is that every package can benefit from automatic
package management.

The "./configure" approach tends to encourage packages that adapt
themselves to the environment in which they are built, for example by
disabling optional features so that they can continue to work when a
particular dependency is not available. This approach makes sense in a
world where installing additional dependencies is a tiresome manual
process and so minimising dependencies is important. The automatic
package management view is that packages should just declare what they
need and the package manager will take responsibility for ensuring that
all the dependencies are installed.

Sometimes of course optional features and optional dependencies do make
sense. Cabal packages can have optional features and varying
dependencies. These conditional dependencies are still specified in a
declarative way however and remain compatible with automatic package
management. The need to remain compatible with automatic package
management means that Cabal's conditional dependencies system is a bit
less flexible than with the "./configure" approach.

412 413 414 415 416 417 418 419 420
.. note::
   `GNU autoconf places restrictions on paths, including the
   path that the user builds a package from.
   <https://www.gnu.org/software/autoconf/manual/autoconf.html#File-System-Conventions>`_
   Package authors using ``build-type: configure`` should be aware of
   these restrictions; because users may be unexpectedly constrained and
   face mysterious errors, it is recommended that ``build-type: configure``
   is only used where strictly necessary.

421
Portability
422
-----------
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495

One of the purposes of Cabal is to make it easier to build packages on
different platforms (operating systems and CPU architectures), with
different compiler versions and indeed even with different Haskell
implementations. (Yes, there are Haskell implementations other than
GHC!)

Cabal provides abstractions of features present in different Haskell
implementations and wherever possible it is best to take advantage of
these to increase portability. Where necessary however it is possible to
use specific features of specific implementations.

For example a package author can list in the package's ``.cabal`` what
language extensions the code uses. This allows Cabal to figure out if
the language extension is supported by the Haskell implementation that
the user picks. Additionally, certain language extensions such as
Template Haskell require special handling from the build system and by
listing the extension it provides the build system with enough
information to do the right thing.

Another similar example is linking with foreign libraries. Rather than
specifying GHC flags directly, the package author can list the libraries
that are needed and the build system will take care of using the right
flags for the compiler. Additionally this makes it easier for tools to
discover what system C libraries a package needs, which is useful for
tracking dependencies on system libraries (e.g. when translating into
Linux distribution packages).

In fact both of these examples fall into the category of explicitly
specifying dependencies. Not all dependencies are other Cabal packages.
Foreign libraries are clearly another kind of dependency. It's also
possible to think of language extensions as dependencies: the package
depends on a Haskell implementation that supports all those extensions.

Where compiler-specific options are needed however, there is an "escape
hatch" available. The developer can specify implementation-specific
options and more generally there is a configuration mechanism to
customise many aspects of how a package is built depending on the
Haskell implementation, the operating system, computer architecture and
user-specified configuration flags.

Developing packages
===================

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

-  One or more Haskell programs.

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

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

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

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

496 497 498 499 500 501 502
.. Note::

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

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

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

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

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

Once you have these, you can create a source bundle of this directory
for distribution. Building of the package is discussed in the section on
527
:ref:`installing-packages`.
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552

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

::

    name:     Foo
    version:  1.0

    library
553
      build-depends:   base >= 4 && < 5
554 555 556 557
      exposed-modules: Foo
      extensions:      ForeignFunctionInterface
      ghc-options:     -Wall
      if os(windows)
558
        build-depends: Win32 >= 2.1 && < 2.6
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574

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

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

::

    name:           HUnit
    version:        1.1.1
    synopsis:       A unit testing framework for Haskell
    homepage:       http://hunit.sourceforge.net/
    category:       Testing
    author:         Dean Herington
    license:        BSD3
    license-file:   LICENSE
575
    cabal-version:  1.12
576 577 578 579 580 581 582 583 584 585
    build-type:     Simple

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

and the following ``Setup.hs``:

586
.. code-block:: haskell
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601

    import Distribution.Simple
    main = defaultMain

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

::

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

    executable program1
605
      build-depends:  HUnit >= 1.1.1 && < 1.2
606 607 608 609 610
      main-is:        Main.hs
      hs-source-dirs: prog1

    executable program2
      main-is:        Main.hs
611
      build-depends:  HUnit >= 1.1.1 && < 1.2
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
      hs-source-dirs: prog2
      other-modules:  Utils

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

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

::

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

    library
631
      build-depends:   HUnit >= 1.1.1 && < 1.2
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
      exposed-modules: A, B, C

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

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

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

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

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

659 660
.. _pkg-desc:

661 662 663 664 665 666 667
Package descriptions
--------------------

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

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

This file should contain of a number global property descriptions and
several sections.

677
-  The `package properties`_ describe the package
678 679 680 681
   as a whole, such as name, license, author, etc.

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

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

687 688
-  Following is an arbitrary number of executable sections which describe
   an executable program and relevant `build information`_.
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720

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

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

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

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

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

-  To get a blank line in a field value, use an indented "``.``"

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

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

Modules and preprocessors
726
^^^^^^^^^^^^^^^^^^^^^^^^^
727

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

734 735 736 737 738 739
-  ``.gc`` (:hackage-pkg:`greencard`)
-  ``.chs`` (:hackage-pkg:`c2hs`)
-  ``.hsc`` (:hackage-pkg:`hsc2hs`)
-  ``.y`` and ``.ly`` (happy_)
-  ``.x`` (alex_)
-  ``.cpphs`` (cpphs_)
740 741 742 743 744 745

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

Some fields take lists of values, which are optionally separated by
750
commas, except for the :pkg-field:`build-depends` field, where the commas are
751 752 753 754 755 756
mandatory.

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

Package properties
757
^^^^^^^^^^^^^^^^^^
758 759 760 761

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

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

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

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

770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
    Package names are case-sensitive and must match the regular expression
    (i.e. alphanumeric "words" separated by dashes; each alphanumeric
    word must contain at least one letter):
    ``[[:digit:]]*[[:alpha:]][[:alnum:]]*(-[[:digit:]]*[[:alpha:]][[:alnum:]]*)*``.

    Or, expressed in ABNF_:

    .. code-block:: abnf

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

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

    .. note::

        Hackage restricts package names to the ASCII subset.

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

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

    .. code-block:: abnf

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

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

801 802 803
    The version of the Cabal specification that this package
    description uses. The Cabal specification does slowly evolve (see
    also :ref:`spec-history`), introducing new features and
804
    occasionally changing the meaning of existing features. By
805 806 807
    specifying which version of the specification you are using it
    enables programs which process the package description to know
    what syntax to expect and what each part means.
808 809

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

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

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

833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
    Starting with ``cabal-version: 2.2`` this field is only valid if
    fully contained in the very first line of a package description
    and ought to adhere to the ABNF_ grammar

    .. code-block:: abnf

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

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

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


    .. note::

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

        .. code-block:: cabal

            cabal-version: >= 1.10

        needs to be used.

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



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

869
    :default: ``Custom`` or ``Simple``
870

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

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

     - For lower :pkg-field:`cabal-version` values, the default is
       ``Custom`` unconditionally.
883 884 885 886 887 888 889 890 891 892

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

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

893
    .. code-block:: haskell
894 895 896 897 898

        import Distribution.Simple
        main = defaultMain

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

902
    .. code-block:: haskell
903 904 905 906

        import Distribution.Simple
        main = defaultMainWithHooks autoconfUserHooks

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

910
    .. code-block:: haskell
911 912 913 914 915 916 917 918 919

        import Distribution.Make
        main = defaultMain

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

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

920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991
.. pkg-field:: license: SPDX expression

    :default: ``NONE``

    The type of license under which this package is distributed.

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

    .. code-block:: cabal

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

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

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

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

    **Pre-SPDX Legacy Identifiers**

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

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


.. pkg-field:: license-file: filename
995 996 997

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

998
.. pkg-field:: license-files: filename list
999
    :since: 1.20
1000

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

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

.. pkg-field:: copyright: freeform
1009 1010 1011

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

      copyright: (c) 2006-2007 Joe Bloggs

.. pkg-field:: author: freeform

1018 1019 1020 1021 1022
    The original author of the package.

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

1023 1024
.. pkg-field:: maintainer: address

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

.. pkg-field:: stability: freeform

1031 1032
    The stability level of the package, e.g. ``alpha``,
    ``experimental``, ``provisional``, ``stable``.
1033 1034 1035

.. pkg-field:: homepage: URL

1036
    The package homepage.
1037 1038 1039

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

1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
    The URL where users should direct bug reports. This would normally
    be either:

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

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

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

    ::

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

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

1056 1057
    The location of a source bundle for the package. The distribution
    should be a Cabal package.
1058 1059 1060

.. pkg-field:: synopsis: freeform

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

.. pkg-field:: description: freeform

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

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

.. pkg-field:: category: freeform
1077 1078

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

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

1085 1086
    A list of compilers and versions against which the package has been
    tested (or at least built).
1087 1088 1089

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

1090 1091 1092
    A list of files to be installed for run-time use by the package.
    This is useful for packages that use a large amount of static data,
    such as tables of values or code templates. Cabal provides a way to
Mikhail Glushenkov's avatar
Mikhail Glushenkov committed
1093
    `find these files at run-time <#accessing-data-files-from-package-code>`_.
1094 1095 1096

    A limited form of ``*`` wildcards in file names, for example
    ``data-files: images/*.png`` matches all the ``.png`` files in the
1097 1098 1099 1100 1101 1102 1103 1104 1105
    ``images`` directory. ``data-files: audio/**/*.mp3`` matches all
    the ``.mp3`` files in the ``audio`` directory, including
    subdirectories.

    The specific limitations of this wildcard syntax are

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

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

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

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

    - A wildcard that does not match any files is an error.
1126 1127 1128 1129 1130 1131

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

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

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

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

1143 1144 1145
    The directory where Cabal looks for data files to install, relative
    to the source directory. By default, Cabal will look in the source
    directory itself.
1146 1147 1148

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

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

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

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

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

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

1168
Library
1169
^^^^^^^
1170

1171
.. pkg-section:: library name
1172 1173
    :synopsis: Library build information.

1174 1175 1176
    Build information for libraries.

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

    Starting with Cabal 2.0, private internal sub-library components
    can be defined by using setting the ``name`` field to a name
    different from the current package's name; see section on
    :ref:`Internal Libraries <sublibs>` for more information.
Leonid Onokhov's avatar
Leonid Onokhov committed
1185

1186 1187
The library section should contain the following fields:

1188 1189 1190 1191
.. pkg-field:: exposed-modules: identifier list

    :required: if this package contains a library

1192
    A list of modules added by this package.
1193

Moritz Angermann's avatar
Moritz Angermann committed
1194
.. pkg-field:: virtual-modules: identifier list
1195
    :since: 2.2
Moritz Angermann's avatar
Moritz Angermann committed
1196 1197 1198 1199 1200 1201 1202 1203

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

1204 1205 1206 1207
.. pkg-field:: exposed: boolean

    :default: ``True``

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

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

Oleg Grenrus's avatar
Oleg Grenrus committed
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
.. pkg-field:: visibility: visibilty specifiers

    :since 3.0

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

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

    Multiple public libraries...

1231
.. pkg-field:: reexported-modules: exportlist
1232
    :since: 1.22
1233

1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
    Supported only in GHC 7.10 and later. A list of modules to
    *reexport* from this package. The syntax of this field is
    ``orig-pkg:Name as NewName`` to reexport module ``Name`` from
    ``orig-pkg`` with the new name ``NewName``. We also support
    abbreviated versions of the syntax: if you omit ``as NewName``,
    we'll reexport without renaming; if you omit ``orig-pkg``, then we
    will automatically figure out which package to reexport from, if
    it's unambiguous.

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

1250 1251 1252 1253 1254
.. pkg-field:: signatures: signature list
    :since: 2.0

    Supported only in GHC 8.2 and later. A list of `module signatures <https://downloads.haskell.org/~ghc/master/users-guide/separate_compilation.html#module-signatures>`__ required by this package.

1255
    Module signatures are part of the Backpack_ extension to
1256 1257 1258 1259 1260 1261 1262
    the Haskell module system.

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

1263

1264

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

1268 1269 1270 1271
.. _sublibs:

**Internal Libraries**

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

::

1282
    cabal-version:  2.0
1283
    name:           foo
1284
    version:        0.1.0.0
1285 1286 1287 1288 1289
    license:        BSD3
    build-type:     Simple

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

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

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

Internal libraries are also useful for packages that define multiple
executables, but do not define a publically accessible library. Internal
libraries are only visible internally in the package (so they can only
1308
be added to the :pkg-field:`build-depends` of same-package libraries,
1309
executables, test suites, etc.) Internal libraries locally shadow any
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
packages which have the same name; consequently, don't name an internal
library with the same name as an external dependency if you need to be
able to refer to the external dependency in a
:pkg-field:`build-depends` declaration.

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

::

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

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

      hs-source-dirs:       src

      -- internal sub-lib
      build-depends:        attoparsec

      exposed-modules:
        Documentation.Haddock

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

      hs-source-dirs:       vendor/attoparsec-0.13.1.0

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

      other-modules:
        Data.Attoparsec.Internal

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

1359 1360 1361 1362 1363 1364 1365 1366

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

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

1367
.. code-block:: console
1368

1369
    $ cabal repl
1370 1371 1372 1373 1374 1375 1376 1377 1378

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

1379
.. code-block:: console
1380

1381 1382 1383 1384
    $ cabal repl foo
    $ cabal repl exe:foo
    $ cabal repl test:bar
    $ cabal repl bench:baz
1385 1386

Freezing dependency versions
1387
""""""""""""""""""""""""""""
1388 1389 1390 1391 1392 1393 1394

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

1395
.. code-block:: console
1396

1397
    $ cabal freeze
1398 1399 1400 1401 1402 1403

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

Generating dependency version bounds
1404
""""""""""""""""""""""""""""""""""""
1405 1406

Cabal also has the ability to suggest dependency version bounds that
1407
conform to `Package Versioning Policy`_, which is
1408 1409 1410
a recommended versioning system for publicly released Cabal