nix-local-build.rst 68.8 KB
Newer Older
Leonid Onokhov's avatar
Leonid Onokhov committed
1
.. highlight:: console
2
3
4
5
6
7
8
9
10
11

Quickstart
==========

Suppose that you are in a directory containing a single Cabal package
which you wish to build. You can configure and build it using Nix-style
local builds with this command (configuring is not necessary):

::

Leonid Onokhov's avatar
Leonid Onokhov committed
12
    $ cabal new-build
13
14
15
16
17

To open a GHCi shell with this package, use this command:

::

Leonid Onokhov's avatar
Leonid Onokhov committed
18
    $ cabal new-repl
19

Francesco Gazzetta's avatar
Francesco Gazzetta committed
20
21
22
23
24
25
To run an executable defined in this package, use this command:

::

    $ cabal new-run <executable name> [executable args]

26
27
28
29
30
31
32
33
34
35
36
Developing multiple packages
----------------------------

Many Cabal projects involve multiple packages which need to be built
together. To build multiple Cabal packages, you need to first create a
``cabal.project`` file which declares where all the local package
directories live. For example, in the Cabal repository, there is a root
directory with a folder per package, e.g., the folders ``Cabal`` and
``cabal-install``. The ``cabal.project`` file specifies each folder as
part of the project:

Leonid Onokhov's avatar
Leonid Onokhov committed
37
.. code-block:: cabal
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

    packages: Cabal/
              cabal-install/

The expectation is that a ``cabal.project`` is checked into your source
control, to be used by all developers of a project. If you need to make
local changes, they can be placed in ``cabal.project.local`` (which
should not be checked in.)

Then, to build every component of every package, from the top-level
directory, run the command: (Warning: cabal-install-1.24 does NOT have
this behavior; you will need to upgrade to HEAD.)

::

Leonid Onokhov's avatar
Leonid Onokhov committed
53
    $ cabal new-build
54
55
56
57
58
59

To build a specific package, you can either run ``new-build`` from the
directory of the package in question:

::

Leonid Onokhov's avatar
Leonid Onokhov committed
60
61
    $ cd cabal-install
    $ cabal new-build
62
63
64
65
66
67

or you can pass the name of the package as an argument to
``cabal new-build`` (this works in any subdirectory of the project):

::

Leonid Onokhov's avatar
Leonid Onokhov committed
68
    $ cabal new-build cabal-install
69
70
71
72
73
74

You can also specify a specific component of the package to build. For
example, to build a test suite named ``package-tests``, use the command:

::

Leonid Onokhov's avatar
Leonid Onokhov committed
75
    $ cabal new-build package-tests
76
77
78
79
80
81
82
83
84

Targets can be qualified with package names. So to request
``package-tests`` *from* the ``Cabal`` package, use
``Cabal:package-tests``.

Unlike sandboxes, there is no need to setup a sandbox or ``add-source``
projects; just check in ``cabal.project`` to your repository and
``new-build`` will just work.

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
Cookbook
========

How can I profile my library/application?
-----------------------------------------

First, make sure you have HEAD; 1.24 is affected by :issue:`3790`,
which means that if any project which transitively depends on a
package which has a Custom setup built against Cabal 1.22 or earlier
will silently not work.

Create or edit your ``cabal.project.local``, adding the following
line::

    profiling: True

Now, ``cabal new-build`` will automatically build all libraries and
executables with profiling.  You can fine-tune the profiling settings
for each package using :cfg-field:`profiling-detail`::

    package p
        profiling-detail: toplevel-functions

Alternately, you can call ``cabal new-build --enable-profiling`` to
temporarily build with profiling.

111
112
113
114
115
116
117
118
119
How it works
============

Local versus external packages
------------------------------

One of the primary innovations of Nix-style local builds is the
distinction between local packages, which users edit and recompile and
must be built per-project, versus external packages, which can be cached
120
across projects. To be more precise:
121
122
123
124
125

1. A **local package** is one that is listed explicitly in the
   ``packages``, ``optional-packages`` or ``extra-packages`` field of a
   project. Usually, these refer to packages whose source code lives
   directly in a folder in your project (although, you can list an
126
   arbitrary Hackage package in ``extra-packages`` to force it to be
127
128
129
130
131
132
133
134
   treated as local).

Local packages, as well as the external packages (below) which depend on
them, are built **inplace**, meaning that they are always built
specifically for the project and are not installed globally. Inplace
packages are not cached and not given unique hashes, which makes them
suitable for packages which you want to edit and recompile.

135
2. An **external package** is any package which is not listed in the
136
137
138
139
140
141
142
143
144
145
146
147
   ``packages`` field. The source code for external packages is usually
   retrieved from Hackage.

When an external package does not depend on an inplace package, it can
be built and installed to a **global** store, which can be shared across
projects. These build products are identified by a hash that over all of
the inputs which would influence the compilation of a package (flags,
dependency selection, etc.). Just as in Nix, these hashes uniquely
identify the result of a build; if we compute this identifier and we
find that we already have this ID built, we can just use the already
built version.

Alex Biehl's avatar
Alex Biehl committed
148
149
150
151
152
The global package store is ``~/.cabal/store`` (configurable via 
global `store-dir` option); if you need to clear your store for 
whatever reason (e.g., to reclaim disk space or because the global
store is corrupted), deleting this directory is safe (``new-build``
will just rebuild everything it needs on its next invocation).
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175

This split motivates some of the UI choices for Nix-style local build
commands. For example, flags passed to ``cabal new-build`` are only
applied to *local* packages, so that adding a flag to
``cabal new-build`` doesn't necessitate a rebuild of *every* transitive
dependency in the global package store.

In cabal-install HEAD, Nix-style local builds also take advantage of a
new Cabal library feature, `per-component
builds <https://github.com/ezyang/ghc-proposals/blob/master/proposals/0000-componentized-cabal.rst>`__,
where each component of a package is configured and built separately.
This can massively speed up rebuilds of packages with lots of components
(e.g., a package that defines multiple executables), as only one
executable needs to be rebuilt. Packages that use Custom setup scripts
are not currently built on a per-component basis.

Where are my build products?
----------------------------

A major deficiency in the current implementation of new-build is that
there is no programmatic way to access the location of build products.
The location of the build products is intended to be an internal
implementation detail of new-build, but we also understand that many
176
unimplemented features (e.g., ``new-install``) can only be reasonably
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
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
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
286
287
288
289
290
291
292
293
worked around by accessing build products directly.

The location where build products can be found varies depending on the
version of cabal-install:

-  In cabal-install-1.24, the dist directory for a package ``p-0.1`` is
   stored in ``dist-newstyle/build/p-0.1``. For example, if you built an
   executable or test suite named ``pexe``, it would be located at
   ``dist-newstyle/build/p-0.1/build/pexe/pexe``.

-  In cabal-install HEAD, the dist directory for a package ``p-0.1``
   defining a library built with GHC 8.0.1 on 64-bit Linux is
   ``dist-newstyle/build/x86_64-linux/ghc-8.0.1/p-0.1``. When
   per-component builds are enabled (any non-Custom package), a
   subcomponent like an executable or test suite named ``pexe`` will be
   stored at
   ``dist-newstyle/build/x86_64-linux/ghc-8.0.1/p-0.1/c/pexe``; thus,
   the full path of the executable is
   ``dist-newstyle/build/x86_64-linux/ghc-8.0.1/p-0.1/c/pexe/build/pexe/pexe``
   (you can see why we want this to be an implementation detail!)

