Skip to content

Commit c070d6a

Browse files
domenkozarhvr
authored andcommitted
Clarify build-tool-depends documentation (#5561) [skip ci]
1 parent f28e615 commit c070d6a

File tree

1 file changed

+55
-12
lines changed

1 file changed

+55
-12
lines changed

Cabal/doc/developing-packages.rst

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,21 +2168,54 @@ system-dependent values for these fields.
21682168
.. pkg-field:: build-tool-depends: package:executable list
21692169
:since: 2.0
21702170

2171-
A list of Haskell programs needed to build this component.
2172-
Each is specified by the package containing the executable and the name of the executable itself, separated by a colon, and optionally followed by a version bound.
2173-
It is fine for the package to be the current one, in which case this is termed an *internal*, rather than *external* executable dependency.
2171+
A list of Haskell executables needed to build this component. Executables are provided
2172+
during the whole duration of the component, so this field can be used for executables
2173+
needed during :pkg-section:`test-suite` as well.
2174+
2175+
Each is specified by the package containing the executable and the name of the
2176+
executable itself, separated by a colon, and optionally followed by a version bound.
2177+
2178+
All executables defined in the given Cabal file are termed as *internal* dependencies
2179+
as opposed to the rest which are *external* dependencies.
2180+
2181+
Each of the two is handled differently:
2182+
2183+
1. External dependencies can (and should) contain a version bound like conventional
2184+
:pkg-field:`build-depends` dependencies.
2185+
2. Internal depenedencies should not contain a version bound, as they will be always
2186+
resolved within the same configuration of the package in the build plan.
2187+
Specifically, version bounds that include the package's version will be warned for
2188+
being extraneous, and version bounds that exclude the package's version will raise
2189+
an error for being impossible to follow.
2190+
2191+
For example (1) using a test-suite to make sure README.md Haskell snippets are tested using
2192+
`markdown-unlit <http://hackage.haskell.org/package/markdown-unlit>`__:
2193+
2194+
::
2195+
2196+
build-tool-depends: markdown-unlit:markdown-unlit >=0.5.0
2197+
2198+
For example (2) using a test-suite to test executable behaviour in the same package:
2199+
2200+
::
2201+
2202+
build-tool-depends: mypackage:executable
2203+
2204+
Cabal tries to make sure that all specified programs are atomically built and prepended
2205+
on the ``$PATH`` shell variable before building the component in question, but can only do
2206+
so for Nix-style builds. Specifically:
2207+
2208+
a) For Nix-style local builds, both internal and external dependencies.
2209+
b) For old-style builds, only for internal dependencies [#old-style-build-tool-depends]_.
2210+
It's up to the user to provide needed executables in this case under `$PATH.`
21742211

2175-
External dependencies can (and should) contain a version bound like conventional :pkg-field:`build-depends` dependencies.
2176-
Internal deps should not contain a version bound, as they will be always resolved within the same configuration of the package in the build plan.
2177-
Specifically, version bounds that include the package's version will be warned for being extraneous, and version bounds that exclude the package's version will raise an error for being impossible to follow.
21782212

2179-
Cabal can make sure that specified programs are built and on the ``PATH`` before building the component in question.
2180-
It will always do so for internal dependencies, and also do so for external dependencies when using Nix-style local builds.
2213+
.. note::
21812214

2182-
:pkg-field:`build-tool-depends` was added in Cabal 2.0, and it will
2183-
be ignored (with a warning) with old versions of Cabal. See
2184-
:pkg-field:`build-tools` for more information about backwards
2185-
compatibility.
2215+
:pkg-field:`build-tool-depends` was added in Cabal 2.0, and it will
2216+
be ignored (with a warning) with old versions of Cabal. See
2217+
:pkg-field:`build-tools` for more information about backwards
2218+
compatibility.
21862219

21872220
.. pkg-field:: build-tools: program list
21882221
:deprecated:
@@ -3589,3 +3622,13 @@ a few options:
35893622
35903623
35913624
.. include:: references.inc
3625+
3626+
.. rubric:: Footnotes
3627+
3628+
.. [#old-style-build-tool-depends]
3629+
3630+
Some packages (ab)use :pkg-field:`build-depends` on old-style builds, but this has a few major drawbacks:
3631+
3632+
- using Nix-style builds it's considered an error if you depend on a exe-only package via build-depends: the solver will refuse it.
3633+
- it may or may not place the executable on $PATH.
3634+
- it does not ensure the correct version of the package is installed, so you might end up overwriting versions with each other.

0 commit comments

Comments
 (0)