4 ``cabal help`` groups commands into :ref:`global<command-group-global>`,
5 :ref:`database<command-group-database>`, :ref:`init<command-group-init>`,
6 :ref:`configure<command-group-config>`, :ref:`build<command-group-build>`,
7 :ref:`run<command-group-run>` and :ref:`ship<command-group-ship>` sections.
12 Command line interface to the Haskell Cabal infrastructure.
14 See http://www.haskell.org/cabal/ for more information.
16 Usage: cabal [GLOBAL FLAGS] [COMMAND [FLAGS]]
20 user-config Display and update the user's global cabal configuration.
21 help Help about commands.
22 path Display paths used by cabal.
25 update Updates list of known packages.
26 list List packages matching a search string.
27 info Display detailed information about a particular package.
29 [initialization and download]
30 init Create a new cabal package.
31 fetch Downloads packages for later installation.
32 get Download/Extract a package's source code (repository).
34 [project configuration]
35 configure Add extra project configuration.
36 freeze Freeze dependencies.
37 gen-bounds Generate dependency bounds.
38 outdated Check for outdated dependencies.
40 [project building and installing]
41 build Compile targets within the project.
42 install Install packages.
43 haddock Build Haddock documentation.
44 haddock-project Generate Haddocks HTML documentation for the cabal project.
45 clean Clean the package store and remove temporary files.
48 list-bin List the path to a single executable.
49 repl Open an interactive session for the given component.
50 run Run an executable.
53 exec Give a command access to the store.
55 [sanity checks and shipping]
56 check Check the package for common mistakes.
57 sdist Generate a source distribution file (.tar.gz).
58 upload Uploads source packages or documentation to Hackage.
59 report Upload build reports to a remote server.
62 unpack Deprecated alias for 'get'.
63 hscolour Generate HsColour colourised code, in HTML format.
65 [new-style projects (forwards-compatible aliases)]
66 Since cabal-install-3.0.0.0, all 'v2-' prefixed names of commands are just
67 aliases for the simple unprefixed names. So v2-build is an alias for
68 build, v2-install for install and so on.
70 [legacy command aliases]
71 No legacy commands are described.
73 Common Arguments and Flags
74 --------------------------
76 Arguments and flags common to some or all commands are:
79 .. option:: --default-user-config=file
81 Allows a "default" ``cabal.config`` freeze file to be passed in
82 manually. This file will only be used if one does not exist in the
83 project directory already. Typically, this can be set from the
84 global cabal ``config`` file so as to provide a default set of
85 partial constraints to be used by projects, providing a way for
86 users to peg themselves to stable package collections.
89 .. option:: --allow-newer[=DEPS], --allow-older[=DEPS]
91 Selectively relax upper or lower bounds in dependencies without
92 editing the package description respectively.
94 The following description focuses on upper bounds and the
95 :option:`--allow-newer` flag, but applies analogously to
96 :option:`--allow-older` and lower bounds. :option:`--allow-newer`
97 and :option:`--allow-older` can be used at the same time.
99 If you want to install a package A that depends on B >= 1.0 && <
100 2.0, but you have the version 2.0 of B installed, you can compile A
101 against B 2.0 by using ``cabal install --allow-newer=B A``. This
102 works for the whole package index: if A also depends on C that in
103 turn depends on B < 2.0, C's dependency on B will be also relaxed.
111 Resolving dependencies...
112 cabal: Could not resolve dependencies:
114 $ cabal configure --allow-newer
115 Resolving dependencies...
122 # Relax upper bounds in all dependencies.
123 $ cabal install --allow-newer foo
125 # Relax upper bounds only in dependencies on bar, baz and quux.
126 $ cabal install --allow-newer=bar,baz,quux foo
128 # Relax the upper bound on bar and force bar==2.1.
129 $ cabal install --allow-newer=bar --constraint="bar==2.1" foo
131 It's also possible to limit the scope of :option:`--allow-newer` to single
132 packages with the ``--allow-newer=scope:dep`` syntax. This means
133 that the dependency on ``dep`` will be relaxed only for the package
140 # Relax upper bound in foo's dependency on base; also relax upper bound in
141 # every package's dependency on lens.
142 $ cabal install --allow-newer=foo:base,lens
144 # Relax upper bounds in foo's dependency on base and bar's dependency
145 # on time; also relax the upper bound in the dependency on lens specified by
147 $ cabal install --allow-newer=foo:base,lens --allow-newer=bar:time
149 Finally, one can enable :option:`--allow-newer` permanently by setting
150 ``allow-newer: True`` in the :ref:`config file <config-file-discovery>`. Enabling
151 'allow-newer' selectively is also supported in the config file
152 (``allow-newer: foo, bar, baz:base``).
154 .. option:: --preference=CONSTRAINT
156 Specify a soft constraint on versions of a package. The solver will
157 attempt to satisfy these preferences on a "best-effort" basis.
159 .. option:: --enable-build-info
161 Generate accurate build information for build components.
163 Information contains meta information, such as component type, compiler type, and
164 Cabal library version used during the build, but also fine grained information,
165 such as dependencies, what modules are part of the component, etc...
167 On build, a file ``build-info.json`` (in the ``json`` format) will be written to
168 the root of the build directory.
171 The format and fields of the generated build information is currently
172 experimental. In the future we might add or remove fields, depending
173 on the needs of other tooling.
178 "cabal-lib-version": "<cabal lib version>",
180 "flavour": "<compiler name>",
181 "compiler-id": "<compiler id>",
182 "path": "<absolute path of the compiler>"
186 "type": "<component type, e.g. lib | bench | exe | flib | test>",
187 "name": "<component name>",
188 "unit-id": "<unitid>",
190 "<compiler args necessary for compilation>"
193 "<modules in this component>"
196 "<source files relative to hs-src-dirs>"
199 "<source directories of this component>"
201 "src-dir": "<root directory of this component>",
202 "cabal-file": "<cabal file location>"
207 .. jsonschema:: ./json-schemas/build-info.schema.json
209 .. option:: --disable-build-info
211 (default) Do not generate detailed build information for built components.
213 Already generated `build-info.json` files will be removed since they would be stale otherwise.
218 A cabal command target can take any of the following forms:
220 - A package target: ``[pkg:]package``, which specifies that all enabled
221 components of a package to be built. By default, test suites and
222 benchmarks are *not* enabled, unless they are explicitly requested
223 (e.g., via ``--enable-tests``.)
225 - A component target: ``[package:][ctype:]component``, which specifies
226 a specific component (e.g., a library, executable, test suite or
227 benchmark) to be built.
229 - All packages: ``all``, which specifies all packages within the project.
231 - Components of a particular type: ``package:ctypes``, ``all:ctypes``:
232 which specifies all components of the given type. Where valid
235 - ``libs``, ``libraries``,
236 - ``flibs``, ``foreign-libraries``,
237 - ``exes``, ``executables``,
239 - ``benches``, ``benchmarks``.
241 - A module target: ``[package:][ctype:]module``, which specifies that the
242 component of which the given module is a part of will be built.
244 - A filepath target: ``[package:][ctype:]filepath``, which specifies that the
245 component of which the given filepath is a part of will be built.
247 - A script target: ``path/to/script``, which specifies the path to a script
248 file. This is supported by ``build``, ``repl``, ``run``, and ``clean``.
249 Script targets are not part of a package.
251 .. _command-group-global:
259 ``cabal user-config [init|diff|update]`` prints and updates user's global
260 cabal preferences. It is very useful when you are e.g. first configuring
261 ``cabal`` on a new machine.
263 - ``cabal user-config init`` creates a new configuration file.
265 .. option:: --config-file=PATH
267 Specify config file path. (default: ``~/.cabal/config``).
269 .. option:: -f, --force
271 Force configuration file overwriting if already exists.
273 - ``cabal user-config diff`` prints a diff of the user's config file and the
276 - ``cabal user-config update`` updates the user's config file with additional
279 .. option:: -a CONFIGLINE or -aCONFIGLINE, --augment=CONFIGLINE
281 Pass additional configuration lines to be incorporated in the
283 ``cabal user-config update --augment="offline: True"``.
285 Note how ``--augment`` syntax follows ``cabal user-config diff``
291 ``cabal path`` allows to query for paths used by ``cabal``.
292 For example, it allows to query for the directories of the cache, store,
293 installed binaries, and so on.
298 cache-home: /home/haskell/.cache/cabal/
299 remote-repo-cache: /home/haskell/.cache/cabal/packages
300 logs-dir: /home/haskell/.cache/cabal/logs
301 store-dir: /home/haskell/.local/state/cabal/store
302 config-file: /home/haskell/.config/cabal/config
303 installdir: /home/haskell/.local/bin
306 Or using the json output:
310 $ cabal path --output-format=json
315 "cabal-version": "3.11.0.0",
319 "path": "/home/user/.ghcup/bin/ghc"
321 "cache-home": "/home/user/.cabal",
322 "remote-repo-cache": "/home/user/.cabal/packages",
323 "logs-dir": "/home/user/.cabal/logs",
324 "store-dir": "/home/user/.cabal/store",
325 "config-file": "/home/user/.cabal/config",
326 "installdir": "/home/user/.cabal/bin"
329 If ``cabal path`` is passed a single option naming a path, then that
330 path will be printed *without* any label:
334 $ cabal path --installdir
335 /home/haskell/.local/bin
337 While this interface is intended to be used for scripting, it is an experimental command.
341 $ ls $(cabal path --installdir)
344 .. _command-group-database:
346 Package database commands
347 -------------------------
352 ``cabal update`` updates the state of the package index. If the
353 project contains multiple remote package repositories it will update
354 the index of all of them (e.g. when using overlays).
360 $ cabal update # update all remote repos
361 $ cabal update head.hackage # update only head.hackage
366 ``cabal list [FLAGS] STRINGS`` lists all packages matching a search string.
368 .. option:: --installed
370 Only output installed packages.
372 .. option:: --simple-output
374 Print matching packages in a one-package-one-line format.
376 .. option:: -i, --ignore-case
378 .. option:: -I, --strict-case
380 .. option:: --package-db=DB
382 Append the given package database to the list of used package
383 databases. See `cabal info`_ for a thorough explanation.
385 .. option:: -w PATH or -wPATH, --with-compiler=PATH
387 Path to specific compiler.
392 ``cabal info [FLAGS] PACKAGES`` displays useful informations about remote
395 .. option:: --package-db=DB
397 Append the given package database to the list of package databases
398 used (to satisfy dependencies and register into). May be a specific
399 file, ``global`` or ``user``. The initial list is ``['global'], ['global',
400 'user']``, depending on context. Use ``clear`` to reset the list to empty.
402 .. _command-group-init:
404 Initialization and download
405 ---------------------------
410 ``cabal init [FLAGS]`` initialises a Cabal package, picking
411 reasonable defaults. Run it in your project folder.
413 .. option:: -i, --interactive
415 Enable interactive mode.
417 .. option:: -m, --minimal
419 Generate a short .cabal file, without extra empty fields or
420 explanatory comments.
422 See :ref:`init quickstart` for an overview on the command, and
423 ``cabal init --help`` for the complete list of options.
428 *☞ N.B.:* ``cabal fetch`` only works for legacy ``v1-`` commands and only
429 for single package projects. If you are not maintaining an old project,
430 `cabal build`_ with ``--only-download`` has similar effects to ``fetch``
431 and benefits from compatibility with newer build methods.
433 ``cabal fetch [FLAGS] PACKAGES`` downloads packages for later installation.
434 It fetches the project plus its dependencies, very useful when
435 e.g. you plan to work on a project with unreliable or no internet access.
437 .. option:: --no-dependencies
441 .. option:: --disable-tests
443 Disable dependency checking and compilation
444 for test suites listed in the package
447 .. option:: --disable-benchmarks
449 Disable dependency checking and compilation
450 for benchmarks listed in the package
453 Check ``cabal fetch --help`` for a complete list of options.
458 ``cabal get [FLAGS] [PACKAGES]`` (synonym: ``cabal unpack``) downloads and unpacks
459 the source code of ``PACKAGES`` locally. By default the content of the
460 packages is unpacked in the current working directory, in named subfolders
461 (e.g. ``./filepath-1.2.0.8/``), use ``--destdir=PATH`` to specify another
462 folder. By default the latest version of the package is downloaded, you can
463 ask for a spefic one by adding version numbers
464 (``cabal get random-1.0.0.1``).
466 The ``cabal get`` command supports the following options:
468 .. option:: -s[[head|this|...]], --source-repository[=[head|this|...]]
470 Clone the package's source repository (Darcs, Git, etc.)
471 instead of downloading the tarball. Only works if the
472 package specifies a ``source-repository``.
474 .. option:: --index-state=STATE
476 Pin your request to a specific Hackage index state. Available
477 ``STATE`` formats: Unix timestamps (e.g. ``@1474732068``),
478 ISO8601 UTC timestamps (e.g. ``2016-09-24T17:47:48Z``), or ``HEAD``
480 This determines which package versions are available as well as which
481 ``.cabal`` file revision is selected (unless ``--pristine`` is used).
483 .. option:: --pristine
485 Unpacks the pristine tarball, i.e. disregarding any Hackage revision.
487 .. option:: -d, --destdir=PATH
489 Where to place the package source, defaults to (a subdirectory of)
490 the current directory.
492 .. option:: --only-package-description, --package-description-only
494 Unpack the original pristine tarball, rather than updating the
495 ``.cabal`` file with the latest revision from the package archive.
498 .. _command-group-config:
500 Project configuration
501 ---------------------
506 ``cabal configure`` takes a set of arguments and writes a
507 ``cabal.project.local`` file based on the flags passed to this command.
508 ``cabal configure FLAGS; cabal build`` is roughly equivalent to
509 ``cabal build FLAGS``, except that with ``configure`` the flags
510 are persisted to all subsequent calls to ``build``.
512 ``cabal configure`` is intended to be a convenient way to write out
513 a ``cabal.project.local`` for simple configurations; e.g.,
514 ``cabal configure -w ghc-7.8`` would ensure that all subsequent
515 builds with ``cabal build`` are performed with the compiler
516 ``ghc-7.8``. For more complex configuration, we recommend writing the
517 ``cabal.project.local`` file directly (or placing it in
520 ``cabal configure`` inherits options from ``Cabal``. semantics:
522 - Any flag accepted by ``./Setup configure``.
524 - Any flag accepted by ``cabal configure`` beyond
525 ``./Setup configure``, namely ``--cabal-lib-version``,
526 ``--constraint``, ``--preference`` and ``--solver.``
528 - Any flag accepted by ``cabal install`` beyond ``./Setup configure``.
530 - Any flag accepted by ``./Setup haddock``.
532 The options of all of these flags apply only to *local* packages in a
533 project; this behavior is different than that of ``cabal install``,
534 which applies flags to every package that would be built. The motivation
535 for this is to avoid an innocuous addition to the flags of a package
536 resulting in a rebuild of every package in the store (which might need
537 to happen if a flag actually applied to every transitive dependency). To
538 apply options to an external package, use a ``package`` stanza in a
539 ``cabal.project`` file.
541 There are two ways of modifying the ``cabal.project.local`` file through
542 ``cabal configure``, either by appending new configurations to it, or
543 by simply overwriting it all. Overwriting is the default behaviour, as
544 such, there's a flag ``--enable-append`` to append the new configurations
545 instead. Since overwriting is rather destructive in nature, a backup system
546 is in place, which moves the old configuration to a ``cabal.project.local~``
547 file, this feature can also be disabled by using the ``--disable-backup``
553 If a package is built in several different environments, such as a
554 development environment, a staging environment and a production
555 environment, it may be necessary or desirable to ensure that the same
556 dependency versions are selected in each environment. This can be done
557 with the ``freeze`` command:
559 ``cabal freeze`` writes out a **freeze file** which records all of
560 the versions and flags that are picked by the solver under the
561 current index and flags. Default name of this file is
562 ``cabal.project.freeze`` but in combination with a
563 ``--project-file=my.project`` flag (see :ref:`project-file
564 <cmdoption-project-file>`)
565 the name will be ``my.project.freeze``.
566 A freeze file has the same syntax as ``cabal.project`` and looks
573 constraints: HTTP ==4000.3.3,
574 HTTP +warp-tests -warn-as-error -network23 +network-uri -mtl1 -conduit10,
576 QuickCheck +templatehaskell,
580 For end-user executables, it is recommended that you distribute the
581 ``cabal.project.freeze`` file in your source repository so that all
582 users see a consistent set of dependencies. For libraries, this is not
583 recommended: users often need to build against different versions of
584 libraries than what you developed against.
589 ``cabal gen-bounds [FLAGS]`` generates bounds for all dependencies that do not
590 currently have them. Generated bounds are printed to stdout. You can then
591 paste them into your .cabal file.
592 The generated bounds conform to the `Package Versioning Policy`_, which is
593 a recommended versioning system for publicly released Cabal packages.
595 .. code-block:: console
599 For example, given the following dependencies without bounds specified in
600 :pkg-field:`build-depends`:
609 ``gen-bounds`` might suggest changing them to the following:
614 base >= 4.15.0 && < 4.16,
615 mtl >= 2.2.2 && < 2.3,
616 transformers >= 0.5.6 && < 0.6,
622 ``cabal outdated [FLAGS]`` checks for outdated dependencies in the package
623 description file or freeze file.
625 Manually updating dependency version bounds in a ``.cabal`` file or a
626 freeze file can be tedious, especially when there's a lot of
627 dependencies. The ``cabal outdated`` command is designed to help with
628 that. It will print a list of packages for which there is a new
629 version on Hackage that is outside the version bound specified in the
630 ``build-depends`` field. The ``outdated`` command can also be
631 configured to act on the freeze file and
632 ignore major (or all) version bumps on Hackage for a subset of
637 .. code-block:: console
641 Outdated dependencies:
642 haskell-src-exts <1.17 (latest: 1.19.1)
643 language-javascript <0.6 (latest: 0.6.0.9)
644 unix ==2.7.2.0 (latest: 2.7.2.1)
646 $ cabal outdated --simple-output
651 $ cabal outdated --ignore=haskell-src-exts
652 Outdated dependencies:
653 language-javascript <0.6 (latest: 0.6.0.9)
654 unix ==2.7.2.0 (latest: 2.7.2.1)
656 $ cabal outdated --ignore=haskell-src-exts,language-javascript,unix
657 All dependencies are up to date.
659 $ cabal outdated --ignore=haskell-src-exts,language-javascript,unix -q
663 $ cd /some/other/package
664 $ cabal outdated --freeze-file
665 Outdated dependencies:
666 HTTP ==4000.3.3 (latest: 4000.3.4)
667 HUnit ==1.3.1.1 (latest: 1.5.0.0)
669 $ cabal outdated --freeze-file --ignore=HTTP --minor=HUnit
670 Outdated dependencies:
671 HUnit ==1.3.1.1 (latest: 1.3.1.2)
674 ``cabal outdated`` supports the following flags:
676 .. option:: --freeze-file
678 Read dependency version bounds from the freeze file.
680 (``cabal.config``) instead of the package description file
681 (``$PACKAGENAME.cabal``).
683 .. option:: --v2-freeze-file
687 Read dependency version bounds from the v2-style freeze file
688 (by default, ``cabal.project.freeze``) instead of the package
689 description file. ``--new-freeze-file`` is an alias for this flag
690 that can be used with pre-2.4 ``cabal``.
692 .. option:: --project-file=FILE
696 Read dependency version bounds from the v2-style freeze file
697 related to the named project file (i.e., ``$PROJECTFILE.freeze``)
698 instead of the package description file. If multiple ``--project-file``
699 flags are provided, only the final one is considered. This flag
700 must only be passed in when ``--new-freeze-file`` is present.
702 .. option:: --simple-output
704 Print only the names of outdated dependencies, one per line.
706 .. option:: --exit-code
708 Exit with a non-zero exit code when there are outdated dependencies.
710 .. option:: -q, --quiet
712 Don't print any output. Implies ``-v0`` and ``--exit-code``.
714 .. option:: --ignore=PKGS
716 Don't warn about outdated dependency version bounds for the packages in this list.
718 .. option:: --minor[PKGS]
720 Ignore major version bumps for these packages.
722 E.g. if there's a version 2.0 of a package ``pkg`` on Hackage and the freeze
723 file specifies the constraint ``pkg == 1.9``, ``cabal outdated --freeze
724 --minor=pkg`` will only consider the ``pkg`` outdated when there's a version
725 of ``pkg`` on Hackage satisfying ``pkg > 1.9 && < 2.0``. ``--minor`` can also
726 be used without arguments, in that case major version bumps are ignored for
729 .. _command-group-build:
731 Project building and installing
732 -------------------------------
737 ``cabal build`` takes a set of targets and builds them. It
738 automatically handles building and installing any dependencies of these
741 In component targets, ``package:`` and ``ctype:`` (valid component types
742 are ``lib``, ``flib``, ``exe``, ``test`` and ``bench``) can be used to
743 disambiguate when multiple packages define the same component, or the
744 same component name is used in a package (e.g., a package ``foo``
745 defines both an executable and library named ``foo``). We always prefer
746 interpreting a target as a package name rather than as a component name.
748 Some example targets:
752 $ cabal build lib:foo-pkg # build the library named foo-pkg
753 $ cabal build foo-pkg:foo-tests # build foo-tests in foo-pkg
754 $ cabal build src/Lib.s # build the library component to
755 # which "src/Lib.hs" belongs
756 $ cabal build app/Main.hs # build the executable component of
758 $ cabal build Lib # build the library component to
759 # which the module "Lib" belongs
760 $ cabal build path/to/script # build the script as an executable
762 Beyond a list of targets, ``cabal build`` accepts all the flags that
763 ``cabal configure`` takes. Most of these flags are only taken into
764 consideration when building local packages; however, some flags may
765 cause extra store packages to be built (for example,
766 ``--enable-profiling`` will automatically make sure profiling libraries
767 for all transitive dependencies are built and installed.)
769 When building a script, the executable is cached under the cabal directory.
770 See ``cabal run`` for more information on scripts.
772 In addition ``cabal build`` accepts these flags:
774 .. option:: --only-configure
776 When given we will forego performing a full build and abort after running
777 the configure phase of each target package.
782 ``cabal install [FLAGS] [TARGETS]`` builds the specified target packages and
783 symlinks/copies their executables in ``installdir`` (usually ``~/.local/bin``).
787 If not every package has an executable to install, use ``all:exes`` rather
788 than ``all`` as the target. To overwrite an installation, use
789 ``--overwrite-policy=always`` as the default policy is ``never``.
791 For example this command will build the latest ``cabal-install`` and symlink
792 its ``cabal`` executable:
796 $ cabal install cabal-install
798 In addition, it's possible to use ``cabal install`` to install components
799 of a local project. For example, with an up-to-date Git clone of the Cabal
800 repository, this command will build cabal-install HEAD and symlink the
801 ``cabal`` executable:
805 $ cabal install exe:cabal
807 Where symlinking is not possible (eg. on some Windows versions) the ``copy``
808 method is used by default. You can specify the install method
809 by using ``--install-method`` flag:
813 $ cabal install exe:cabal --install-method=copy --installdir=$HOME/bin
815 Note that copied executables are not self-contained, since they might use
816 data-files from the store.
818 .. _adding-libraries:
820 Adding libraries to GHC package environments
821 """"""""""""""""""""""""""""""""""""""""""""
823 It is also possible to "install" libraries using the ``--lib`` flag. For
824 example, this command will build the latest Cabal library and install it:
828 $ cabal install --lib Cabal
830 This works by managing GHC package environment files. By default, it is writing
831 to the global environment in ``~/.ghc/$ARCH-$OS-$GHCVER/environments/default``.
832 ``install`` provides the ``--package-env`` flag to control which of these
833 environments is modified.
835 This command will modify the environment file in the current directory:
839 $ cabal install --lib Cabal --package-env .
841 This command will modify the environment file in the ``~/foo`` directory:
845 $ cabal install --lib Cabal --package-env foo/
847 Do note that the results of the previous two commands will be overwritten by
848 the use of other style commands, so it is not recommended to use them inside
851 This command will modify the environment in the ``local.env`` file in the
856 $ cabal install --lib Cabal --package-env local.env
858 This command will modify the ``myenv`` named global environment:
862 $ cabal install --lib Cabal --package-env myenv
864 If you wish to create a named environment file in the current directory where
865 the name does not contain an extension, you must reference it as ``./myenv``.
867 You can learn more about how to use these environments in `this section of the
868 GHC manual <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/packages.html#package-environments>`_.
873 ``cabal haddock [FLAGS] [TARGET]`` builds Haddock documentation for
874 the specified packages within the project.
876 If a target is not a library :cfg-field:`haddock-benchmarks`,
877 :cfg-field:`haddock-executables`, :cfg-field:`haddock-internal`,
878 :cfg-field:`haddock-tests` will be implied as necessary.
880 cabal haddock-project
881 ^^^^^^^^^^^^^^^^^^^^^
883 ``cabal haddock-project [FLAGS]`` builds Haddock documentation for all local
884 packages specified in the project.
886 By default the documentation will be put in ``./haddocks`` folder, this can be
887 modified with the ``--output`` flag.
889 This command supports two primary modes: building a self contained directory
890 (which is the default mode) or documentation that links to hackage (with
893 In both cases the html index as well as quickjump index will include all terms
894 and types defined in any of the local packages, but not ones that are included
895 in any of the dependencies. But note that if you navigate to a dependency,
896 you will have access to its quickjump index.
898 The generated landing page will contain one tree of all modules per local
904 ``cabal clean [FLAGS]`` cleans up the temporary files and build artifacts
905 stored in the ``dist-newstyle`` folder.
907 By default, it removes the entire folder, but it can also spare the configuration
908 and caches if the ``--save-config`` option is given, in which case it only removes
909 the build artefacts (``.hi``, ``.o`` along with any other temporary files generated
910 by the compiler, along with the build output).
912 ``cabal clean [FLAGS] path/to/script`` cleans up the temporary files and build
913 artifacts for the script, which are stored under the .cabal/script-builds directory.
915 In addition when clean is invoked it will remove all script build artifacts for
916 which the corresponding script no longer exists.
918 .. _command-group-run:
926 ``cabal list-bin`` will either (a) display the path for a single executable or (b)
927 complain that the target doesn't resolve to a single binary. In the latter case,
928 it will name the binary products contained in the package. These products can
929 be used to narrow the search and get an actual path to a particular executable.
931 Example showing a failure to resolve to a single executable.
935 $ cabal list-bin cabal-install
936 cabal: The list-bin command is for finding a single binary at once. The
937 target 'cabal-install' refers to the package cabal-install-#.#.#.# which
938 includes the executable 'cabal', the test suite 'unit-tests', the test suite
939 'mem-use-tests', the test suite 'long-tests' and the test suite
940 'integration-tests2'.
942 For a scope that results in only one item we'll get a path.
946 $ cabal list-bin cabal-install:exes
947 /.../dist-newstyle/build/.../cabal/cabal
949 $ cabal list-bin cabal-install:cabal
950 /.../dist-newstyle/build/.../cabal/cabal
952 We can also scope to test suite targets as they produce binaries.
956 $ cabal list-bin cabal-install:tests
957 cabal: The list-bin command is for finding a single binary at once. The
958 target 'cabal-install:tests' refers to the test suites in the package
959 cabal-install-#.#.#.# which includes the test suite 'unit-tests', the test
960 suite 'mem-use-tests', the test suite 'long-tests' and the test suite
961 'integration-tests2'.
963 $ cabal list-bin cabal-install:unit-tests
964 /.../dist-newstyle/.../unit-tests/unit-tests
966 Note that ``cabal list-bin`` will print the executables' location, but
967 will not make sure that these executables actually exist (i.e., have
968 been successfully built). In order to determine the correct location,
969 it may invoke the configuration step (see ``cabal configure``).
974 ``cabal repl TARGET [FLAGS]``
975 opens an interactive session for the target component within the project and
976 loads all of the modules of the target into GHCi as interpreted bytecode.
977 The available targets are the same as for the ``build`` command: individual components
978 within packages in the project, including libraries, executables, test-suites
979 and benchmarks (see `the build section <#cabal-build>`__ for the target syntax).
980 Local packages can also be specified, in which case the library
981 component in the package will be used, or the (first listed) executable in the
982 package if there is no library. Dependencies are built or rebuilt as necessary.
988 $ cabal repl # default component in the package in the current directory
989 $ cabal repl pkgname # default component in the package named 'pkgname'
990 $ cabal repl ./pkgfoo # default component in the package in the ./pkgfoo directory
991 $ cabal repl cname # component named 'cname'
992 $ cabal repl pkgname:cname # component 'cname' in the package 'pkgname'
994 Configuration flags can be specified on the command line and these extend the project
995 configuration from the 'cabal.project', 'cabal.project.local' and other files.
997 .. option:: --repl-options=FLAG
999 To avoid ``ghci``-specific flags from triggering unneeded global rebuilds, these
1000 flags are stripped from the internal configuration. As a result,
1001 ``--ghc-options`` will no longer (reliably) work to pass flags to ``ghci`` (or
1002 other REPLs). Instead, you should use the ``--repl-options`` flag to
1003 specify these options to the invoked REPL.
1005 .. option:: --repl-no-load
1007 Disables the loading of target modules at startup.
1009 .. option:: -b DEPENDENCIES or -bDEPENDENCIES, --build-depends=DEPENDENCIES
1011 A way to experiment with libraries without needing to download
1012 them manually or to install them globally.
1014 This command opens a REPL with the current default target loaded, and a version
1015 of the ``vector`` package matching that specification exposed.
1019 $ cabal repl --build-depends="vector >= 0.12 && < 0.13"
1021 Both of these commands do the same thing as the above, but only expose ``base``,
1022 ``vector``, and the ``vector`` package's transitive dependencies even if the user
1023 is in a project context.
1027 $ cabal repl --ignore-project --build-depends="vector >= 0.12 && < 0.13"
1028 $ cabal repl --project='' --build-depends="vector >= 0.12 && < 0.13"
1030 This command would add ``vector``, but not (for example) ``primitive``, because
1031 it only includes the packages specified on the command line (and ``base``, which
1032 cannot be excluded for technical reasons).
1036 $ cabal repl --build-depends=vector --no-transitive-deps
1038 ``cabal repl`` can open scripts by passing the path to the script as the target.
1042 $ cabal repl path/to/script
1044 The configuration information for the script is cached under the cabal directory
1045 and can be pre-built with ``cabal build path/to/script``.
1046 See ``cabal run`` for more information on scripts.
1048 .. option:: --enable-multi-repl
1050 Allow starting GHCi with multiple targets.
1051 This requires GHC with multiple home unit support (GHC-9.4+)
1053 The closure of required components will be loaded.
1055 .. option:: --disable-multi-repl
1057 Disallow starting GHCi with multiple targets. This reverts back to the behaviour
1058 in version 3.10 and earlier where only a single component can be loaded at
1066 ``cabal run [TARGET] [FLAGS] [-- EXECUTABLE_FLAGS]`` runs the executable
1067 specified by the target, which can be a component, a package or can be left
1068 blank, as long as it can uniquely identify an executable within the project.
1069 Tests and benchmarks are also treated as executables.
1071 See `the build section <#cabal-build>`__ for the target syntax.
1073 When ``TARGET`` is one of the following:
1075 - A component target: execute the specified executable, benchmark or test suite.
1078 1. If the package has exactly one executable component, it will be selected.
1079 2. If the package has multiple executable components, an error is raised.
1080 3. If the package has exactly one test or benchmark component, it will be selected.
1081 4. Otherwise an issue is raised.
1083 - The path to a script: execute the script at the path.
1085 - Empty target: Same as package target, implicitly using the package from the current
1088 Except in the case of the empty target, the strings after it will be
1089 passed to the executable as arguments.
1091 If one of the arguments starts with ``-`` it will be interpreted as
1092 a cabal flag, so if you need to pass flags to the executable you
1093 have to separate them with ``--``.
1097 $ cabal run target -- -a -bcd --argument
1099 ``run`` supports running script files that use a certain format.
1104 #!/usr/bin/env cabal
1106 build-depends: base ^>= 4.14
1110 with-compiler: ghc-8.10.7
1117 Where there cabal metadata block is mandatory and contains fields from a
1118 package executable block, and the project metadata block is optional and
1119 contains fields that would be in the cabal.project file in a regular project.
1121 Only some fields are supported in the metadata blocks, and these fields are
1122 currently not validated. See
1123 `#8024 <https://github.com/haskell/cabal/issues/8024>`__ for details.
1125 A script can either be executed directly using `cabal` as an interpreter or
1130 $ cabal run path/to/script
1132 The executable is cached under the cabal directory, and can be pre-built with
1133 ``cabal build path/to/script`` and the cache can be removed with
1134 ``cabal clean path/to/script``.
1136 A note on targets: Whenever a command takes a script target and it matches the
1137 name of another target, the other target is preferred. To load the script
1138 instead pass it as an explicit path: ./script
1140 By default, scripts are run at silent verbosity (``--verbose=0``). To show the
1141 build output for a script either use the command
1145 $ cabal run --verbose=n path/to/script
1147 or the interpreter line
1151 #!/usr/bin/env -S cabal run --verbose=n
1153 For more information see :cfg-field:`verbose`
1158 ``cabal bench [TARGETS] [FLAGS]`` runs the specified benchmarks
1159 (all the benchmarks in the current package by default), first ensuring
1160 they are up to date.
1162 ``cabal bench`` inherits flags of the ``bench`` subcommand of ``Setup.hs``,
1163 :ref:`see the corresponding section <setup-bench>`.
1168 ``cabal test [TARGETS] [FLAGS]`` runs the specified test suites
1169 (all the test suites in the current package by default), first ensuring
1170 they are up to date.
1172 ``cabal test`` inherits flags of the ``test`` subcommand of ``Setup.hs``
1173 (:ref:`see the corresponding section <setup-test>`) with one caveat: every
1174 ``Setup.hs test`` flag receives the ``test-`` prefix if it already does
1175 not have one; e.g. ``--show-details`` becomes ``--test-show-details`` but
1176 ``--test-wrapper`` remains the same.
1181 ``cabal exec [FLAGS] [--] COMMAND [--] [ARGS]`` runs the specified command
1182 using the project's environment. That is, passing the right flags to compiler
1183 invocations and bringing the project's executables into scope.
1185 .. _command-group-ship:
1187 Sanity checks and shipping
1188 --------------------------
1193 ``cabal check [FLAGS]`` checks the package for common mistakes (e.g.: if
1194 it is missing important fields like ``synopsis``, if it is using
1195 tricky GHC options, etc.).
1197 Run ``cabal check`` in the folder where your ``.cabal`` package file is.
1199 .. option:: -i, --ignore=WARNING
1201 Ignore a specific type of warning (e.g. ``--ignore=missing-upper-bounds``).
1202 Check the list of warnings for which constructor to use.
1204 .. option:: -v[n], --verbose[=n]
1206 Control verbosity (n is 0--3, default verbosity level is 1).
1208 Issues are classified as ``Warning``\s and ``Error``\s. The latter correspond
1209 to Hackage requirements for uploaded packages: if no error is reported,
1210 Hackage should accept your package. If errors are present ``cabal check``
1211 exits with ``1`` and Hackage will refuse the package.
1213 A list of all warnings with their constructor:
1215 - ``parser-warning``: inherited from parser.
1216 - ``no-name-field``: missing ``name`` field.
1217 - ``no-version-field``: missing ``version`` field.
1218 - ``no-target``: missing target in ``.cabal``.
1219 - ``unnamed-internal-library``: unnamed internal library.
1220 - ``duplicate-sections``: duplicate name in target.
1221 - ``illegal-library-name``: internal library with same name as package.
1222 - ``no-modules-exposed``: no module exposed in library.
1223 - ``signatures``: ``signatures`` used with ``cabal-version`` < 2.0.
1224 - ``autogen-not-exposed``: ``autogen-module`` neither in ``exposed-modules`` nor ``other-modules``.
1225 - ``autogen-not-included``: ``autogen-include`` neither in ``include`` nor ``install-includes``.
1226 - ``no-main-is``: missing ``main-is``.
1227 - ``unknown-extension-main``: ``main-is`` is not ``.hs`` nor ``.lhs``.
1228 - ``c-like-main``: C-like source file in ``main-is`` with ``cabal-version`` < 1.18.
1229 - ``autogen-other-modules``: ``autogen-module`` not in ``other-modules``.
1230 - ``autogen-exe``: ``autogen-include`` not in ``includes``.
1231 - ``unknown-testsuite-type``: unknown test-suite type.
1232 - ``unsupported-testsuite``: unsupported test-suite type.
1233 - ``unknown-bench``: unknown benchmark type.
1234 - ``unsupported-bench``: unsupported benchmark type.
1235 - ``bench-unknown-extension``: ``main-is`` for benchmark is neither ``.hs`` nor ``.lhs``.
1236 - ``invalid-name-win``: invalid package name on Windows.
1237 - ``reserved-z-prefix``: package with ``z-`` prexif (reseved for Cabal.
1238 - ``no-build-type``: missing ``build-type``.
1239 - ``undeclared-custom-setup``: ``custom-setup`` section without ``build-type: Custom``
1240 - ``unknown-compiler-tested``: unknown compiler in ``tested-with``.
1241 - ``unknown-languages``: unknown languages.
1242 - ``unknown-extension``: unknown extensions.
1243 - ``languages-as-extensions``: languages listed as extensions.
1244 - ``deprecated-extensions``: deprecated extensions.
1245 - ``no-category``: missing ``category`` field.
1246 - ``no-maintainer``: missing ``maintainer`` field.
1247 - ``no-synopsis``: missing ``synopsis`` field.
1248 - ``no-description``: missing ``description`` field.
1249 - ``no-syn-desc``: missing ``synopsis`` or ``description`` field.
1250 - ``long-synopsis``: ``synopsis`` longer than 80 characters.
1251 - ``short-description``: ``description`` shorter than ``synopsis``.
1252 - ``invalid-range-tested``: invalid ``tested-with`` version range.
1253 - ``impossible-dep``: impossible internal library version range dependency.
1254 - ``impossible-dep-exe``: impossible internal executable version range dependency.
1255 - ``no-internal-exe``: missing internal executable.
1256 - ``license-none``: ``NONE`` in ``license`` field.
1257 - ``no-license``: no ``license`` field.
1258 - ``all-rights-reserved``: “All rights reserved” license.
1259 - ``license-parse``: license not to be used with ``cabal-version`` < 1.4.
1260 - ``unknown-license``: unknown license.
1261 - ``bsd4-license``: uncommon BSD (BSD4) license.
1262 - ``unknown-license-version``: unknown license version.
1263 - ``no-license-file``: missing license file.
1264 - ``unrecognised-repo-type``: unrecognised kind of source-repository.
1265 - ``repo-no-type``: missing ``type`` in ``source-repository``.
1266 - ``repo-no-location``: missing ``location`` in ``source-repository``.
1267 - ``repo-no-module``: missing ``module`` in ``source-repository``.
1268 - ``repo-no-tag``: missing ``tag`` in ``source-repository``.
1269 - ``repo-relative-dir``: ``subdir`` in ``source-repository`` must be relative.
1270 - ``repo-malformed-subdir``: malformed ``subdir`` in ``source-repository``.
1271 - ``option-fasm``: unnecessary ``-fasm``.
1272 - ``option-fhpc``: unnecessary ``-fhpc``.
1273 - ``option-prof``: unnecessary ``-prof``.
1274 - ``option-o``: unnecessary ``-o``.
1275 - ``option-hide-package``: unnecessary ``-hide-package``.
1276 - ``option-make``: unnecessary ``--make``.
1277 - ``option-optimize``: unnecessary disable optimization flag.
1278 - ``option-o1``: unnecessary optimisation flag (``-O1``).
1279 - ``option-o2``: unnecessary optimisation flag (``-O2``).
1280 - ``option-split-section``: unnecessary ``-split-section``.
1281 - ``option-split-objs``: unnecessary ``-split-objs``.
1282 - ``option-optl-wl``:unnecessary ``-optl-Wl,-s``.
1283 - ``use-extension``: use ``extension`` field instead of ``-fglasgow-exts``.
1284 - ``option-rtsopts``: unnecessary ``-rtsopts``.
1285 - ``option-with-rtsopts``: unnecessary ``-with-rtsopts``.
1286 - ``option-opt-c``: unnecessary ``-O[n]`` in C code.
1287 - ``cpp-options``: unportable ``-cpp-options`` flag.
1288 - ``misplaced-c-opt``: C-like options in wrong cabal field.
1289 - ``relative-path-outside``: relative path outside of source tree.
1290 - ``absolute-path``: absolute path where not allowed.
1291 - ``malformed-relative-path``: malformed relative path.
1292 - ``unreliable-dist-path``: unreliable path pointing inside ``dist``.
1293 - ``glob-syntax-error``: glob syntax error.
1294 - ``recursive-glob``: recursive glob including source control folders.
1295 - ``invalid-path-win``: invalid path on Windows.
1296 - ``long-path``: path too long (POSIX, 255 ASCII chars).
1297 - ``long-name``: path *name* too long (POSIX, 100 ASCII chars).
1298 - ``name-not-portable``: path non portable (POSIX, split requirements).
1299 - ``empty-path``: empty path.
1300 - ``test-cabal-ver``: ``test-suite`` used with ``cabal-version`` < 1.10.
1301 - ``default-language``: ``default-language`` used with ``cabal-version`` < 1.10.
1302 - ``no-default-language``: missing ``default-language``.
1303 - ``extra-doc-files``: ``extra-doc-files`` used with ``cabal-version`` < 1.18.
1304 - ``multilib``: multiple ``library`` sections with ``cabal-version`` < 2.0.
1305 - ``reexported-modules``: ``reexported-modules`` with ``cabal-version`` < 1.22.
1306 - ``mixins``: ``mixins`` with ``cabal-version`` < 2.0.
1307 - ``extra-framework-dirs``: ``extra-framework-dirs`` with ``cabal-version`` < 1.24.
1308 - ``default-extensions``: ``default-extensions`` with ``cabal-version`` < 1.10.
1309 - ``extensions-field``: deprecated ``extensions`` field used with ``cabal-version`` ≥ 1.10
1310 - ``unsupported-sources``: ``asm-sources``, ``cmm-sources``, ``extra-bundled-libraries`` or ``extra-library-flavours`` used with ``cabal-version`` < 3.0.
1311 - ``extra-dynamic``: ``extra-dynamic-library-flavours`` used with cabal-version < 3.0.
1312 - ``virtual-modules``: ``virtual-modules`` used with cabal-version < 2.2.
1313 - ``source-repository``: ``source-repository`` used with ``cabal-version`` 1.6.
1314 - ``incompatible-extension``: incompatible language extension with ``cabal-version``.
1315 - ``no-setup-depends``: missing ``setup-depends`` field in ``custom-setup`` with ``cabal-version`` ≥ 1.24.
1316 - ``dependencies-setup``: missing dependencies in ``custom-setup`` with ``cabal-version`` ≥ 1.24.
1317 - ``no-autogen-paths``: missing autogen ``Paths_*`` modules in ``autogen-modules`` (``cabal-version`` ≥ 2.0).
1318 - ``no-autogen-pinfo``: missing autogen ``PackageInfo_*`` modules in ``autogen-modules`` *and* ``exposed-modules``/``other-modules`` (``cabal-version`` ≥ 2.0).
1319 - ``no-glob-match``: glob pattern not matching any file.
1320 - ``glob-no-extension``: glob pattern not matching any file becuase of lack of extension matching (`cabal-version` < 2.4).
1321 - ``glob-missing-dir``: glob pattern trying to match a missing directory.
1322 - ``unknown-os``: unknown operating system name in condition.
1323 - ``unknown-arch``: unknown architecture in condition.
1324 - ``unknown-compiler``: unknown compiler in condition.
1325 - ``missing-bounds-important``: missing upper bounds for important dependencies (``base``, and for ``custom-setup`` ``Cabal`` too).
1326 - ``missing-upper-bounds``: missing upper bound in dependency (excluding test-suites and benchmarks).
1327 - ``suspicious-flag``: troublesome flag name (e.g. starting with a dash).
1328 - ``unused-flag``: unused user flags.
1329 - ``non-ascii``: non-ASCII characters in custom field.
1330 - ``rebindable-clash-paths``: ``Rebindable Syntax`` with ``OverloadedStrings``/``OverloadedStrings`` plus autogenerated ``Paths_*`` modules with ``cabal-version`` < 2.2.
1331 - ``rebindable-clash-info``: ``Rebindable Syntax`` with ``OverloadedStrings``/``OverloadedStrings`` plus autogenerated ``PackageInfo_*`` modules with ``cabal-version`` < 2.2.
1332 - ``werror``: ``-WError`` not under a user flag.
1333 - ``unneeded-j``: suspicious ``-j[n]`` usage.
1334 - ``fdefer-type-errors``: suspicious ``-fdefer-type-errors``.
1335 - ``debug-flag``: suspicious ``-d*`` debug flag for distributed package.
1336 - ``fprof-flag``: suspicious ``-fprof-*`` flag.
1337 - ``missing-bounds-setup``: missing upper bounds in ``setup-depends``.
1338 - ``duplicate-modules``: duplicate modules in target.
1339 - ``maybe-duplicate-modules``: potential duplicate module in target (subject to conditionals).
1340 - ``bom``: unicode byte order mark (BOM) character at start of file.
1341 - ``name-no-match``: filename not matching ``name``.
1342 - ``no-cabal-file``: no ``.cabal`` file found in folder.
1343 - ``multiple-cabal-file``: multiple ``.cabal`` files found in folder.
1344 - ``unknown-file``: path refers to a file which does not exist.
1345 - ``missing-setup``: missing ``Setup.hs`` or ``Setup.lsh``.
1346 - ``missing-conf-script``: missing ``configure`` script with ``build-type: Configure``.
1347 - ``unknown-directory``: paths refer to a directory which does not exist.
1348 - ``no-repository``: missing ``source-repository`` section.
1349 - ``no-docs``: missing expected documentation files (changelog).
1350 - ``doc-place``: documentation files listed in ``extra-source-files`` instead of ``extra-doc-files``.
1356 ``cabal sdist [FLAGS] [PACKAGES]`` takes the crucial files needed to build ``PACKAGES``
1357 and puts them into an archive format ready for upload to Hackage. These archives are stable
1358 and two archives of the same format built from the same source will hash to the same value.
1360 ``cabal sdist`` takes the following flags:
1362 .. option:: -l, --list-only
1364 Rather than creating an archive, lists files that would be included.
1366 Output is to ``stdout`` by default. The file paths are relative to the project's root
1369 .. option:: -o PATH or -oPATH, --output-directory=PATH
1371 Sets the output dir, if a non-default one is desired. The default is
1372 ``dist-newstyle/sdist/``. ``--output-directory -`` will send output to ``stdout``
1373 unless multiple archives are being created.
1375 .. option:: --null-sep
1377 Only used with ``--list-only``. Separates filenames with a NUL
1378 byte instead of newlines.
1380 ``sdist`` is inherently incompatible with sdist hooks (which were removed in `Cabal-3.0`),
1381 not due to implementation but due to fundamental core invariants
1382 (same source code should result in the same tarball, byte for byte)
1383 that must be satisfied for it to function correctly in the larger build ecosystem.
1384 ``autogen-modules`` is able to replace uses of the hooks to add generated modules, along with
1385 the custom publishing of Haddock documentation to Hackage.
1390 ``cabal upload [FLAGS] TARFILES`` uploads source packages or documentation
1393 .. option:: --publish
1395 Publish the package immediately instead of uploading it as a
1396 `package candidate <https://hackage.haskell.org/upload#candidates>`__
1397 (make sure everything is fine, you cannot delete published packages
1400 .. option:: -d, --documentation
1402 Upload documentation instead of a source package. To upload
1403 documentation for a published package (and not a candidate), add
1406 .. option:: -t TOKEN or -tTOKEN, --token=TOKEN
1408 Your Hackage authentication token. You can create and delete
1409 authentication tokens on Hackage's `account management page
1410 <https://hackage.haskell.org/users/account-management>`__.
1412 .. option:: -u USERNAME or -uUSERNAME, --username=USERNAME
1414 Your Hackage username.
1416 .. option:: -p PASSWORD or -pPASSWORD, --password=PASSWORD
1418 Your Hackage password.
1420 .. option:: -P COMMAND or -PCOMMAND, --password-command=COMMAND
1422 Command to get your Hackage password. Arguments with whitespace
1423 must be quoted (double-quotes only). For example:
1427 --password-command='sh -c "grep hackage ~/secrets | cut -d : -f 2"'
1429 Or in the config file:
1433 password-command: sh -c "grep hackage ~/secrets | cut -d : -f 2"
1439 ``cabal report [FLAGS]`` uploads build reports to Hackage.
1441 .. option:: -t TOKEN or -tTOKEN, --token=TOKEN
1443 Your Hackage authentication token. You can create and delete
1444 authentication tokens on Hackage's `account management page
1445 <https://hackage.haskell.org/users/account-management>`__.
1447 .. option:: -u USERNAME or -uUSERNAME, --username=USERNAME
1449 Your Hackage username.
1451 .. option:: -p PASSWORD or -pPASSWORD, --password=PASSWORD
1453 Your Hackage password.
1455 .. include:: references.inc