The paths are a bit longer in HEAD but the benefit is that you can
transparently have multiple builds with different versions of GHC. We
plan to add the ability to create aliases for certain build
configurations, and more convenient paths to access particularly useful
build products like executables.

Caching
-------

Nix-style local builds sport a robust caching system which help reduce
the time it takes to execute a rebuild cycle. While the details of how
``cabal-install`` does caching are an implementation detail and may
change in the future, knowing what gets cached is helpful for
understanding the performance characteristics of invocations to
``new-build``. The cached intermediate results are stored in
``dist-newstyle/cache``; this folder can be safely deleted to clear the
cache.

The following intermediate results are cached in the following files in
this folder (the most important two are first):

``solver-plan`` (binary)
    The result of calling the dependency solver, assuming that the
    Hackage index, local ``cabal.project`` file, and local ``cabal``
    files are unmodified. (Notably, we do NOT have to dependency solve
    again if new build products are stored in the global store; the
    invocation of the dependency solver is independent of what is
    already available in the store.)
``source-hashes`` (binary)
    The hashes of all local source files. When all local source files of
    a local package are unchanged, ``cabal new-build`` will skip
    invoking ``setup build`` entirely (saving us from a possibly
    expensive call to ``ghc --make``). The full list of source files
    participating in compilation are determined using
    ``setup sdist --list-sources`` (thus, if you do not list all your
    source files in a Cabal file, you may fail to recompile when you
    edit them.)
``config`` (same format as ``cabal.project``)
    The full project configuration, merged from ``cabal.project`` (and
    friends) as well as the command line arguments.
``compiler`` (binary)
    The configuration of the compiler being used to build the project.
``improved-plan`` (binary)
    Like ``solver-plan``, but with all non-inplace packages improved
    into pre-existing copies from the store.

Note that every package also has a local cache managed by the Cabal
build system, e.g., in ``$distdir/cache``.

There is another useful file in ``dist-newstyle/cache``, ``plan.json``,
which is a JSON serialization of the computed install plan. (TODO: docs)

Commands
========

We now give an in-depth description of all the commands, describing the
arguments and flags they accept.

cabal new-configure
-------------------

``cabal new-configure`` takes a set of arguments and writes a
``cabal.project.local`` file based on the flags passed to this command.
``cabal new-configure FLAGS; cabal new-build`` is roughly equivalent to
``cabal new-build FLAGS``, except that with ``new-configure`` the flags
are persisted to all subsequent calls to ``new-build``.

``cabal new-configure`` is intended to be a convenient way to write out
a ``cabal.project.local`` for simple configurations; e.g.,
``cabal new-configure -w ghc-7.8`` would ensure that all subsequent
builds with ``cabal new-build`` are performed with the compiler
``ghc-7.8``. For more complex configuration, we recommend writing the
``cabal.project.local`` file directly (or placing it in
``cabal.project``!)

``cabal new-configure`` inherits options from ``Cabal``. semantics:

-  Any flag accepted by ``./Setup configure``.

-  Any flag accepted by ``cabal configure`` beyond
   ``./Setup configure``, namely ``--cabal-lib-version``,
   ``--constraint``, ``--preference`` and ``--solver.``

-  Any flag accepted by ``cabal install`` beyond ``./Setup configure``.

-  Any flag accepted by ``./Setup haddock``.

The options of all of these flags apply only to *local* packages in a
project; this behavior is different than that of ``cabal install``,
which applies flags to every package that would be built. The motivation
for this is to avoid an innocuous addition to the flags of a package
resulting in a rebuild of every package in the store (which might need
to happen if a flag actually applied to every transitive dependency). To
apply options to an external package, use a ``package`` stanza in a
``cabal.project`` file.

Moritz Angermann's avatar
Moritz Angermann committed
294
295
296
297
298
299
300
301
302
303
304
305
306
307
cabal new-update
----------------

``cabal new-update`` updates the state of the package index. If the
project contains multiple remote package repositories it will update
the index of all of them (e.g. when using overlays).

Seom examples:

::

    $ cabal new-update                  # update all remote repos
    $ cabal new-update head.hackage     # update only head.hackage

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
cabal new-build
---------------

``cabal new-build`` takes a set of targets and builds them. It
automatically handles building and installing any dependencies of these
targets.

A target can take any of the following forms:

-  A package target: ``package``, which specifies that all enabled
   components of a package to be built. By default, test suites and
   benchmarks are *not* enabled, unless they are explicitly requested
   (e.g., via ``--enable-tests``.)

-  A component target: ``[package:][ctype:]component``, which specifies
   a specific component (e.g., a library, executable, test suite or
   benchmark) to be built.

Duncan Coutts's avatar
Duncan Coutts committed
326
327
-  All packages: ``all``, which specifies all packages within the project.

328
329
330
331
332
333
334
335
-  Components of a particular type: ``package:ctypes``, ``all:ctypes``:
   which specifies all components of the given type. Where valid
   ``ctypes`` are:
     - ``libs``, ``libraries``,
     - ``flibs``, ``foreign-libraries``,
     - ``exes``, ``executables``,
     - ``tests``,
     - ``benches``, ``benchmarks``.
Duncan Coutts's avatar
Duncan Coutts committed
336

337
In component targets, ``package:`` and ``ctype:`` (valid component types
338
are ``lib``, ``flib``, ``exe``, ``test`` and ``bench``) can be used to
339
340
341
342
343
344
345
346
347
disambiguate when multiple packages define the same component, or the
same component name is used in a package (e.g., a package ``foo``
defines both an executable and library named ``foo``). We always prefer
interpreting a target as a package name rather than as a component name.

Some example targets:

::

Leonid Onokhov's avatar
Leonid Onokhov committed
348
349
    $ cabal new-build lib:foo-pkg       # build the library named foo-pkg
    $ cabal new-build foo-pkg:foo-tests # build foo-tests in foo-pkg
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371

