developing-packages.rst 90.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
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".

::

    $ 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"
32
------------------
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

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
81
-----------------------
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

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
you will find the ``executable`` or ``library`` section.

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
128
-------------------------------
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

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

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
``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 ``other-modules`` field.

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

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``
-  ``pkgname >= n && < m``
-  ``pkgname == n.*``

The last is just shorthand, for example ``base == 4.*`` means exactly
the same thing as ``base >= 4 && < 5``.

Building the package
182
--------------------
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202

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

::

    cabal configure
    cabal build

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

::

    cabal install

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
203
----------
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221

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
222
---------------------
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253

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
254
--------------------------
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285

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
the version number in terms of changes in the package. Section [TODO]
has some tips on package versioning.

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
286
----------------------------------------
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330

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
331
--------------------
332 333 334 335 336 337 338

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.

339
It is perhaps easiest to see what being "the unit of distribution"
340 341 342 343 344 345 346 347 348 349 350 351 352
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
353
------------------------------------------------------
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403

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.

Portability
404
-----------
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706

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

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

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

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

*package*\ ``.cabal``
    a Unicode UTF-8 text file containing a package description. For
    details of the syntax of this file, see the `section on package
    descriptions <#package-descriptions>`__.

``Setup.hs``
    a single-module Haskell program to perform various setup tasks (with
    the interface described in the section on `building and installing
    packages <installing-packages.html>`__. 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 ``build-type`` setting in the ``.cabal`` file. In
    most cases it will be trivial, calling on the Cabal library to do
    most of the work.

Once you have these, you can create a source bundle of this directory
for distribution. Building of the package is discussed in the section on
`building and installing packages <installing-packages.html>`__.

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

::

    name:     Foo
    version:  1.0

    library
      build-depends:   base
      exposed-modules: Foo
      extensions:      ForeignFunctionInterface
      ghc-options:     -Wall
      if os(windows)
        build-depends: Win32

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

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

::

    name:           HUnit
    version:        1.1.1
    synopsis:       A unit testing framework for Haskell
    homepage:       http://hunit.sourceforge.net/
    category:       Testing
    author:         Dean Herington
    license:        BSD3
    license-file:   LICENSE
    cabal-version:  >= 1.10
    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``:

::

    import Distribution.Simple
    main = defaultMain

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

::

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

    executable program1
      build-depends:  HUnit
      main-is:        Main.hs
      hs-source-dirs: prog1

    executable program2
      main-is:        Main.hs
      build-depends:  HUnit
      hs-source-dirs: prog2
      other-modules:  Utils

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

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

::

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

    library
      build-depends:   HUnit
      exposed-modules: A, B, C

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

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

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

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

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

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

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

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.

-  The `global properties <#package-properties>`__ describe the package
   as a whole, such as name, license, author, etc.

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

-  The (optional) library section specifies the `library
   properties <#library>`__ and relevant `build
   information <#build-information>`__.

-  Following is an arbitrary number of executable sections which
   describe an executable program and relevant `build
   information <#build-information>`__.

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

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

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

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

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

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

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

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

Modules and preprocessors
707
^^^^^^^^^^^^^^^^^^^^^^^^^
708 709 710 711 712 713 714

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

715 716 717 718 719 720
-  ``.gc`` (:hackage-pkg:`greencard`)
-  ``.chs`` (:hackage-pkg:`c2hs`)
-  ``.hsc`` (:hackage-pkg:`hsc2hs`)
-  ``.y`` and ``.ly`` (happy_)
-  ``.x`` (alex_)
-  ``.cpphs`` (cpphs_)
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736

When building, Cabal will automatically run the appropriate preprocessor
and compile the Haskell module it produces. For the ``c2hs`` and
``hsc2hs`` preprocessors, Cabal will also automatically add, compile and
link any C sources generated by the preprocessor (produced by
``hsc2hs``'s ``#def`` feature or ``c2hs``'s auto-generated wrapper
functions).

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

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

Package properties
737
^^^^^^^^^^^^^^^^^^
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885

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

``name:`` *package-name* (required)
    The unique name of the package, without the version number.
``version:`` *numbers* (required)
    The package version number, usually consisting of a sequence of
    natural numbers separated by dots.
``cabal-version:`` *>= x.y*
    The version of the Cabal specification that this package description
    uses. The Cabal specification does slowly evolve, introducing new
    features and occasionally changing the meaning of existing features.
    By specifying which version of the spec you are using it enables
    programs which process the package description to know what syntax
    to expect and what each part means.

    For historical reasons this is always expressed using *>=* version
    range syntax. No other kinds of version range make sense, in
    particular upper bounds do not make sense. In future this field will
    specify just a version number, rather than a version range.

    The version number you specify will affect both compatibility and
    behaviour. Most tools (including the Cabal library and cabal
    program) understand a range of versions of the Cabal specification.
    Older tools will of course only work with older versions of the
    Cabal specification. Most of the time, tools that are too old will
    recognise this fact and produce a suitable error message.

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

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

``build-type:`` *identifier*
    The type of build used by this package. Build types are the
    constructors of the
    `BuildType <../release/cabal-latest/doc/API/Cabal/Distribution-PackageDescription.html#t:BuildType>`__
    type, defaulting to ``Custom``.

    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:

    ::

        import Distribution.Simple
        main = defaultMain

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

    ::

        import Distribution.Simple
        main = defaultMainWithHooks autoconfUserHooks

    For build type ``Make`` (see the section on `more complex
    packages <installing-packages.html#more-complex-packages>`__ below),
    the contents of ``Setup.hs`` must be:

    ::

        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.

``license:`` *identifier* (default: ``AllRightsReserved``)
    The type of license under which this package is distributed. License
    names are the constants of the
    `License <../release/cabal-latest/doc/API/Cabal/Distribution-License.html#t:License>`__
    type.
``license-file:`` *filename* or ``license-files:`` *filename list*
    The name of a file(s) containing the precise copyright license for
    this package. The license file(s) will be installed with the
    package.

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

``copyright:`` *freeform*
    The content of a copyright notice, typically the name of the holder
    of the copyright on the package and the year(s) from which copyright
    is claimed. For example: ``Copyright: (c) 2006-2007 Joe Bloggs``
``author:`` *freeform*
    The original author of the package.

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

``maintainer:`` *address*
    The current maintainer or maintainers of the package. This is an
    e-mail address to which users should send bug reports, feature
    requests and patches.
``stability:`` *freeform*
    The stability level of the package, e.g. ``alpha``,
    ``experimental``, ``provisional``, ``stable``.
``homepage:`` *URL*
    The package homepage.
``bug-reports:`` *URL*
    The URL where users should direct bug reports. This would normally
    be either:

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

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

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

    ::

        bug-reports: http://hackage.haskell.org/trac/hackage/

``package-url:`` *URL*
    The location of a source bundle for the package. The distribution
    should be a Cabal package.
``synopsis:`` *freeform*
    A very short description of the package, for use in a table of
    packages. This is your headline, so keep it short (one line) but as
    informative as possible. Save space by not including the package
    name or saying it's written in Haskell.
``description:`` *freeform*
    Description of the package. This may be several paragraphs, and
    should be aimed at a Haskell programmer who has never heard of your
    package before.

    For library packages, this field is used as prologue text by
    ```setup haddock`` <installing-packages.html#setup-haddock>`__, and
886
    thus may contain the same markup as Haddock_ documentation
887 888 889 890
    comments.

``category:`` *freeform*
    A classification category for future use by the package catalogue
891
    Hackage_. These categories have not
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945
    yet been specified, but the upper levels of the module hierarchy
    make a good start.
``tested-with:`` *compiler list*
    A list of compilers and versions against which the package has been
    tested (or at least built).
``data-files:`` *filename list*
    A list of files to be installed for run-time use by the package.
    This is useful for packages that use a large amount of static data,
    such as tables of values or code templates. Cabal provides a way to
    `find these files at
    run-time <#accessing-data-files-from-package-code>`__.

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

    The limitation is that ``*`` wildcards are only allowed in place of
    the file name, not in the directory name or file extension. In
    particular, wildcards do not include directories contents
    recursively. Furthermore, if a wildcard is used it must be used with
    an extension, so ``data-files: data/*`` is not allowed. When
    matching a wildcard plus extension, a file's full extension must
    match exactly, so ``*.gz`` matches ``foo.gz`` but not
    ``foo.tar.gz``. A wildcard that does not match any files is an
    error.

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

``data-dir:`` *directory*
    The directory where Cabal looks for data files to install, relative
    to the source directory. By default, Cabal will look in the source
    directory itself.
``extra-source-files:`` *filename list*
    A list of additional files to be included in source distributions
    built with
    ```setup sdist`` <installing-packages.html#setup-sdist>`__. As with
    ``data-files`` it can use a limited form of ``*`` wildcards in file
    names.
``extra-doc-files:`` *filename list*
    A list of additional files to be included in source distributions,
    and also copied to the html directory when Haddock documentation is
    generated. As with ``data-files`` it can use a limited form of ``*``
    wildcards in file names.
``extra-tmp-files:`` *filename list*
    A list of additional files or directories to be removed by
    ```setup clean`` <installing-packages.html#setup-clean>`__. These
    would typically be additional files created by additional hooks,
    such as the scheme described in the section on `system-dependent
    parameters <#system-dependent-parameters>`__.

Library
946
^^^^^^^
947 948 949

The library section should contain the following fields:

950
``exposed-modules:`` *identifier list* (required if this package contains a library)
951
    A list of modules added by this package.
952

953 954 955 956 957 958 959 960 961 962 963 964 965 966
``exposed:`` *boolean* (default: ``True``)
    Some Haskell compilers (notably GHC) support the notion of packages
    being "exposed" or "hidden" which means the modules they provide can
    be easily imported without always having to specify which package
    they come from. However this only works effectively if the modules
    provided by all exposed packages do not overlap (otherwise a module
    import would be ambiguous).

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

967
``reexported-modules:`` *exportlist*
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
    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.

The library section may also contain build information fields (see the
section on `build information <#build-information>`__).

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

::

    name:           foo
    version:        1.0
    license:        BSD3
    cabal-version:  >= 1.23
    build-type:     Simple

    library foo-internal
        exposed-modules: Foo.Internal
        build-depends: base

    library
        exposed-modules: Foo.Public
        build-depends: foo-internal, base

    test-suite test-foo
        type:       exitcode-stdio-1.0
        main-is:    test-foo.hs
        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
be added to the ``build-depends`` of same-package libraries,
executables, test suites, etc.) Internal libraries locally shadow any
packages which have the same name (so don't name an internal library
with the same name as an external dependency.)

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:

::

    cabal repl

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

::

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

Freezing dependency versions
1051
""""""""""""""""""""""""""""
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067

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:

::

    cabal freeze

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

Generating dependency version bounds
1068
""""""""""""""""""""""""""""""""""""
1069 1070

Cabal also has the ability to suggest dependency version bounds that
1071
conform to `Package Versioning Policy`_, which is
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
a recommended versioning system for publicly released Cabal packages.
This is done by running the ``gen-bounds`` command:

::

    cabal gen-bounds

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

::

    foo == 0.5.2
    bar == 1.1

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

::

    foo >= 0.5.2 && < 0.6
    bar >= 1.1 && < 1.2

Executables
1095
^^^^^^^^^^^
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113

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

The executable may be described using the following fields, as well as
build information fields (see the section on `build
information <#build-information>`__).

``main-is:`` *filename* (required)
    The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
    module. Note that it is the ``.hs`` filename that must be listed,
    even if that file is generated using a preprocessor. The source file
    must be relative to one of the directories listed in
    ``hs-source-dirs``.

Running executables
1114
"""""""""""""""""""
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130

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

::

    $ cabal run EXECUTABLE [-- EXECUTABLE_FLAGS]

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

Test suites
1131
^^^^^^^^^^^
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155

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

The test suite may be described using the following fields, as well as
build information fields (see the section on `build
information <#build-information>`__).

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

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

1156
``main-is:`` *filename* (required: ``exitcode-stdio-1.0``, disallowed: ``detailed-0.9``)
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
    The name of the ``.hs`` or ``.lhs`` file containing the ``Main``
    module. Note that it is the ``.hs`` filename that must be listed,
    even if that file is generated using a preprocessor. The source file
    must be relative to one of the directories listed in
    ``hs-source-dirs``. This field is analogous to the ``main-is`` field
    of an executable section.

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

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

1174
``test-module:`` *identifier* (required: ``detailed-0.9``, disallowed: ``exitcode-stdio-1.0``)
1175 1176 1177
    The module exporting the ``tests`` symbol.

Example: Package using ``exitcode-stdio-1.0`` interface
1178
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210

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

foo.cabal:

::

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

    Test-Suite test-foo
        type:       exitcode-stdio-1.0
        main-is:    test-foo.hs
        build-depends: base

test-foo.hs:

::

    module Main where

    import System.Exit (exitFailure)

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

Example: Package using ``detailed-0.9`` interface
1211
"""""""""""""""""""""""""""""""""""""""""""""""""
1212 1213 1214 1215 1216 1217 1218 1219 1220

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

bar.cabal:

1221
.. code-block:: none
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233

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

    Test-Suite test-bar
        type:       detailed-0.9
        test-module: Bar
        build-depends: base, Cabal >= 1.9.2

1234

1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261
Bar.hs:

::

    module Bar ( tests ) where

    import Distribution.TestSuite

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

Running test suites
1262
"""""""""""""""""""
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275

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

::

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

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

Benchmarks
1276
^^^^^^^^^^
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307

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

The benchmark may be described using the following fields, as well as
build information fields (see the section on `build
information <#build-information>`__).

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

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

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

Example: Package using ``exitcode-stdio-1.0`` interface
1308
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347

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

foo.cabal:

::

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

    Benchmark bench-foo
        type:       exitcode-stdio-1.0
        main-is:    bench-foo.hs
        build-depends: base, time

bench-foo.hs:

::

    {-# LANGUAGE BangPatterns #-}
    module Main where

    import Data.Time.Clock

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

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

Running benchmarks
1348
""""""""""""""""""
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362

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

::

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

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

Build information
1363
^^^^^^^^^^^^^^^^^
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390

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

``build-depends:`` *package list*
    A list of packages needed to build this one. Each package can be
    annotated with a version constraint.

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

    ::

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

    Dependencies like ``foo >= 1.2.3 && < 1.3`` turn out to be very
    common because it is recommended practise for package versions to
1391
    correspond to API versions (see PVP_).
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403

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

    ::

        build-depends: foo ==1.2.*

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

    Starting with Cabal 2.0, there's a new syntactic sugar to support
1404
    PVP_-style
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627
    major upper bounds conveniently, and is inspired by similiar
    syntactic sugar found in other language ecosystems where it's often
    called the "Caret" operator:

    ::

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

    The declaration above is exactly equivalent to

    ::

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

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

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

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

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

``hs-source-dirs:`` *directory list* (default: "``.``")
    Root directories for the module hierarchy.

    For backwards compatibility, the old variant ``hs-source-dir`` is
    also recognized.

``default-extensions:`` *identifier list*
    A list of Haskell extensions used by every module. These determine
    corresponding compiler options enabled for all files. Extension
    names are the constructors of the
    `Extension <../release/cabal-latest/doc/API/Cabal/Language-Haskell-Extension.html#t:Extension>`__
    type. For example, ``CPP`` specifies that Haskell source files are
    to be preprocessed with a C preprocessor.
``other-extensions:`` *identifier list*
    A list of Haskell extensions used by some (but not necessarily all)
    modules. From GHC version 6.6 onward, these may be specified by
    placing a ``LANGUAGE`` pragma in the source files affected e.g.

    ::

        {-# LANGUAGE CPP, MultiParamTypeClasses #-}

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

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

    ::

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

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

``build-tools:`` *program list*
    A list of programs, possibly annotated with versions, needed to
    build this package, e.g. ``c2hs >= 0.15, cpphs``. If no version
    constraint is specified, any version is assumed to be acceptable.
    ``build-tools`` can refer to locally defined executables, in which
    case Cabal will make sure that executable is built first and add it
    to the PATH upon invocations to the compiler.
``buildable:`` *boolean* (default: ``True``)
    Is the component buildable? Like some of the other fields below,
    this field is more useful with the slightly more elaborate form of
    the simple build infrastructure described in the section on
    `system-dependent parameters <#system-dependent-parameters>`__.
``ghc-options:`` *token list*
    Additional options for GHC. You can often achieve the same effect
    using the ``extensions`` field, which is preferred.

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

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

``ghc-prof-options:`` *token list*
    Additional options for GHC when the package is built with profiling
    enabled.

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

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

``ghc-shared-options:`` *token list*
    Additional options for GHC when the package is built as shared
    library. The options specified via this field are combined with the
    ones specified via ``ghc-options``, and are passed to GHC during
    both the compile and link phases.
``includes:`` *filename list*
    A list of header files to be included in any compilations via C.
    This field applies to both header files that are already installed
    on the system and to those coming with the package to be installed.
    The former files should be found in absolute paths, while the latter
    files should be found in paths relative to the top of the source
    tree or relative to one of the directories listed in
    ``include-dirs``.

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

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

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

    ::

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

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

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

``include-dirs:`` *directory list*
    A list of directories to search for header files, when preprocessing
    with ``c2hs``, ``hsc2hs``, ``cpphs`` or the C preprocessor, and also
    when compiling via C. Directories can be absolute paths (e.g., for
    system directories) or paths that are relative to the top of the
    source tree. Cabal looks in these directories when attempting to
    locate files listed in ``includes`` and ``install-includes``.
``c-sources:`` *filename list*
    A list of C source files to be compiled and linked with the Haskell
    files.
``js-sources:`` *filename list*
    A list of JavaScript source files to be linked with the Haskell
    files (only for JavaScript targets).
``extra-libraries:`` *token list*
    A list of extra libraries to link with.
``extra-ghci-libraries:`` *token list*
    A list of extra libraries to be used instead of 'extra-libraries'
    when the package is loaded with GHCi.
``extra-lib-dirs:`` *directory list*
    A list of directories to search for libraries.
``cc-options:`` *token list*
    Command-line arguments to be passed to the C compiler. Since the
    arguments are compiler-dependent, this field is more useful with the
    setup described in the section on `system-dependent
    parameters <#system-dependent-parameters>`__.
``cpp-options:`` *token list*
    Command-line arguments for pre-processing Haskell code. Applies to
    haskell source and other pre-processed Haskell source like .hsc
    .chs. Does not apply to C code, that's what cc-options is for.
``ld-options:`` *token list*
    Command-line arguments to be passed to the linker. Since the
    arguments are compiler-dependent, this field is more useful with the
    setup described in the section on `system-dependent
    parameters <#system-dependent-parameters>`__>.
``pkgconfig-depends:`` *package list*
    A list of
    `pkg-config <http://www.freedesktop.org/wiki/Software/pkg-config/>`__
    packages, needed to build this package. They can be annotated with
    versions, e.g. ``gtk+-2.0 >= 2.10, cairo >= 1.0``. If no version
    constraint is specified, any version is assumed to be acceptable.
    Cabal uses ``pkg-config`` to find if the packages are available on
    the system and to find the extra compilation and linker options
    needed to use the packages.

    If you need to bind to a C library that supports ``pkg-config`` (use
    ``pkg-config --list-all`` to find out if it is supported) then it is
    much preferable to use this field rather than hard code options into
    the other fields.

``frameworks:`` *token list*
    On Darwin/MacOS X, a list of frameworks to link to. See Apple's
    developer documentation for more details on frameworks. This entry
    is ignored on all other platforms.
``extra-frameworks-dirs:`` *directory list*
    On Darwin/MacOS X, a list of directories to search for frameworks.
    This entry is ignored on all other platforms.

Configurations
1628
^^^^^^^^^^^^^^
1629 1630 1631 1632 1633 1634 1635 1636

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

Example: A package containing a library and executable programs
1637
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683

::

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

    Flag Debug
      Description: Enable debug support
      Default:     False

    Flag WebFrontend
      Description: Include API for web frontend.
      -- Cabal checks if the configuration is possible, first
      -- with this flag set to True and if not it tries with False

    Library
      Build-Depends:   base
      Exposed-Modules: Testing.Test1
      Extensions:      CPP

      if flag(debug)
        GHC-Options: -DDEBUG
        if !os(windows)
          CC-Options: "-DDEBUG"
        else
          CC-Options: "-DNDEBUG"

      if flag(webfrontend)
        Build-Depends: cgi > 0.42
        Other-Modules: Testing.WebStuff

    Executable test1
      Main-is: T1.hs
      Other-Modules: Testing.Test1
      Build-Depends: base

      if flag(debug)
        CC-Options: "-DDEBUG"
        GHC-Options: -DDEBUG

Layout
1684
""""""
1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697

Flags, conditionals, library and executable sections use layout to
indicate structure. This is very similar to the Haskell layout rule.
Entries in a section have to all be indented to the same level which
must be more than the section header. Tabs are not allowed to be used
for indentation.

As an alternative to using layout you can also use explicit braces
``{}``. In this case the indentation of entries in a section does not
matter, though different fields within a block must be on different
lines. Here is a bit of the above example again, using braces:

Example: Using explicit braces rather than indentation for layout
1698
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729

::

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

    Flag Debug {
      Description: Enable debug support
      Default:     False
    }

    Library {
      Build-Depends:   base
      Exposed-Modules: Testing.Test1
      Extensions:      CPP
      if flag(debug) {
        GHC-Options: -DDEBUG
        if !os(windows) {
          CC-Options: "-DDEBUG"
        } else {
          CC-Options: "-DNDEBUG"
        }
      }
    }

Configuration Flags
1730
"""""""""""""""""""
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777

A flag section takes the flag name as an argument and may contain the
following fields.

``description:`` *freeform*
    The description of this flag.
``default:`` *boolean* (default: ``True``)
    The default value of this flag.

    Note that this value may be `overridden in several
    ways <installing-packages.html#controlling-flag-assignments>`__. The
    rationale for having flags default to True is that users usually
    want new features as soon as they are available. Flags representing
    features that are not (yet) recommended for most users (such as
    experimental features or debugging support) should therefore
    explicitly override the default to False.

``manual:`` *boolean* (default: ``False``)
    By default, Cabal will first try to satisfy dependencies with the
    default flag value and then, if that is not possible, with the
    negated value. However, if the flag is manual, then the default
    value (which can be overridden by commandline flags) will be used.

Conditional Blocks
^^^^^^^^^^^^^^^^^^

Conditional blocks may appear anywhere inside a library or executable
section. They have to follow rather strict formatting rules. Conditional
blocks must always be of the shape

::

      if condition
         property-descriptions-or-conditionals

or

::

      if condition
           property-descriptions-or-conditionals
      else
           property-descriptions-or-conditionals

Note that the ``if`` and the condition have to be all on the same line.

Conditions
1778
""""""""""
1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833

Conditions can be formed using boolean tests and the boolean operators
``||`` (disjunction / logical "or"), ``&&`` (conjunction / logical
"and"), or ``!`` (negation / logical "not"). The unary ``!`` takes
highest precedence, ``||`` takes lowest. Precedence levels may be
overridden through the use of parentheses. For example,
``os(darwin) && !arch(i386) || os(freebsd)`` is equivalent to
``(os(darwin) && !(arch(i386))) || os(freebsd)``.

The following tests are currently supported.

``os(``\ *name*\ ``)``
    Tests if the current operating system is *name*. The argument is
    tested against ``System.Info.os`` on the target system. There is
    unfortunately some disagreement between Haskell implementations
    about the standard values of ``System.Info.os``. Cabal canonicalises
    it so that in particular ``os(windows)`` works on all
    implementations. If the canonicalised os names match, this test
    evaluates to true, otherwise false. The match is case-insensitive.
``arch(``\ *name*\ ``)``
    Tests if the current architecture is *name*. The argument is matched
    against ``System.Info.arch`` on the target system. If the arch names
    match, this test evaluates to true, otherwise false. The match is
    case-insensitive.
``impl(``\ *compiler*\ ``)``
    Tests for the configured Haskell implementation. An optional version
    constraint may be specified (for example ``impl(ghc >= 6.6.1)``). If
    the configured implementation is of the right type and matches the
    version constraint, then this evaluates to true, otherwise false.
    The match is case-insensitive.

    Note that including a version constraint in an ``impl`` test causes
    it to check for two properties:

    -  The current compiler has the specified name, and

    -  The compiler's version satisfied the specified version constraint

    As a result, ``!impl(ghc >= x.y.z)`` is not entirely equivalent to
    ``impl(ghc < x.y.z)``. The test ``!impl(ghc >= x.y.z)`` checks that:

    -  The current compiler is not GHC, or

    -  The version of GHC is earlier than version x.y.z.

``flag(``\ *name*\ ``)``
    Evaluates to the current assignment of the flag of the given name.
    Flag names are case insensitive. Testing for flags that have not
    been introduced with a flag section is an error.
``true``
    Constant value true.
``false``
    Constant value false.

Resolution of Conditions and Flags
1834
""""""""""""""""""""""""""""""""""
1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869

If a package descriptions specifies configuration flags the package user
can `control these in several
ways <installing-packages.html#controlling-flag-assignments>`__. If the
user does not fix the value of a flag, Cabal will try to find a flag
assignment in the following way.

-  For each flag specified, it will assign its default value, evaluate
   all conditions with this flag assignment, and check if all
   dependencies can be satisfied. If this check succeeded, the package
   will be configured with those flag assignments.

-  If dependencies were missing, the last flag (as by the order in which
   the flags were introduced in the package description) is tried with
   its alternative value and so on. This continues until either an
   assignment is found where all dependencies can be satisfied, or all
   possible flag assignments have been tried.

To put it another way, Cabal does a complete backtracking search to find
a satisfiable package configuration. It is only the dependencies
specified in the ``build-depends`` field in conditional blocks that
determine if a particular flag assignment is satisfiable
(``build-tools`` are not considered). The order of the declaration and
the default value of the flags determines the search order. Flags
overridden on the command line fix the assignment of that flag, so no
backtracking will be tried for that flag.

If no suitable flag assignment could be found, the configuration phase
will fail and a list of missing dependencies will be printed. Note that
this resolution process is exponential in the worst case (i.e., in the
case where dependencies cannot be satisfied). There are some
optimizations applied internally, but the overall complexity remains
unchanged.

Meaning of field values when using conditionals
1870
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915

During the configuration phase, a flag assignment is chosen, all
conditionals are evaluated, and the package description is combined into
a flat package descriptions. If the same field both inside a conditional
and outside then they are combined using the following rules.

-  Boolean fields are combined using conjunction (logical "and").

-  List fields are combined by appending the inner items to the outer
   items, for example

   ::

       other-extensions: CPP
       if impl(ghc)
         other-extensions: MultiParamTypeClasses

   when compiled using GHC will be combined to

   ::

       other-extensions: CPP, MultiParamTypeClasses

   Similarly, if two conditional sections appear at the same nesting
   level, properties specified in the latter will come after properties
   specified in the former.

-  All other fields must not be specified in ambiguous ways. For example

   ::

       Main-is: Main.hs
       if flag(useothermain)
         Main-is: OtherMain.hs

   will lead to an error. Instead use

   ::

       if flag(useothermain)
         Main-is: OtherMain.hs
       else
         Main-is: Main.hs

Source Repositories
1916
^^^^^^^^^^^^^^^^^^^
1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022

It is often useful to be able to specify a source revision control
repository for a package. Cabal lets you specifying this information in
a relatively structured form which enables other tools to interpret and
make effective use of the information. For example the information
should be sufficient for an automatic tool to checkout the sources.

Cabal supports specifying different information for various common
source control systems. Obviously not all automated tools will support
all source control systems.

Cabal supports specifying repositories for different use cases. By
declaring which case we mean automated tools can be more useful. There
are currently two kinds defined:

-  The ``head`` kind refers to the latest development branch of the
   package. This may be used for example to track activity of a project
   or as an indication to outside developers what sources to get for
   making new contributions.

-  The ``this`` kind refers to the branch and tag of a repository that
   contains the sources for this version or release of a package. For
   most source control systems this involves specifying a tag, id or
   hash of some form and perhaps a branch. The purpose is to be able to
   reconstruct the sources corresponding to a particular package
   version. This might be used to indicate what sources to get if
   someone needs to fix a bug in an older branch that is no longer an
   active head branch.

You can specify one kind or the other or both. As an example here are
the repositories for the Cabal library. Note that the ``this`` kind of
repository specifies a tag.

::

    source-repository head
      type:     darcs
      location: http://darcs.haskell.org/cabal/

    source-repository this
      type:     darcs
      location: http://darcs.haskell.org/cabal-branches/cabal-1.6/
      tag:      1.6.1

The exact fields are as follows:

``type:`` *token*
    The name of the source control system used for this repository. The
    currently recognised types are:

    -  ``darcs``
    -  ``git``
    -  ``svn``
    -  ``cvs``
    -  ``mercurial`` (or alias ``hg``)
    -  ``bazaar`` (or alias ``bzr``)
    -  ``arch``
    -  ``monotone``

    This field is required.

``location:`` *URL*
    The location of the repository. The exact form of this field depends
    on the repository type. For example:

    -  for darcs: ``http://code.haskell.org/foo/``
    -  for git: ``git://github.com/foo/bar.git``
    -  for CVS: ``anoncvs@cvs.foo.org:/cvs``

    This field is required.

``module:`` *token*
    CVS requires a named module, as each CVS server can host multiple
    named repositories.

    This field is required for the CVS repository type and should not be
    used otherwise.

``branch:`` *token*
    Many source control systems support the notion of a branch, as a
    distinct concept from having repositories in separate locations. For
    example CVS, SVN and git use branches while for darcs uses different
    locations for different branches. If you need to specify a branch to
    identify a your repository then specify it in this field.

    This field is optional.

``tag:`` *token*
    A tag identifies a particular state of a source repository. The tag
    can be used with a ``this`` repository kind to identify the state of
    a repository corresponding to a particular package version or
    release. The exact form of the tag depends on the repository type.

    This field is required for the ``this`` repository kind.

``subdir:`` *directory*
    Some projects put the sources for multiple packages under a single
    source repository. This field lets you specify the relative path
    from the root of the repository to the top directory for the
    package, i.e. the directory containing the package's ``.cabal``
    file.

    This field is optional. It default to empty which corresponds to the
    root directory of the repository.

Downloading a package's source
2023
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051