4 ``cabal help`` groups commands into global, package, new-style project and
5 legacy sections. We talk in detail about some global and package commands.
10 Command line interface to the Haskell Cabal infrastructure.
12 See http://www.haskell.org/cabal/ for more information.
14 Usage: cabal [GLOBAL FLAGS] [COMMAND [FLAGS]]
18 update Updates list of known packages.
19 install Install packages.
20 help Help about commands.
23 configure Add extra project configuration.
24 build Compile targets within the project.
25 clean Clean the package store and remove temporary files.
27 run Run an executable.
28 repl Open an interactive session for the given component.
32 sdist Generate a source distribution file (.tar.gz).
34 freeze Freeze dependencies.
35 haddock Build Haddock documentation.
36 haddock-project Build Haddock documentation of local packages.
37 exec Give a command access to the store.
38 list-bin List path to a single executable.
40 [new-style projects (forwards-compatible aliases)]
41 Since cabal-install-3.0.0.0, all 'v2-' prefixed names of commands are just aliases for the simple unprefixed names.
42 So v2-build is an alias for build, v2-install for install and so on.
44 [legacy command aliases]
45 No legacy commands are described.
47 Common Arguments and Flags
48 --------------------------
50 Arguments and flags common to some or all commands are:
53 .. option:: --default-user-config=file
55 Allows a "default" ``cabal.config`` freeze file to be passed in
56 manually. This file will only be used if one does not exist in the
57 project directory already. Typically, this can be set from the
58 global cabal ``config`` file so as to provide a default set of
59 partial constraints to be used by projects, providing a way for
60 users to peg themselves to stable package collections.
63 .. option:: --allow-newer[=pkgs], --allow-older[=pkgs]
65 Selectively relax upper or lower bounds in dependencies without
66 editing the package description respectively.
68 The following description focuses on upper bounds and the
69 :option:`--allow-newer` flag, but applies analogously to
70 :option:`--allow-older` and lower bounds. :option:`--allow-newer`
71 and :option:`--allow-older` can be used at the same time.
73 If you want to install a package A that depends on B >= 1.0 && <
74 2.0, but you have the version 2.0 of B installed, you can compile A
75 against B 2.0 by using ``cabal install --allow-newer=B A``. This
76 works for the whole package index: if A also depends on C that in
77 turn depends on B < 2.0, C's dependency on B will be also relaxed.
85 Resolving dependencies...
86 cabal: Could not resolve dependencies:
88 $ cabal configure --allow-newer
89 Resolving dependencies...
96 # Relax upper bounds in all dependencies.
97 $ cabal install --allow-newer foo
99 # Relax upper bounds only in dependencies on bar, baz and quux.
100 $ cabal install --allow-newer=bar,baz,quux foo
102 # Relax the upper bound on bar and force bar==2.1.
103 $ cabal install --allow-newer=bar --constraint="bar==2.1" foo
105 It's also possible to limit the scope of :option:`--allow-newer` to single
106 packages with the ``--allow-newer=scope:dep`` syntax. This means
107 that the dependency on ``dep`` will be relaxed only for the package
114 # Relax upper bound in foo's dependency on base; also relax upper bound in
115 # every package's dependency on lens.
116 $ cabal install --allow-newer=foo:base,lens
118 # Relax upper bounds in foo's dependency on base and bar's dependency
119 # on time; also relax the upper bound in the dependency on lens specified by
121 $ cabal install --allow-newer=foo:base,lens --allow-newer=bar:time
123 Finally, one can enable :option:`--allow-newer` permanently by setting
124 ``allow-newer: True`` in the :ref:`config file <config-file-discovery>`. Enabling
125 'allow-newer' selectively is also supported in the config file
126 (``allow-newer: foo, bar, baz:base``).
128 .. option:: --preference=preference
130 Specify a soft constraint on versions of a package. The solver will
131 attempt to satisfy these preferences on a "best-effort" basis.
133 .. option:: --enable-build-info
135 Generate accurate build information for build components.
137 Information contains meta information, such as component type, compiler type, and
138 Cabal library version used during the build, but also fine grained information,
139 such as dependencies, what modules are part of the component, etc...
141 On build, a file ``build-info.json`` (in the ``json`` format) will be written to
142 the root of the build directory.
145 The format and fields of the generated build information is currently
146 experimental. In the future we might add or remove fields, depending
147 on the needs of other tooling.
152 "cabal-lib-version": "<cabal lib version>",
154 "flavour": "<compiler name>",
155 "compiler-id": "<compiler id>",
156 "path": "<absolute path of the compiler>"
160 "type": "<component type, e.g. lib | bench | exe | flib | test>",
161 "name": "<component name>",
162 "unit-id": "<unitid>",
164 "<compiler args necessary for compilation>"
167 "<modules in this component>"
170 "<source files relative to hs-src-dirs>"
173 "<source directories of this component>"
175 "src-dir": "<root directory of this component>",
176 "cabal-file": "<cabal file location>"
181 .. jsonschema:: ./json-schemas/build-info.schema.json
183 .. option:: --disable-build-info
185 (default) Do not generate detailed build information for built components.
187 Already generated `build-info.json` files will be removed since they would be stale otherwise.
192 A cabal command target can take any of the following forms:
194 - A package target: ``package``, which specifies that all enabled
195 components of a package to be built. By default, test suites and
196 benchmarks are *not* enabled, unless they are explicitly requested
197 (e.g., via ``--enable-tests``.)
199 - A component target: ``[package:][ctype:]component``, which specifies
200 a specific component (e.g., a library, executable, test suite or
201 benchmark) to be built.
203 - All packages: ``all``, which specifies all packages within the project.
205 - Components of a particular type: ``package:ctypes``, ``all:ctypes``:
206 which specifies all components of the given type. Where valid
209 - ``libs``, ``libraries``,
210 - ``flibs``, ``foreign-libraries``,
211 - ``exes``, ``executables``,
213 - ``benches``, ``benchmarks``.
215 - A module target: ``[package:][ctype:]module``, which specifies that the
216 component of which the given module is a part of will be built.
218 - A filepath target: ``[package:][ctype:]filepath``, which specifies that the
219 component of which the given filepath is a part of will be built.
221 - A script target: ``path/to/script``, which specifies the path to a script
222 file. This is supported by ``build``, ``repl``, ``run``, and ``clean``.
223 Script targets are not part of a package.
231 ``cabal user-config [init|diff|update]`` prints and updates user's global
232 cabal preferences. It is very useful when you are e.g. first configuring
233 ``cabal`` on a new machine.
235 - ``cabal user-config init`` creates a new configuration file.
237 .. option:: --config-file=PATH
239 Specify config file path. (default: ``~/.cabal/config``).
241 .. option:: -f, --force
243 Force configuration file overwriting if already exists.
245 - ``cabal user-config diff`` prints a diff of the user's config file and the
248 - ``cabal user-config update`` updates the user's config file with additional
251 .. option:: -a, --augment=CONFIGLINE
253 Pass additional configuration lines to be incorporated in the
255 ``cabal user-config update --augment "offline: True"``.
257 Note how ``--augment`` syntax follows ``cabal user-config diff``
261 Package database commands
262 -------------------------
267 ``cabal update`` updates the state of the package index. If the
268 project contains multiple remote package repositories it will update
269 the index of all of them (e.g. when using overlays).
275 $ cabal update # update all remote repos
276 $ cabal update head.hackage # update only head.hackage
281 ``cabal list [FLAGS] STRINGS`` lists all packages matching a search string.
283 .. option:: --installed
285 Only output installed packages.
287 .. option:: --simple-output
289 Print matching packages in a one-package-one-line format.
291 .. option:: -i, --ignore-case
293 .. option:: -I, --strict-case
295 .. option:: --package-db=DB
297 Append the given package database to the list of used package
298 databases. See `cabal info`_ for a thorough explanation.
300 .. option:: -w, --with-compiler=PATH
302 Path to specific compiler.
307 ``cabal info [FLAGS] PACKAGES`` displays useful informations about remote
310 .. option:: --package-db=DB
312 Append the given package database to the list of package databases
313 used (to satisfy dependencies and register into). May be a specific
314 file, ``global`` or ``user``. The initial list is ``['global'], ['global',
315 'user']``, depending on context. Use ``clear`` to reset the list to empty.
318 Initialization and download
319 ---------------------------
324 ``cabal init [FLAGS]`` initialises a Cabal package, picking
325 reasonable defaults. Run it in your project folder.
327 .. option:: -i, --interactive
329 Enable interactive mode.
331 .. option:: -m, --minimal
333 Generate a short .cabal file, without extra empty fields or
334 explanatory comments.
336 See :ref:`init quickstart` for an overview on the command, and
337 ``cabal init --help`` for the complete list of options.
342 *☞ N.B.:* ``cabal fetch`` only works for legacy ``v1-`` commands and only
343 for single package projects. If you are not maintaining an old project,
344 `cabal build`_ with ``--only-download`` has similar effects to ``fetch``
345 and benefits from compatibility with newer build methods.
347 ``cabal fetch [FLAGS] PACKAGES`` downloads packages for later installation.
348 It fetches the project plus its dependencies, very useful when
349 e.g. you plan to work on a project with unreliable or no internet access.
351 .. option:: --no-dependencies
355 .. option:: --disable-tests
357 Disable dependency checking and compilation
358 for test suites listed in the package
361 .. option:: --disable-benchmarks
363 Disable dependency checking and compilation
364 for benchmarks listed in the package
367 Check ``cabal fetch --help`` for a complete list of options.
372 ``cabal get [PACKAGES]`` (synonym: ``cabal unpack``) downloads and unpacks
373 the source code of ``PACKAGES`` locally. By default the content of the
374 packages is unpacked in the current working directory, in named subfolders
375 (e.g. ``./filepath-1.2.0.8/``), use ``--destdir=PATH`` to specify another
376 folder. By default the latest version of the package is downloaded, you can
377 ask for a spefic one by adding version numbers
378 (``cabal get random-1.0.0.1``).
380 .. option:: -s, --source-repository[=head|this|...]]
382 Clone the package's source repository (Darcs, Git, etc.) instead
383 of downloading the tarball. Only works if the package specifies
384 a ``source-repository``.
386 .. option:: --index-state=STATE
388 Pin your request to a specific Hackage index state. Available
389 ``STATE`` formats: Unix timestamps (e.g. ``@1474732068``),
390 ISO8601 UTC timestamps (e.g. ``2016-09-24T17:47:48Z``), or ``HEAD``
393 .. option:: --pristine
395 Unpacks the pristine tarball, i.e. disregarding any Hackage revision.
397 Project configuration
398 ---------------------
403 ``cabal configure`` takes a set of arguments and writes a
404 ``cabal.project.local`` file based on the flags passed to this command.
405 ``cabal configure FLAGS; cabal build`` is roughly equivalent to
406 ``cabal build FLAGS``, except that with ``configure`` the flags
407 are persisted to all subsequent calls to ``build``.
409 ``cabal configure`` is intended to be a convenient way to write out
410 a ``cabal.project.local`` for simple configurations; e.g.,
411 ``cabal configure -w ghc-7.8`` would ensure that all subsequent
412 builds with ``cabal build`` are performed with the compiler
413 ``ghc-7.8``. For more complex configuration, we recommend writing the
414 ``cabal.project.local`` file directly (or placing it in
417 ``cabal configure`` inherits options from ``Cabal``. semantics:
419 - Any flag accepted by ``./Setup configure``.
421 - Any flag accepted by ``cabal configure`` beyond
422 ``./Setup configure``, namely ``--cabal-lib-version``,
423 ``--constraint``, ``--preference`` and ``--solver.``
425 - Any flag accepted by ``cabal install`` beyond ``./Setup configure``.
427 - Any flag accepted by ``./Setup haddock``.
429 The options of all of these flags apply only to *local* packages in a
430 project; this behavior is different than that of ``cabal install``,
431 which applies flags to every package that would be built. The motivation
432 for this is to avoid an innocuous addition to the flags of a package
433 resulting in a rebuild of every package in the store (which might need
434 to happen if a flag actually applied to every transitive dependency). To
435 apply options to an external package, use a ``package`` stanza in a
436 ``cabal.project`` file.
438 There are two ways of modifying the ``cabal.project.local`` file through
439 ``cabal configure``, either by appending new configurations to it, or
440 by simply overwriting it all. Overwriting is the default behaviour, as
441 such, there's a flag ``--enable-append`` to append the new configurations
442 instead. Since overwriting is rather destructive in nature, a backup system
443 is in place, which moves the old configuration to a ``cabal.project.local~``
444 file, this feature can also be disabled by using the ``--disable-backup``
450 ``cabal freeze`` writes out a **freeze file** which records all of
451 the versions and flags that are picked by the solver under the
452 current index and flags. Default name of this file is
453 ``cabal.project.freeze`` but in combination with a
454 ``--project-file=my.project`` flag (see :ref:`project-file
455 <cmdoption-project-file>`)
456 the name will be ``my.project.freeze``.
457 A freeze file has the same syntax as ``cabal.project`` and looks
464 constraints: HTTP ==4000.3.3,
465 HTTP +warp-tests -warn-as-error -network23 +network-uri -mtl1 -conduit10,
467 QuickCheck +templatehaskell,
471 For end-user executables, it is recommended that you distribute the
472 ``cabal.project.freeze`` file in your source repository so that all
473 users see a consistent set of dependencies. For libraries, this is not
474 recommended: users often need to build against different versions of
475 libraries than what you developed against.
480 ``cabal gen-bounds [FLAGS]`` generates bounds for all dependencies that do not
481 currently have them. Generated bounds are printed to stdout. You can then
482 paste them into your .cabal file.
484 See `the section on generating dependency version bounds <cabal-package.html#generating-dependency-version-bounds>`__ for more details and examples.
489 ``cabal outdated [FLAGS]`` checks for outdated dependencies in the package
490 description file or freeze file.
492 ``cabal outdated`` supports the following flags:
494 .. option:: --v1-freeze-file
496 Read dependency version bounds from the freeze file.
498 (``cabal.config``) instead of the package description file
499 (``$PACKAGENAME.cabal``).
501 .. option:: --v2-freeze-file
505 Read dependency version bounds from the v2-style freeze file
506 (by default, ``cabal.project.freeze``) instead of the package
507 description file. ``--new-freeze-file`` is an alias for this flag
508 that can be used with pre-2.4 ``cabal``.
510 .. option:: --project-file PROJECTFILE
514 Read dependency version bounds from the v2-style freeze file
515 related to the named project file (i.e., ``$PROJECTFILE.freeze``)
516 instead of the package description file. If multiple ``--project-file``
517 flags are provided, only the final one is considered. This flag
518 must only be passed in when ``--new-freeze-file`` is present.
520 .. option:: --simple-output
522 Print only the names of outdated dependencies, one per line.
524 .. option:: --exit-code
526 Exit with a non-zero exit code when there are outdated dependencies.
528 .. option:: -q, --quiet
530 Don't print any output. Implies ``-v0`` and ``--exit-code``.
532 .. option:: --ignore PACKAGENAMES
534 Don't warn about outdated dependency version bounds for the packages in this list.
536 .. option:: --minor [PACKAGENAMES]
538 Ignore major version bumps for these packages.
540 E.g. if there's a version 2.0 of a package ``pkg`` on Hackage and the freeze
541 file specifies the constraint ``pkg == 1.9``, ``cabal outdated --freeze
542 --minor=pkg`` will only consider the ``pkg`` outdated when there's a version
543 of ``pkg`` on Hackage satisfying ``pkg > 1.9 && < 2.0``. ``--minor`` can also
544 be used without arguments, in that case major version bumps are ignored for
547 See `the section on listing outdated dependency version bounds <cabal-package.html#listing-outdated-dependency-version-bounds>`__ for more details and examples.
549 Project building and installing
550 -------------------------------
555 ``cabal build`` takes a set of targets and builds them. It
556 automatically handles building and installing any dependencies of these
559 In component targets, ``package:`` and ``ctype:`` (valid component types
560 are ``lib``, ``flib``, ``exe``, ``test`` and ``bench``) can be used to
561 disambiguate when multiple packages define the same component, or the
562 same component name is used in a package (e.g., a package ``foo``
563 defines both an executable and library named ``foo``). We always prefer
564 interpreting a target as a package name rather than as a component name.
566 Some example targets:
570 $ cabal build lib:foo-pkg # build the library named foo-pkg
571 $ cabal build foo-pkg:foo-tests # build foo-tests in foo-pkg
572 $ cabal build src/Lib.s # build the library component to
573 # which "src/Lib.hs" belongs
574 $ cabal build app/Main.hs # build the executable component of
576 $ cabal build Lib # build the library component to
577 # which the module "Lib" belongs
578 $ cabal build path/to/script # build the script as an executable
580 Beyond a list of targets, ``cabal build`` accepts all the flags that
581 ``cabal configure`` takes. Most of these flags are only taken into
582 consideration when building local packages; however, some flags may
583 cause extra store packages to be built (for example,
584 ``--enable-profiling`` will automatically make sure profiling libraries
585 for all transitive dependencies are built and installed.)
587 When building a script, the executable is cached under the cabal directory.
588 See ``cabal run`` for more information on scripts.
590 In addition ``cabal build`` accepts these flags:
592 .. option:: --only-configure
594 When given we will forego performing a full build and abort after running
595 the configure phase of each target package.
600 ``cabal install [FLAGS] [TARGETS]`` builds the specified target packages and
601 symlinks/copies their executables in ``installdir`` (usually ``~/.local/bin``).
605 If not every package has an executable to install, use ``all:exes`` rather
606 than ``all`` as the target. To overwrite an installation, use
607 ``--overwrite-policy=always`` as the default policy is ``never``.
609 For example this command will build the latest ``cabal-install`` and symlink
610 its ``cabal`` executable:
614 $ cabal install cabal-install
616 In addition, it's possible to use ``cabal install`` to install components
617 of a local project. For example, with an up-to-date Git clone of the Cabal
618 repository, this command will build cabal-install HEAD and symlink the
619 ``cabal`` executable:
623 $ cabal install exe:cabal
625 Where symlinking is not possible (eg. on some Windows versions) the ``copy``
626 method is used by default. You can specify the install method
627 by using ``--install-method`` flag:
631 $ cabal install exe:cabal --install-method=copy --installdir=$HOME/bin
633 Note that copied executables are not self-contained, since they might use
634 data-files from the store.
636 .. _adding-libraries:
638 Adding libraries to GHC package environments
639 """"""""""""""""""""""""""""""""""""""""""""
641 It is also possible to "install" libraries using the ``--lib`` flag. For
642 example, this command will build the latest Cabal library and install it:
646 $ cabal install --lib Cabal
648 This works by managing GHC package environment files. By default, it is writing
649 to the global environment in ``~/.ghc/$ARCH-$OS-$GHCVER/environments/default``.
650 ``install`` provides the ``--package-env`` flag to control which of these
651 environments is modified.
653 This command will modify the environment file in the current directory:
657 $ cabal install --lib Cabal --package-env .
659 This command will modify the environment file in the ``~/foo`` directory:
663 $ cabal install --lib Cabal --package-env foo/
665 Do note that the results of the previous two commands will be overwritten by
666 the use of other style commands, so it is not recommended to use them inside
669 This command will modify the environment in the ``local.env`` file in the
674 $ cabal install --lib Cabal --package-env local.env
676 This command will modify the ``myenv`` named global environment:
680 $ cabal install --lib Cabal --package-env myenv
682 If you wish to create a named environment file in the current directory where
683 the name does not contain an extension, you must reference it as ``./myenv``.
685 You can learn more about how to use these environments in `this section of the
686 GHC manual <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/packages.html#package-environments>`_.
691 ``cabal haddock [FLAGS] [TARGET]`` builds Haddock documentation for
692 the specified packages within the project.
694 If a target is not a library :cfg-field:`haddock-benchmarks`,
695 :cfg-field:`haddock-executables`, :cfg-field:`haddock-internal`,
696 :cfg-field:`haddock-tests` will be implied as necessary.
698 cabal haddock-project
699 ^^^^^^^^^^^^^^^^^^^^^
701 ``cabal haddock-project [FLAGS]`` builds Haddock documentation for all local
702 packages specified in the project.
704 By default the documentation will be put in ``./haddocks`` folder, this can be
705 modified with the ``--output`` flag.
707 This command supports two primary modes: building a self contained directory
708 (by specifying ``--local`` flag) or documentation that links to hackage (with
709 ``--hackage`` flag). Both options imply: ``--quickjump``, ``--gen-index``,
710 ``--gen-contents`` and ``--hyperlinked-source``.
712 If neither ``--local`` nor ``--hackage`` option is specified a self contained
713 directory will only be build if ``--html-location`` is not specified.
715 In both cases the html index as well as quickjump index will include all terms
716 and types defined in any of the local packages, but not ones that are included
717 in any of the dependencies. But note that if you navigate to a dependency,
718 you will have access to its quickjump index.
720 The generated landing page will contain one tree of all modules per local
726 ``cabal clean [FLAGS]`` cleans up the temporary files and build artifacts
727 stored in the ``dist-newstyle`` folder.
729 By default, it removes the entire folder, but it can also spare the configuration
730 and caches if the ``--save-config`` option is given, in which case it only removes
731 the build artefacts (``.hi``, ``.o`` along with any other temporary files generated
732 by the compiler, along with the build output).
734 ``cabal clean [FLAGS] path/to/script`` cleans up the temporary files and build
735 artifacts for the script, which are stored under the .cabal/script-builds directory.
737 In addition when clean is invoked it will remove all script build artifacts for
738 which the corresponding script no longer exists.
746 ``cabal list-bin`` will either (a) display the path for a single executable or (b)
747 complain that the target doesn't resolve to a single binary. In the latter case,
748 it will name the binary products contained in the package. These products can
749 be used to narrow the search and get an actual path to a particular executable.
751 Example showing a failure to resolve to a single executable.
755 $ cabal list-bin cabal-install
756 cabal: The list-bin command is for finding a single binary at once. The
757 target 'cabal-install' refers to the package cabal-install-#.#.#.# which
758 includes the executable 'cabal', the test suite 'unit-tests', the test suite
759 'mem-use-tests', the test suite 'long-tests' and the test suite
760 'integration-tests2'.
762 For a scope that results in only one item we'll get a path.
766 $ cabal list-bin cabal-install:exes
767 /.../dist-newstyle/build/.../cabal/cabal
769 $ cabal list-bin cabal-install:cabal
770 /.../dist-newstyle/build/.../cabal/cabal
772 We can also scope to test suite targets as they produce binaries.
776 $ cabal list-bin cabal-install:tests
777 cabal: The list-bin command is for finding a single binary at once. The
778 target 'cabal-install:tests' refers to the test suites in the package
779 cabal-install-#.#.#.# which includes the test suite 'unit-tests', the test
780 suite 'mem-use-tests', the test suite 'long-tests' and the test suite
781 'integration-tests2'.
783 $ cabal list-bin cabal-install:unit-tests
784 /.../dist-newstyle/.../unit-tests/unit-tests
786 Note that ``cabal list-bin`` will print the executables' location, but
787 will not make sure that these executables actually exist (i.e., have
788 been successfully built). In order to determine the correct location,
789 it may invoke the configuration step (see ``cabal configure``).
794 ``cabal repl TARGET [FLAGS]``
795 opens an interactive session for the target component within the project and
796 loads all of the modules of the target into GHCi as interpreted bytecode.
797 The available targets are the same as for the ``build`` command: individual components
798 within packages in the project, including libraries, executables, test-suites
799 and benchmarks (see `the build section <#cabal-build>`__ for the target syntax).
800 Local packages can also be specified, in which case the library
801 component in the package will be used, or the (first listed) executable in the
802 package if there is no library. Dependencies are built or rebuilt as necessary.
804 Currently, it is not supported to pass multiple targets to ``repl``
805 (``repl`` will just successively open a separate GHCi session for
812 $ cabal repl # default component in the package in the current directory
813 $ cabal repl pkgname # default component in the package named 'pkgname'
814 $ cabal repl ./pkgfoo # default component in the package in the ./pkgfoo directory
815 $ cabal repl cname # component named 'cname'
816 $ cabal repl pkgname:cname # component 'cname' in the package 'pkgname'
818 Configuration flags can be specified on the command line and these extend the project
819 configuration from the 'cabal.project', 'cabal.project.local' and other files.
821 .. option:: --repl-options
823 To avoid ``ghci``-specific flags from triggering unneeded global rebuilds, these
824 flags are stripped from the internal configuration. As a result,
825 ``--ghc-options`` will no longer (reliably) work to pass flags to ``ghci`` (or
826 other REPLs). Instead, you should use the ``--repl-options`` flag to
827 specify these options to the invoked REPL.
829 .. option:: --repl-no-load
831 Disables the loading of target modules at startup.
833 .. option:: -b, --build-depends
835 A way to experiment with libraries without needing to download
836 them manually or to install them globally.
838 This command opens a REPL with the current default target loaded, and a version
839 of the ``vector`` package matching that specification exposed.
843 $ cabal repl --build-depends "vector >= 0.12 && < 0.13"
845 Both of these commands do the same thing as the above, but only expose ``base``,
846 ``vector``, and the ``vector`` package's transitive dependencies even if the user
847 is in a project context.
851 $ cabal repl --ignore-project --build-depends "vector >= 0.12 && < 0.13"
852 $ cabal repl --project='' --build-depends "vector >= 0.12 && < 0.13"
854 This command would add ``vector``, but not (for example) ``primitive``, because
855 it only includes the packages specified on the command line (and ``base``, which
856 cannot be excluded for technical reasons).
860 $ cabal repl --build-depends vector --no-transitive-deps
862 ``cabal repl`` can open scripts by passing the path to the script as the target.
866 $ cabal repl path/to/script
868 The configuration information for the script is cached under the cabal directory
869 and can be pre-built with ``cabal build path/to/script``.
870 See ``cabal run`` for more information on scripts.
877 ``cabal run [TARGET [ARGS]]`` runs the executable specified by the
878 target, which can be a component, a package or can be left blank, as
879 long as it can uniquely identify an executable within the project.
880 Tests and benchmarks are also treated as executables.
882 See `the build section <#cabal-build>`__ for the target syntax.
884 When ``TARGET`` is one of the following:
886 - A component target: execute the specified executable, benchmark or test suite.
889 1. If the package has exactly one executable component, it will be selected.
890 2. If the package has multiple executable components, an error is raised.
891 3. If the package has exactly one test or benchmark component, it will be selected.
892 4. Otherwise an issue is raised.
894 - The path to a script: execute the script at the path.
896 - Empty target: Same as package target, implicitly using the package from the current
899 Except in the case of the empty target, the strings after it will be
900 passed to the executable as arguments.
902 If one of the arguments starts with ``-`` it will be interpreted as
903 a cabal flag, so if you need to pass flags to the executable you
904 have to separate them with ``--``.
908 $ cabal run target -- -a -bcd --argument
910 ``run`` supports running script files that use a certain format.
917 build-depends: base ^>= 4.14
921 with-compiler: ghc-8.10.7
928 Where there cabal metadata block is mandatory and contains fields from a
929 package executable block, and the project metadata block is optional and
930 contains fields that would be in the cabal.project file in a regular project.
932 Only some fields are supported in the metadata blocks, and these fields are
933 currently not validated. See
934 `#8024 <https://github.com/haskell/cabal/issues/8024>`__ for details.
936 A script can either be executed directly using `cabal` as an interpreter or
941 $ cabal run path/to/script
943 The executable is cached under the cabal directory, and can be pre-built with
944 ``cabal build path/to/script`` and the cache can be removed with
945 ``cabal clean path/to/script``.
947 A note on targets: Whenever a command takes a script target and it matches the
948 name of another target, the other target is preferred. To load the script
949 instead pass it as an explicit path: ./script
951 By default, scripts are run at silent verbosity (``--verbose=0``). To show the
952 build output for a script either use the command
956 $ cabal run --verbose=n path/to/script
958 or the interpreter line
962 #!/usr/bin/env -S cabal run --verbose=n
964 For more information see :cfg-field:`verbose`
969 ``cabal bench [TARGETS] [OPTIONS]`` runs the specified benchmarks
970 (all the benchmarks in the current package by default), first ensuring
976 ``cabal test [TARGETS] [OPTIONS]`` runs the specified test suites
977 (all the test suites in the current package by default), first ensuring
983 ``cabal exec [FLAGS] [--] COMMAND [--] [ARGS]`` runs the specified command
984 using the project's environment. That is, passing the right flags to compiler
985 invocations and bringing the project's executables into scope.
987 Sanity checks and shipping
988 --------------------------
993 ``cabal check [FLAGS]`` checks the package for common mistakes (e.g.: if
994 it is missing important fields like ``synopsis``, if it is using
995 tricky GHC options, etc.).
997 Run ``cabal check`` in the folder where your ``.cabal`` package file is.
999 .. option:: -v, --verbose[=n]
1001 Set verbosity level (0–3, default is 1).
1003 ``cabal check`` mimics Hackage's requirements: if no error or warning
1004 is reported, Hackage should accept your package.
1009 ``cabal sdist [FLAGS] [TARGETS]`` takes the crucial files needed to build ``TARGETS``
1010 and puts them into an archive format ready for upload to Hackage. These archives are stable
1011 and two archives of the same format built from the same source will hash to the same value.
1013 ``cabal sdist`` takes the following flags:
1015 .. option:: -l, --list-only
1017 Rather than creating an archive, lists files that would be included.
1019 Output is to ``stdout`` by default. The file paths are relative to the project's root
1022 .. option:: -o, --output-directory
1024 Sets the output dir, if a non-default one is desired. The default is
1025 ``dist-newstyle/sdist/``. ``--output-directory -`` will send output to ``stdout``
1026 unless multiple archives are being created.
1028 .. option:: --null-sep
1030 Only used with ``--list-only``. Separates filenames with a NUL
1031 byte instead of newlines.
1033 ``sdist`` is inherently incompatible with sdist hooks (which were removed in `Cabal-3.0`),
1034 not due to implementation but due to fundamental core invariants
1035 (same source code should result in the same tarball, byte for byte)
1036 that must be satisfied for it to function correctly in the larger build ecosystem.
1037 ``autogen-modules`` is able to replace uses of the hooks to add generated modules, along with
1038 the custom publishing of Haddock documentation to Hackage.
1043 ``cabal upload [FLAGS] TARFILES`` uploads source packages or documentation
1046 .. option:: --publish
1048 Publish the package immediately instead of uploading it as a
1049 `package candidate <https://hackage.haskell.org/upload#candidates>`__
1050 (make sure everything is fine, you cannot delete published packages
1053 .. option:: -d, --documentation
1055 Upload documentation instead of a source package. To upload
1056 documentation for a published package (and not a candidate), add
1059 .. option:: -u, --username
1061 Your Hackage username.
1063 .. option:: -p, --password
1065 Your Hackage password.
1067 .. option:: -P, --password-command
1069 Command to get your Hackage password.
1074 ``cabal report [FLAGS]`` uploads build reports to Hackage.
1076 .. option:: -u, --username
1078 Your Hackage username.
1080 .. option:: -p, --password
1082 Your Hackage password.