(There is also syntax for specifying module and file targets, but it
doesn't currently do anything.)

Beyond a list of targets, ``cabal new-build`` accepts all the flags that
``cabal new-configure`` takes. Most of these flags are only taken into
consideration when building local packages; however, some flags may
cause extra store packages to be built (for example,
``--enable-profiling`` will automatically make sure profiling libraries
for all transitive dependencies are built and installed.)

cabal new-repl
--------------

``cabal new-repl TARGET`` loads all of the modules of the target into
GHCi as interpreted bytecode. It takes the same flags as
``cabal new-build``.

Currently, it is not supported to pass multiple targets to ``new-repl``
(``new-repl`` will just successively open a separate GHCi session for
each target.)

Francesco Gazzetta's avatar
Francesco Gazzetta committed
372
373
374
375
376
377
cabal new-run
-------------

``cabal new-run [TARGET [ARGS]]`` runs the executable specified by the
target, which can be a component, a package or can be left blank, as
long as it can uniquely identify an executable within the project.
378
Tests and benchmarks are also treated as executables.
Francesco Gazzetta's avatar
Francesco Gazzetta committed
379

380
See `the new-build section <#cabal-new-build>`__ for the target syntax.
Francesco Gazzetta's avatar
Francesco Gazzetta committed
381
382
383
384
385
386
387
388
389
390
391
392

Except in the case of the empty target, the strings after it will be
passed to the executable as arguments.

If one of the arguments starts with ``-`` it will be interpreted as
a cabal flag, so if you need to pass flags to the executable you
have to separate them with ``--``.

::

    $ cabal new-run target -- -a -bcd --argument

393
394
395
cabal new-freeze
----------------

396
397
398
399
400
401
402
403
404
``cabal new-freeze`` writes out a **freeze file** which records all of
the versions and flags which that are picked by the solver under the
current index and flags.  Default name of this file is
``cabal.project.freeze`` but in combination with a
``--project-file=my.project`` flag (see :ref:`project-file
<cmdoption-project-file>`)
the name will be ``my.project.freeze``.
A freeze file has the same syntax as ``cabal.project`` and looks
something like this:
405

Leonid Onokhov's avatar
Leonid Onokhov committed
406
.. highlight:: cabal
407

Leonid Onokhov's avatar
Leonid Onokhov committed
408
::
Leonid Onokhov's avatar
Leonid Onokhov committed
409

410
411
412
413
    constraints: HTTP ==4000.3.3,
                 HTTP +warp-tests -warn-as-error -network23 +network-uri -mtl1 -conduit10,
                 QuickCheck ==2.9.1,
                 QuickCheck +templatehaskell,
414
415
                 -- etc...

416
417
418
419
420
421
422

For end-user executables, it is recommended that you distribute the
``cabal.project.freeze`` file in your source repository so that all
users see a consistent set of dependencies. For libraries, this is not
recommended: users often need to build against different versions of
libraries than what you developed against.

423
424
425
426
427
428
429
cabal new-bench
---------------

``cabal new-bench [TARGETS] [OPTIONS]`` runs the specified benchmarks
(all the benchmarks in the current package by default), first ensuring
they are up to date.

430
431
432
433
434
435
436
437
438
439
cabal new-test
--------------

``cabal new-test [TARGETS] [OPTIONS]`` runs the specified test suites
(all the test suites in the current package by default), first ensuring
they are up to date.

cabal new-haddock
-----------------

alexbiehl's avatar
alexbiehl committed
440
``cabal new-haddock [FLAGS] [TARGET]`` builds Haddock documentation for
441
442
the specified packages within the project.

alexbiehl's avatar
alexbiehl committed
443
444
445
446
If a target is not a library :cfg-field:`haddock-benchmarks`,
:cfg-field:`haddock-executables`, :cfg-field:`haddock-internal`,
:cfg-field:`haddock-tests` will be implied as necessary.

Francesco Gazzetta's avatar
Francesco Gazzetta committed
447
448
cabal new-exec
---------------
449

Francesco Gazzetta's avatar
Francesco Gazzetta committed
450
451
452
``cabal new-exec [FLAGS] [--] COMMAND [--] [ARGS]`` runs the specified command
using the project's environment. That is, passing the right flags to compiler
invocations and bringing the project's executables into scope.
453

Francesco Gazzetta's avatar
Francesco Gazzetta committed
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
cabal new-install
-----------------

``cabal new-install [FLAGS] PACKAGES`` builds the specified nonlocal packages
and symlinks their executables in ``symlink-bindir`` (usually ``~/.cabal/bin``).

For example this command will build the latest ``cabal-install`` and symlink
its ``cabal`` executable:

::

    $ cabal new-install cabal-install

For libraries and local packages see
`Unsupported commands <#unsupported-commands>`__

470
471
472
473
474
475
476
477
478
479
480
cabal new-clean
---------------

``cabal new-clean [FLAGS]`` cleans up the temporary files and build artifacts
stored in the ``dist-newstyle`` folder.

By default, it removes the entire folder, but it can also spare the configuration
and caches if the ``--save-config`` option is given, in which case it only removes
the build artefacts (``.hi``, ``.o`` along with any other temporary files generated
by the compiler, along with the build output).

481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
cabal new-sdist
---------------

``cabal new-sdist [FLAGS] [TARGETS]`` takes the crucial files needed to build ``TARGETS``
and puts them into an archive format ready for upload to Hackage. These archives are stable
and two archives of the same format built from the same source will hash to the same value.

``cabal new-sdist`` takes the following flags:

- ``--list-only``: Rather than creating an archive, lists files that would be included.
  Output is to ``stdout`` by default.

- ``--targz``: Output an archive in ``.tar.gz`` format.

- ``--zip``: Output an archive in ``.zip`` format.

- ``--output-dir``: Sets the output dir, if a non-default one is desired. The default is
  ``dist-newstyle/sdist/``.

Alexis Williams's avatar
Alexis Williams committed
500
501
502
503
504
505
``new-sdist`` is inherently incompatible with sdist hooks, not due to implementation but due
to fundamental core invariants (same source code should result in the same tarball, byte for
byte) that must be satisfied for it to function correctly in the larger new-build ecosystem.
``autogen-modules`` is able to replace uses of the hooks to add generated modules, along with
the custom publishing of Haddock documentation to Hackage.

506
507
Unsupported commands
--------------------
508

Francesco Gazzetta's avatar
Francesco Gazzetta committed
509
The following commands are not currently supported:
510

Francesco Gazzetta's avatar
Francesco Gazzetta committed
511
512
``cabal new-install`` (libraries and local executables)
    (:issue:`3737` and :issue:`4558`)
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
    Workaround: no good workaround at the moment. (But note that you no
    longer need to install libraries before building!)

Configuring builds with cabal.project
=====================================

``cabal.project`` files support a variety of options which configure the
details of your build. The general syntax of a ``cabal.project`` file is
similar to that of a Cabal file: there are a number of fields, some of
which live inside stanzas:

::

    packages: */*.cabal
    with-compiler: /opt/ghc/8.0.1/bin/ghc

    package cryptohash
      optimization: False

In general, the accepted field names coincide with the accepted command
line flags that ``cabal install`` and other commands take. For example,
534
535
``cabal new-configure --enable-profiling`` will write out a project
file with ``profiling: True``.
536
537
538
539
540
541
542
543
544
545
546
547

The full configuration of a project is determined by combining the
following sources (later entries override earlier ones):

1. ``~/.cabal/config`` (the user-wide global configuration)

2. ``cabal.project`` (the project configuratoin)

3. ``cabal.project.freeze`` (the output of ``cabal new-freeze``)

4. ``cabal.project.local`` (the output of ``cabal new-configure``)

548

549
550
551
552
553
554
Specifying the local packages
-----------------------------

The following top-level options specify what the local packages of a
project are:

555
.. cfg-field:: packages: package location list (space or comma separated)
Leonid Onokhov's avatar
Leonid Onokhov committed
556
    :synopsis: Project packages.
557
558

    :default: ``./*.cabal``
559

560
561
562
563
564
    Specifies the list of package locations which contain the local
    packages to be built by this project. Package locations can take the
    following forms:

    1. They can specify a Cabal file, or a directory containing a Cabal
565
       file, e.g., ``packages: Cabal cabal-install/cabal-install.cabal``.
566
567
568
569
570
571
572
573
574
575
576
577
578
579

    2. They can specify a glob-style wildcards, which must match one or
       more (a) directories containing a (single) Cabal file, (b) Cabal
       files (extension ``.cabal``), or (c) [STRIKEOUT:tarballs which
       contain Cabal packages (extension ``.tar.gz``)] (not implemented
       yet). For example, to match all Cabal files in all
       subdirectories, as well as the Cabal projects in the parent
       directories ``foo`` and ``bar``, use
       ``packages: */*.cabal ../{foo,bar}/``

    3. [STRIKEOUT:They can specify an ``http``, ``https`` or ``file``
       URL, representing the path to a remote tarball to be downloaded
       and built.] (not implemented yet)

580
    There is no command line variant of this field; see :issue:`3585`.
581

582
.. cfg-field:: optional-packages: package location list (space or comma-separated)
Leonid Onokhov's avatar
Leonid Onokhov committed
583
    :synopsis: Optional project packages.
584
585
586

    :default: ``./*/*.cabal``

Leonid Onokhov's avatar
Leonid Onokhov committed
587
588
589
590
591
592
    Like :cfg-field:`packages`, specifies a list of package locations
    containing local packages to be built. Unlike :cfg-field:`packages`,
    if we glob for a package, it is permissible for the glob to match against
    zero packages. The intended use-case for :cfg-field:`optional-packages`
    is to make it so that vendored packages can be automatically picked up if
    they are placed in a subdirectory, but not error if there aren't any.
593
594
595

    There is no command line variant of this field.

596
.. cfg-field:: extra-packages: package list with version bounds (comma separated)
Leonid Onokhov's avatar
Leonid Onokhov committed
597
    :synopsis: Adds external pacakges as local
598

599
600
601
602
603
604
605
606
607
    [STRIKEOUT:Specifies a list of external packages from Hackage which
    should be considered local packages.] (Not implemented)

    There is no command line variant of this field.

[STRIKEOUT:There is also a stanza ``source-repository-package`` for
specifying packages from an external version control.] (Not
implemented.)

608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
All local packages are *vendored*, in the sense that if other packages
(including external ones from Hackage) depend on a package with the name
of a local package, the local package is preferentially used.  This
motivates the default settings::

    packages: ./*.cabal
    optional-packages: ./*/*.cabal

...any package can be vendored simply by making a checkout in the
top-level project directory, as might be seen in this hypothetical
directory layout::

    foo.cabal
    foo-helper/     # local package
    unix/           # vendored external package

624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
All of these options support globs. ``cabal new-build`` has its own glob
format:

-  Anywhere in a path, as many times as you like, you can specify an
   asterisk ``*`` wildcard. E.g., ``*/*.cabal`` matches all ``.cabal``
   files in all immediate subdirectories. Like in glob(7), asterisks do
   not match hidden files unless there is an explicit period, e.g.,
   ``.*/foo.cabal`` will match ``.private/foo.cabal`` (but
   ``*/foo.cabal`` will not).

-  You can use braces to specify specific directories; e.g.,
   ``{vendor,pkgs}/*.cabal`` matches all Cabal files in the ``vendor``
   and ``pkgs`` subdirectories.

Formally, the format described by the following BNF:

640
.. code-block:: abnf
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662

    FilePathGlob    ::= FilePathRoot FilePathGlobRel
    FilePathRoot    ::= {- empty -}        # relative to cabal.project
                      | "/"                # Unix root
                      | [a-zA-Z] ":" [/\\] # Windows root
                      | "~"                # home directory
    FilePathGlobRel ::= Glob "/"  FilePathGlobRel # Unix directory
                      | Glob "\\" FilePathGlobRel # Windows directory
                      | Glob         # file
                      | {- empty -}  # trailing slash
    Glob      ::= GlobPiece *
    GlobPiece ::= "*"            # wildcard
                | [^*{},/\\] *   # literal string
                | "\\" [*{},]    # escaped reserved character
                | "{" Glob "," ... "," Glob "}" # union (match any of these)

Global configuration options
----------------------------

The following top-level configuration options are not specific to any
package, and thus apply globally:

663
664
.. cfg-field:: verbose: nat
               --verbose=n, -vn
Leonid Onokhov's avatar
Leonid Onokhov committed
665
    :synopsis: Build verbosity level.
666
667
668

    :default: 1

669
670
671
672
673
674
    Control the verbosity of ``cabal`` commands, valid values are from 0
    to 3.

    The command line variant of this field is ``--verbose=2``; a short
    form ``-v2`` is also supported.

675
676
.. cfg-field:: jobs: nat or $ncpus
               --jobs=n, -jn, --jobs=$ncpus
Leonid Onokhov's avatar
Leonid Onokhov committed
677
    :synopsis: Number of builds running in parallel.
678
679
680

    :default: 1

681
682
683
684
685
686
687
688
689
    Run *nat* jobs simultaneously when building. If ``$ncpus`` is
    specified, run the number of jobs equal to the number of CPUs.
    Package building is often quite parallel, so turning on parallelism
    can speed up build times quite a bit!

    The command line variant of this field is ``--jobs=2``; a short form
    ``-j2`` is also supported; a bare ``--jobs`` or ``-j`` is equivalent
    to ``--jobs=$ncpus``.

690
691
.. cfg-field::  keep-going: boolean
                --keep-going
Leonid Onokhov's avatar
Leonid Onokhov committed
692
    :synopsis: Try to continue building on failure.
693
694
695

    :default: False

696
697
698
699
700
    If true, after a build failure, continue to build other unaffected
    packages.

    The command line variant of this field is ``--keep-going``.

701
702
703
704
705
706
707
708
709
710
.. option:: --builddir=DIR

    Specifies the name of the directory where build products for
    build will be stored; defaults to ``dist-newstyle``.  If a
    relative name is specified, this directory is resolved relative
    to the root of the project (i.e., where the ``cabal.project``
    file lives.)

    This option cannot be specified via a ``cabal.project`` file.

711
.. _cmdoption-project-file:
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
.. option:: --project-file=FILE

    Specifies the name of the project file used to specify the
    rest of the top-level configuration; defaults to ``cabal.project``.
    This name not only specifies the name of the main project file,
    but also the auxiliary project files ``cabal.project.freeze``
    and ``cabal.project.local``; for example, if you specify
    ``--project-file=my.project``, then the other files that will
    be probed are ``my.project.freeze`` and ``my.project.local``.

    If the specified project file is a relative path, we will
    look for the file relative to the current working directory,
    and then for the parent directory, until the project file is
    found or we have hit the top of the user's home directory.

    This option cannot be specified via a ``cabal.project`` file.
728

Alex Biehl's avatar
Alex Biehl committed
729
730
731
732
.. option:: --store-dir=DIR

    Specifies the name of the directory of the global package store.
    
733
734
735
736
737
Solver configuration options
----------------------------

The following settings control the behavior of the dependency solver:

738
.. cfg-field:: constraints: constraints list (comma separated)
739
               --constraint="pkg >= 2.0"
Leonid Onokhov's avatar
Leonid Onokhov committed
740
    :synopsis: Extra dependencies constraints.
741

742
743
744
745
    Add extra constraints to the version bounds, flag settings,
    and other properties a solver can pick for a
    package. For example:
               
746
747
748
749
750
751
752
753
754
755
    ::

        constraints: bar == 2.1

    A package can be specified multiple times in ``constraints``, in
    which case the specified constraints are intersected. This is
    useful, since the syntax does not allow you to specify multiple
    constraints at once. For example, to specify both version bounds and
    flag assignments, you would write:

756
757
758
    ::

        constraints: bar == 2.1,
759
                     bar +foo -baz
760

761
762
    Valid constraints take the same form as for the `constraint
    command line option
763
    <installing-packages.html#cmdoption-setup-configure-constraint>`__.
764

765
766
.. cfg-field:: preferences: preference (comma separated)
               --preference="pkg >= 2.0"
Leonid Onokhov's avatar
Leonid Onokhov committed
767
    :synopsis: Prefered dependency versions.
768
769
770

    Like :cfg-field:`constraints`, but the solver will attempt to satisfy
    these preferences on a best-effort basis. The resulting install is locally
771
772
773
774
775
776
777
778
    optimal with respect to preferences; specifically, no single package
    could be replaced with a more preferred version that still satisfies
    the hard constraints.

    Operationally, preferences can cause the solver to attempt certain
    version choices of a package before others, which can improve
    dependency solver runtime.

779
    One way to use :cfg-field:`preferences` is to take a known working set of
780
781
782
783
784
785
786
787
788
789
    constraints (e.g., via ``cabal new-freeze``) and record them as
    preferences. In this case, the solver will first attempt to use this
    configuration, and if this violates hard constraints, it will try to
    find the minimal number of upgrades to satisfy the hard constraints
    again.

    The command line variant of this field is
    ``--preference="pkg >= 2.0"``; to specify multiple preferences, pass
    the flag multiple times.

790
.. cfg-field:: allow-newer: none, all or list of scoped package names (space or comma separated)
791
               --allow-newer, --allow-newer=[none,all,[scope:][^]pkg]
Leonid Onokhov's avatar
Leonid Onokhov committed
792
    :synopsis: Lift dependencies upper bound constaints.
793
794
795

    :default: ``none``

796
    Allow the solver to pick an newer version of some packages than
797
798
    would normally be permitted by than the :pkg-field:`build-depends` bounds
    of packages in the install plan. This option may be useful if the
799
800
    dependency solver cannot otherwise find a valid install plan.

801
    For example, to relax ``pkg``\ s :pkg-field:`build-depends` upper bound on
802
803
804
805
806
807
    ``dep-pkg``, write a scoped package name of the form:

    ::

        allow-newer: pkg:dep-pkg

808
809
810
811
812
813
814
815
816
817
818
    If the scope shall be limited to specific releases of ``pkg``, the
    extended form as in

    ::

        allow-newer: pkg-1.2.3:dep-pkg, pkg-1.1.2:dep-pkg

    can be used to limit the relaxation of dependencies on
    ``dep-pkg`` by the ``pkg-1.2.3`` and ``pkg-1.1.2`` releases only.

    The scoped syntax is recommended, as it is often only a single package
819
820
821
822
    whose upper bound is misbehaving. In this case, the upper bounds of
    other packages should still be respected; indeed, relaxing the bound
    can break some packages which test the selected version of packages.

823
824
825
826
827
828
829
    The syntax also allows to prefix the dependee package with a
    modifier symbol to modify the scope/semantic of the relaxation
    transformation in a additional ways. Currently only one modifier
    symbol is defined, i.e. ``^`` (i.e. caret) which causes the
    relaxation to be applied only to ``^>=`` operators and leave all other
    version operators untouched.

830
831
832
833
834
835
836
837
    However, in some situations (e.g., when attempting to build packages
    on a new version of GHC), it is useful to disregard *all*
    upper-bounds, with respect to a package or all packages. This can be
    done by specifying just a package name, or using the keyword ``all``
    to specify all packages:

    ::

Leonid Onokhov's avatar
Leonid Onokhov committed
838
        -- Disregard upper bounds involving the dependencies on
839
840
841
        -- packages bar, baz. For quux only, relax
        -- 'quux ^>= ...'-style constraints only.
        allow-newer: bar, baz, ^quux
842

Leonid Onokhov's avatar
Leonid Onokhov committed
843
        -- Disregard all upper bounds when dependency solving
844
845
        allow-newer: all

846
847
848
        -- Disregard all `^>=`-style upper bounds when dependency solving
        allow-newer: ^all

849
850

    For consistency, there is also the explicit wildcard scope syntax
851
852
    ``*`` (or its alphabetic synonym ``all``). Consequently, the
    examples above are equivalent to the explicitly scoped variants:
853
854
855
856
857

    ::

        allow-newer: all:bar, *:baz, *:^quux

858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
        allow-newer: *:*
        allow-newer: all:all

        allow-newer: *:^*
        allow-newer: all:^all

    In order to ignore all bounds specified by a package ``pkg-1.2.3``
    you can combine scoping with a right-hand-side wildcard like so

    ::

        -- Disregard any upper bounds specified by pkg-1.2.3
        allow-newer: pkg-1.2.3:*

        -- Disregard only `^>=`-style upper bounds in pkg-1.2.3
        allow-newer: pkg-1.2.3:^*


876
877
878
    :cfg-field:`allow-newer` is often used in conjunction with a constraint
    (in the cfg-field:`constraints` field) forcing the usage of a specific,
    newer version of a package.
879

880
    The command line variant of this field is e.g. ``--allow-newer=bar``. A
881
882
    bare ``--allow-newer`` is equivalent to ``--allow-newer=all``.

883
.. cfg-field:: allow-older: none, all, list of scoped package names (space or comma separated)
884
               --allow-older, --allow-older=[none,all,[scope:][^]pkg]
Leonid Onokhov's avatar
Leonid Onokhov committed
885
    :synopsis: Lift dependency lower bound constaints.
886
    :since: 2.0
887
888
889
890
891

    :default: ``none``

    Like :cfg-field:`allow-newer`, but applied to lower bounds rather than
    upper bounds.
892
893
894
895

    The command line variant of this field is ``--allow-older=all``. A
    bare ``--allow-older`` is equivalent to ``--allow-older=all``.

896
897
898

.. cfg-field:: index-state: HEAD, unix-timestamp, ISO8601 UTC timestamp.
   :synopsis: Use source package index state as it existed at a previous time.
899
   :since: 2.0
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918

   :default: ``HEAD``

   This allows to change the source package index state the solver uses
   to compute install-plans. This is particularly useful in
   combination with freeze-files in order to also freeze the state the
   package index was in at the time the install-plan was frozen.

   ::

      -- UNIX timestamp format example
      index-state: @1474739268

      -- ISO8601 UTC timestamp format example
      -- This format is used by 'cabal new-configure'
      -- for storing `--index-state` values.
      index-state: 2016-09-24T17:47:48Z


919
920
921
Package configuration options
-----------------------------

922
Package options affect the building of specific packages. There are three
923
924
925
926
927
928
929
930
931
ways a package option can be specified:

-  They can be specified at the top-level, in which case they apply only
   to **local package**, or

-  They can be specified inside a ``package`` stanza, in which case they
   apply to the build of the package, whether or not it is local or
   external.

932
-  They can be specified inside an ``package *`` stanza, in which case they
933
934
935
936
   apply to all packages, local ones from the project and also external
   dependencies.


937
938
939
For example, the following options specify that :cfg-field:`optimization`
should be turned off for all local packages, and that ``bytestring`` (possibly
an external dependency) should be built with ``-fno-state-hack``::
940
941
942
943
944
945

    optimization: False

    package bytestring
        ghc-options: -fno-state-hack

946
947
948
949
``ghc-options`` is not specifically described in this documentation,
but is one of many fields for configuring programs.  They take the form
``progname-options`` and ``progname-location``, and
can only be set inside package stanzas.  (TODO: They are not supported
950
at top-level, see :issue:`3579`.)
951

952
953
954
955
956
957
958
959
960
961
At the moment, there is no way to specify an option to apply to all
external packages or all inplace packages. Additionally, it is only
possible to specify these options on the command line for all local
packages (there is no per-package command line interface.)

Some flags were added by more recent versions of the Cabal library. This
means that they are NOT supported by packages which use Custom setup
scripts that require a version of the Cabal library older than when the
feature was added.

962
963
.. cfg-field:: flags: list of +flagname or -flagname (space separated)
               --flags="+foo -bar", -ffoo, -f-bar
Leonid Onokhov's avatar
Leonid Onokhov committed
964
    :synopsis: Enable or disable package flags.
965

966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
    Force all flags specified as ``+flagname`` to be true, and all flags
    specified as ``-flagname`` to be false. For example, to enable the
    flag ``foo`` and disable ``bar``, set:

    ::

        flags: +foo -bar

    If there is no leading punctuation, it is assumed that the flag
    should be enabled; e.g., this is equivalent:

    ::

        flags: foo -bar

    Flags are *per-package*, so it doesn't make much sense to specify
    flags at the top-level, unless you happen to know that *all* of your
    local packages support the same named flags. If a flag is not
    supported by a package, it is ignored.

986
    See also the solver configuration field :cfg-field:`constraints`.
987
988
989
990
991
992
993
994
995
996

    The command line variant of this flag is ``--flags``. There is also
    a shortened form ``-ffoo -f-bar``.

    A common mistake is to say ``cabal new-build -fhans``, where
    ``hans`` is a flag for a transitive dependency that is not in the
    local package; in this case, the flag will be silently ignored. If
    ``haskell-tor`` is the package you want this flag to apply to, try
    ``--constraint="haskell-tor +hans"`` instead.

997
998
.. cfg-field:: with-compiler: executable
               --with-compiler=executable
Leonid Onokhov's avatar
Leonid Onokhov committed
999
    :synopsis: Path to compiler executable.
1000

1001
    Specify the path to a particular compiler to be used. If not an
1002
    absolute path, it will be resolved according to the :envvar:`PATH`
1003
    environment. The type of the compiler (GHC, GHCJS, etc) must be
1004
    consistent with the setting of the :cfg-field:`compiler` field.
1005
1006
1007
1008
1009

    The most common use of this option is to specify a different version
    of your compiler to be used; e.g., if you have ``ghc-7.8`` in your
    path, you can specify ``with-compiler: ghc-7.8`` to use it.

1010
1011
    This flag also sets the default value of :cfg-field:`with-hc-pkg`, using
    the heuristic that it is named ``ghc-pkg-7.8`` (if your executable name
1012
1013
    is suffixed with a version number), or is the executable named
    ``ghc-pkg`` in the same directory as the ``ghc`` directory. If this
1014
    heuristic does not work, set :cfg-field:`with-hc-pkg` explicitly.
1015
1016
1017
1018
1019
1020

    For inplace packages, ``cabal new-build`` maintains a separate build
    directory for each version of GHC, so you can maintain multiple
    build trees for different versions of GHC without clobbering each
    other.

1021
    At the moment, it's not possible to set :cfg-field:`with-compiler` on a
1022
1023
1024
1025
1026
1027
1028
    per-package basis, but eventually we plan on relaxing this
    restriction. If this is something you need, give us a shout.

    The command line variant of this flag is
    ``--with-compiler=ghc-7.8``; there is also a short version
    ``-w ghc-7.8``.

1029
1030
.. cfg-field:: with-hc-pkg: executable
               --with-hc-pkg=executable
Leonid Onokhov's avatar
Leonid Onokhov committed
1031
    :synopsis: Specifies package tool.
1032

1033
1034
    Specify the path to the package tool, e.g., ``ghc-pkg``. This
    package tool must be compatible with the compiler specified by
1035
1036
1037
    :cfg-field:`with-compiler` (generally speaking, it should be precisely
    the tool that was distributed with the compiler). If this option is
    omitted, the default value is determined from :cfg-field:`with-compiler`.
1038
1039
1040
1041

    The command line variant of this flag is
    ``--with-hc-pkg=ghc-pkg-7.8``.

1042
1043
1044
.. cfg-field:: optimization: nat
               --enable-optimization
               --disable-optimization
Leonid Onokhov's avatar
Leonid Onokhov committed
1045
    :synopsis: Build with optimization.
1046
1047
1048

    :default: ``1``

1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
    Build with optimization. This is appropriate for production use,
    taking more time to build faster libraries and programs.

    The optional *nat* value is the optimisation level. Some compilers
    support multiple optimisation levels. The range is 0 to 2. Level 0
    disables optimization, level 1 is the default. Level 2 is higher
    optimisation if the compiler supports it. Level 2 is likely to lead
    to longer compile times and bigger generated code. If you are not
    planning to run code, turning off optimization will lead to better
    build times and less code to be rebuilt when a module changes.

1060
1061
    When optimizations are enabled, Cabal passes ``-O2`` to the C compiler.

1062
1063
1064
1065
    We also accept ``True`` (equivalent to 1) and ``False`` (equivalent
    to 0).

    Note that as of GHC 8.0, GHC does not recompile when optimization
1066
    levels change (see :ghc-ticket:`10923`), so if
1067
1068
1069
1070
1071
1072
1073
1074
    you change the optimization level for a local package you may need
    to blow away your old build products in order to rebuild with the
    new optimization level.

    The command line variant of this flag is ``-O2`` (with ``-O1``
    equivalent to ``-O``). There are also long-form variants
    ``--enable-optimization`` and ``--disable-optimization``.

1075
1076
.. cfg-field:: configure-options: args (space separated)
               --configure-option=arg
Leonid Onokhov's avatar
Leonid Onokhov committed
1077
    :synopsis: Options to pass to configure script.
1078

1079
1080
1081
1082
1083
1084
1085
1086
1087
    A list of extra arguments to pass to the external ``./configure``
    script, if one is used. This is only useful for packages which have
    the ``Configure`` build type. See also the section on
    `system-dependent
    parameters <developing-packages.html#system-dependent-parameters>`__.

    The command line variant of this flag is ``--configure-option=arg``,
    which can be specified multiple times to pass multiple options.

1088
1089
.. cfg-field:: compiler: ghc, ghcjs, jhc, lhc, uhc or haskell-suite
               --compiler=compiler
Leonid Onokhov's avatar
Leonid Onokhov committed
1090
    :synopsis: Compiler to build with.
1091
1092
1093

    :default: ``ghc``

1094
1095
1096
1097
1098
1099
    Specify which compiler toolchain to be used. This is independent of
    ``with-compiler``, because the choice of toolchain affects Cabal's
    build logic.

    The command line variant of this flag is ``--compiler=ghc``.

1100
1101
1102
.. cfg-field:: tests: boolean
               --enable-tests
               --disable-tests
Leonid Onokhov's avatar
Leonid Onokhov committed
1103
    :synopsis: Build tests.
1104
1105
1106

    :default: ``False``

1107
1108
1109
1110
1111
1112
1113
1114
    Force test suites to be enabled. For most users this should not be
    needed, as we always attempt to solve for test suite dependencies,
    even when this value is ``False``; furthermore, test suites are
    automatically enabled if they are requested as a built target.

    The command line variant of this flag is ``--enable-tests`` and
    ``--disable-tests``.

1115
1116
1117
.. cfg-field:: benchmarks: boolean
               --enable-benchmarks
               --disable-benchmarks
Leonid Onokhov's avatar
Leonid Onokhov committed
1118
    :synopsis: Build benchmarks.
1119
1120
1121

    :default: ``False``

1122
1123
1124
1125
1126
1127
1128
1129
    Force benchmarks to be enabled. For most users this should not be
    needed, as we always attempt to solve for benchmark dependencies,
    even when this value is ``False``; furthermore, benchmarks are
    automatically enabled if they are requested as a built target.

    The command line variant of this flag is ``--enable-benchmarks`` and
    ``--disable-benchmarks``.

1130
1131
.. cfg-field:: extra-prog-path: paths (newline or comma separated)
               --extra-prog-path=PATH
Leonid Onokhov's avatar
Leonid Onokhov committed
1132
    :synopsis: Add directories to program search path.
1133
1134
    :since: 1.18

1135
1136
1137
1138
1139
1140
1141
1142
1143
    A list of directories to search for extra required programs. Most
    users should not need this, as programs like ``happy`` and ``alex``
    will automatically be installed and added to the path. This can be
    useful if a ``Custom`` setup script relies on an exotic extra
    program.

    The command line variant of this flag is ``--extra-prog-path=PATH``,
    which can be specified multiple times.

1144
1145
.. cfg-field:: run-tests: boolean
               --run-tests
Leonid Onokhov's avatar
Leonid Onokhov committed
1146
    :synopsis: Run package test suite upon installation.
1147
1148
1149

    :default: ``False``

1150
1151
1152
1153
    Run the package test suite upon installation. This is useful for
    saying "When this package is installed, check that the test suite
    passes, terminating the rest of the build if it is broken."

1154
1155
1156
1157
1158
1159
1160
    .. warning::

      One deficiency: the :cfg-field:`run-tests` setting of a package is NOT
      recorded as part of the hash, so if you install something without
      :cfg-field:`run-tests` and then turn on ``run-tests``, we won't
      subsequently test the package. If this is causing you problems, give
      us a shout.
1161
1162
1163
1164

    The command line variant of this flag is ``--run-tests``.

Object code options
1165
^^^^^^^^^^^^^^^^^^^
1166

1167
1168
.. cfg-field:: debug-info: integer
               --enable-debug-info=<n>
1169
               --disable-debug-info
Leonid Onokhov's avatar
Leonid Onokhov committed
1170
    :synopsis: Build with debug info enabled.
1171
1172
1173
1174
    :since: 1.22

    :default: False

1175
1176
    If the compiler (e.g., GHC 7.10 and later) supports outputing OS
    native debug info (e.g., DWARF), setting ``debug-info: True`` will
1177
1178
    instruct it to do so. See the GHC wiki page on :ghc-wiki:`DWARF`
    for more information about this feature.
1179

1180
1181
    (This field also accepts numeric syntax, but until GHC 8.2 this didn't
    do anything.)
1182
1183
1184
1185

    The command line variant of this flag is ``--enable-debug-info`` and
    ``--disable-debug-info``.

Ben Gamari's avatar
Ben Gamari committed
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
.. cfg-field:: split-sections: boolean
               --enable-split-sections
               --disable-split-sections
    :synopsis: Use GHC's split sections feature.
    :since: 2.1

    :default: False

    Use the GHC ``-split-sections`` feature when building the library. This
    reduces the final size of the executables that use the library by
    allowing them to link with only the bits that they use rather than
    the entire library. The downside is that building the library takes
    longer and uses a bit more memory.

    This feature is supported by GHC 8.0 and later.

    The command line variant of this flag is ``--enable-split-sections`` and
    ``--disable-split-sections``.

1205
1206
1207
.. cfg-field:: split-objs: boolean
               --enable-split-objs
               --disable-split-objs
Ben Gamari's avatar
Ben Gamari committed
1208
    :synopsis: Use GHC's split objects feature.
1209
1210
1211

    :default: False

1212
1213
1214
1215
1216
1217
    Use the GHC ``-split-objs`` feature when building the library. This
    reduces the final size of the executables that use the library by
    allowing them to link with only the bits that they use rather than
    the entire library. The downside is that building the library takes
    longer and uses considerably more memory.

Ben Gamari's avatar
Ben Gamari committed
1218
1219
1220
    It is generally recommend that you use ``split-sections`` instead
    of ``split-objs`` where possible.

1221
1222
1223
    The command line variant of this flag is ``--enable-split-objs`` and
    ``--disable-split-objs``.

1224
1225
1226
.. cfg-field:: executable-stripping: boolean
               --enable-executable-stripping
               --disable-executable-stripping
Leonid Onokhov's avatar
Leonid Onokhov committed
1227
    :synopsis: Strip installed programs.
1228
1229
1230

    :default: True

1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
    When installing binary executable programs, run the ``strip``
    program on the binary. This can considerably reduce the size of the
    executable binary file. It does this by removing debugging
    information and symbols.

    Not all Haskell implementations generate native binaries. For such
    implementations this option has no effect.

    (TODO: Check what happens if you combine this with ``debug-info``.)

    The command line variant of this flag is
    ``--enable-executable-stripping`` and
    ``--disable-executable-stripping``.

1245
1246
1247
.. cfg-field:: library-stripping: boolean
               --enable-library-stripping
               --disable-library-stripping
Leonid Onokhov's avatar
Leonid Onokhov committed
1248
    :synopsis: Strip installed libraries.
1249
1250
    :since: 1.19

1251
1252
1253
1254
1255
1256
1257
1258
    When installing binary libraries, run the ``strip`` program on the
    binary, saving space on the file system. See also
    ``executable-stripping``.

    The command line variant of this flag is
    ``--enable-library-stripping`` and ``--disable-library-stripping``.

Executable options
1259
^^^^^^^^^^^^^^^^^^
1260

1261
1262
.. cfg-field:: program-prefix: prefix
               --program-prefix=prefix
Leonid Onokhov's avatar
Leonid Onokhov committed
1263
    :synopsis: Prepend prefix to program names.
1264

1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
    [STRIKEOUT:Prepend *prefix* to installed program names.] (Currently
    implemented in a silly and not useful way. If you need this to work
    give us a shout.)

    *prefix* may contain the following path variables: ``$pkgid``,
    ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``,
    ``$abitag``

    The command line variant of this flag is ``--program-prefix=foo-``.

1275
1276
.. cfg-field:: program-suffix: suffix
               --program-suffix=suffix
Leonid Onokhov's avatar
Leonid Onokhov committed
1277
    :synopsis: Append refix to program names.
1278

1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
    [STRIKEOUT:Append *suffix* to installed program names.] (Currently
    implemented in a silly and not useful way. If you need this to work
    give us a shout.)

    The most obvious use for this is to append the program's version
    number to make it possible to install several versions of a program
    at once: ``program-suffix: $version``.

    *suffix* may contain the following path variables: ``$pkgid``,
    ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``,
    ``$abitag``

    The command line variant of this flag is
    ``--program-suffix='$version'``.

Dynamic linking options
1295
^^^^^^^^^^^^^^^^^^^^^^^
1296

1297
1298
1299
.. cfg-field:: shared: boolean
               --enable-shared
               --disable-shared
Leonid Onokhov's avatar
Leonid Onokhov committed
1300
    :synopsis: Build shared library.
1301
1302
1303

    :default: False

1304
1305
1306
1307
1308
1309
    Build shared library. This implies a separate compiler run to
    generate position independent code as required on most platforms.

    The command line variant of this flag is ``--enable-shared`` and
    ``--disable-shared``.

1310
1311
1312
.. cfg-field:: executable-dynamic: boolean
               --enable-executable-dynamic
               --disable-executable-dynamic
Leonid Onokhov's avatar
Leonid Onokhov committed
1313
    :synopsis: Link executables dynamically.
1314
1315
1316

    :default: False

1317
1318
1319
1320
1321
1322
1323
1324
    Link executables dynamically. The executable's library dependencies
    should be built as shared objects. This implies ``shared: True``
    unless ``shared: False`` is explicitly specified.

    The command line variant of this flag is
    ``--enable-executable-dynamic`` and
    ``--disable-executable-dynamic``.

1325
1326
1327
.. cfg-field:: library-for-ghci: boolean
               --enable-library-for-ghci
               --disable-library-for-ghci
Leonid Onokhov's avatar
Leonid Onokhov committed
1328
    :synopsis: Build libraries suitable for use with GHCi.
1329
1330
1331

    :default: True

1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
    Build libraries suitable for use with GHCi. This involves an extra
    linking step after the build.

    Not all platforms support GHCi and indeed on some platforms, trying
    to build GHCi libs fails. In such cases, consider setting
    ``library-for-ghci: False``.

    The command line variant of this flag is
    ``--enable-library-for-ghci`` and ``--disable-library-for-ghci``.

1342
1343
.. cfg-field:: relocatable:
               --relocatable
Leonid Onokhov's avatar
Leonid Onokhov committed
1344
    :synopsis: Build relocatable package.
1345
1346
1347
1348
    :since: 1.21

    :default: False

1349
1350
1351
1352
1353
    [STRIKEOUT:Build a package which is relocatable.] (TODO: It is not
    clear what this actually does, or if it works at all.)

    The command line variant of this flag is ``--relocatable``.

Moritz Angermann's avatar
Moritz Angermann committed
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
Static linking options
^^^^^^^^^^^^^^^^^^^^^^

.. cfg-field:: static: boolean
               --enable-static
               --disable-static
    :synopsis: Build static library.


    :default: False

    Roll this and all dependent libraries into a combined ``.a`` archive.
    This uses GHCs ``-staticlib`` flag, which is avaiable for iOS and with
    GHC 8.4 and later for other platforms as well.

1369
Foreign function interface options
1370
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1371

1372
1373
.. cfg-field:: extra-include-dirs: directories (comma or newline separated list)
               --extra-include-dirs=DIR
Leonid Onokhov's avatar
Leonid Onokhov committed
1374
    :synopsis: Adds C header search path.
1375

1376
1377
1378
1379
1380
1381
    An extra directory to search for C header files. You can use this
    flag multiple times to get a list of directories.

    You might need to use this flag if you have standard system header
    files in a non-standard location that is not mentioned in the
    package's ``.cabal`` file. Using this option has the same affect as
1382
    appending the directory *dir* to the :pkg-field:`include-dirs` field in each
1383
1384
1385
1386
1387
1388
1389
1390
1391
    library and executable in the package's ``.cabal`` file. The
    advantage of course is that you do not have to modify the package at
    all. These extra directories will be used while building the package
    and for libraries it is also saved in the package registration
    information and used when compiling modules that use the library.

    The command line variant of this flag is
    ``--extra-include-dirs=DIR``, which can be specified multiple times.

1392
1393
.. cfg-field:: extra-lib-dirs: directories (comma or newline separated list)
               --extra-lib-dirs=DIR
Leonid Onokhov's avatar
Leonid Onokhov committed
1394
    :synopsis: Adds library search directory.
1395

1396
1397
1398
1399
1400
    An extra directory to search for system libraries files.

    The command line variant of this flag is ``--extra-lib-dirs=DIR``,
    which can be specified multiple times.

1401
1402
.. cfg-field:: extra-framework-dirs: directories (comma or newline separated list)
               --extra-framework-dirs=DIR
Leonid Onokhov's avatar
Leonid Onokhov committed
1403
    :synopsis: Adds framework search directory (OS X only).
1404

1405
1406
1407
1408
1409
    An extra directory to search for frameworks (OS X only).

    You might need to use this flag if you have standard system
    libraries in a non-standard location that is not mentioned in the
    package's ``.cabal`` file. Using this option has the same affect as
1410
    appending the directory *dir* to the :cfg-field:`extra-lib-dirs` field in
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
    each library and executable in the package's ``.cabal`` file. The
    advantage of course is that you do not have to modify the package at
    all. These extra directories will be used while building the package
    and for libraries it is also saved in the package registration
    information and used when compiling modules that use the library.

    The command line variant of this flag is
    ``--extra-framework-dirs=DIR``, which can be specified multiple
    times.

Profiling options
1422
^^^^^^^^^^^^^^^^^
1423

1424
1425
1426
.. cfg-field:: profiling: boolean
               --enable-profiling
               --disable-profiling
Leonid Onokhov's avatar
Leonid Onokhov committed
1427
    :synopsis: Enable profiling builds.
1428
1429
1430
1431
    :since: 1.21

    :default: False

1432
1433
    Build libraries and executables with profiling enabled (for
    compilers that support profiling as a separate mode). It is only
1434
1435
    necessary to specify :cfg-field:`profiling` for the specific package you
    want to profile; ``cabal new-build`` will ensure that all of its
1436
1437
1438
    transitive dependencies are built with profiling enabled.

    To enable profiling for only libraries or executables, see
1439
    :cfg-field:`library-profiling` and :cfg-field:`executable-profiling`.
1440
1441

    For useful profiling, it can be important to control precisely what
1442
    cost centers are allocated; see :cfg-field:`profiling-detail`.
1443
1444
1445
1446

    The command line variant of this flag is ``--enable-profiling`` and
    ``--disable-profiling``.

1447
1448
.. cfg-field:: profiling-detail: level
               --profiling-detail=level
Leonid Onokhov's avatar
Leonid Onokhov committed
1449
    :synopsis: Profiling detail level.
1450
1451
    :since: 1.23

1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
    Some compilers that support profiling, notably GHC, can allocate
    costs to different parts of the program and there are different
    levels of granularity or detail with which this can be done. In
    particular for GHC this concept is called "cost centers", and GHC
    can automatically add cost centers, and can do so in different ways.

    This flag covers both libraries and executables, but can be
    overridden by the ``library-profiling-detail`` field.

    Currently this setting is ignored for compilers other than GHC. The
    levels that cabal currently supports are:

1464
    default
1465
1466
        For GHC this uses ``exported-functions`` for libraries and
        ``toplevel-functions`` for executables.
Leonid Onokhov's avatar