Skip to content

Commit 6335a90

Browse files
committed
Improve docmentation of stack script
1 parent 24cee3d commit 6335a90

File tree

2 files changed

+94
-10
lines changed

2 files changed

+94
-10
lines changed

doc/build_command.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ supported syntaxes for targets are:
9898
some boot packages. In particular, some snapshots include directly `Win32`
9999
(which is a boot package on Windows) while others do not. For example, if
100100
`Cabal` (a boot package) is not a local package or an extra dep, then
101-
`stack build Cabal` with Stackage snapshot LTS Haskell 19.25 will:
101+
`stack build Cabal` with Stackage snapshot LTS Haskell 20.25 will:
102102

103103
* on Windows, try to build the latest version of `Cabal` in the package
104104
index (because that snapshot includes `Win32` directly, and `Cabal`

doc/script_command.md

Lines changed: 93 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ Unlike `stack ghc` and `stack runghc`, the command ignores all Stack YAML
1717
configuration files (global and project-level). A snapshot must be specified on
1818
the command line (with the `--resolver` option). For example:
1919

20-
~~~text
21-
stack --resolver lts-20.19 MyScript.hs
22-
~~~
23-
24-
or, equivalently:
25-
2620
~~~text
2721
stack script --resolver lts-20.19 MyScript.hs
2822
~~~
@@ -39,12 +33,36 @@ A package can be added to the snapshot on the command line with the
3933
Each required package can be specified by name on the command line with the
4034
`--package` option (which can be specified multiple times). A single `--package`
4135
option can also refer to a list of package names, separated by a space or comma
42-
character. If the package is not in the snapshot, the most recent version on
43-
Hackage will be obtained. If no packages are specified in that way, all the
44-
required packages that are in the snapshot will be deduced by reference to the
36+
character. If the package is not in the snapshot, the most recent version in the
37+
package index (e.g. Hackage) will be obtained.
38+
39+
If no packages are specified in that way, all the required packages that are in
40+
the snapshot or are a GHC boot package (packages that come with GHC and are
41+
included in GHC's global package database) will be deduced by reference to the
4542
`import` statements in the source file. The `base` package associated with the
4643
version of GHC specified by the snapshot is always available.
4744

45+
If a required package is a GHC boot package, the behaviour can be complex. If
46+
the boot package has not been 'replaced', then it will be used in Stack's build
47+
plan. However, if the boot package has been 'replaced', the latest version of
48+
that package in the package index will be used in Stack's build plan, which may
49+
differ from the version provided by the version of GHC specified by the
50+
snapshot. A boot package will be treated as 'replaced' if the package i
51+
included directly in the Stackage snapshot or it depends on a package included
52+
directly in the snapshot. Stackage snapshots do not include directly most boot
53+
packages but some snapshots may include directly some boot packages. In
54+
particular, some snapshots include directly `Win32` (which is a boot package on
55+
Windows) while others do not. For example, if `Cabal` (a boot package) is a
56+
required package then, with Stackage snapshot LTS Haskell 20.25, Stack will:
57+
58+
* on Windows, try to construct a build plan based on the latest version of
59+
`Cabal` in the package index (because that snapshot includes `Win32` directly,
60+
and `Cabal` depends on `Win32` and so is treated as 'replaced'); and
61+
* on non-Windows, use the boot package in the build plan (because `Cabal` is not
62+
'replaced').
63+
64+
Boot packages that have been 'replaced' can be specified as an `--extra-dep`.
65+
4866
The source file can be compiled by passing either the `--compile` flag (no
4967
optimization) or the `--optimize` flag (compilation with optimization). If the
5068
file is compiled, passing the `--no-run` flag will mean the compiled code is not
@@ -91,3 +109,69 @@ All the compilation outputs (like `Main.hi`, `Main.o`, and the executable
91109
If compiled and run with the additional flag `--use-root`, all the compilation
92110
outputs will be written to a directory named `MyScript.hs` at
93111
`Users/jane/my-project/` in the `scripts` directory of the Stack root.
112+
113+
For example, consider the following script extract, based on snapshot Stackage
114+
LTS Haskell 20.25, where considerations on Windows differ from non-Windows. The
115+
`stack script` command is specified using Stack's
116+
[script interpreter](scripts.md).
117+
118+
=== "Windows"
119+
120+
The snapshot includes `Win32` directly. As a consequence, GHC boot packages
121+
`directory`, `process` and `time` (which depend on `Win32`) are all treated
122+
as 'replaced'.
123+
124+
~~~haskell
125+
{- stack script
126+
--resolver lts-20.25
127+
--extra-dep acme-missiles-0.3
128+
--extra-dep directory-1.3.6.2
129+
--extra-dep process-1.6.16.0
130+
--extra-dep time-1.11.1.1
131+
-}
132+
133+
import Acme.Missiles -- from acme-missiles
134+
import Data.Time.Clock.System -- from time
135+
import System.Time.Extra -- from extra
136+
137+
...
138+
~~~
139+
140+
`acme-missiles` is not in the snapshot and so needs to be specified as an
141+
extra dep.
142+
143+
Stack can deduce that the module imports imply that the required packages
144+
are `acme-missiles`, `time` and `extra` (which is in the snapshot).
145+
146+
`extra` depends on `directory` and `process`. If `directory` and `process`
147+
are not specified as extra deps, Stack will complain that they have been
148+
'pruned'.
149+
150+
`directory-1.3.6.2` depends on `time < 1.12`. If `time` is not specified as
151+
an extra dep, Stack will try to construct a build plan based on the latest
152+
version in the package index (which will fail, as the latest version is
153+
`>= 1.12`)
154+
155+
=== "Unix-like"
156+
157+
~~~haskell
158+
{- stack script
159+
--resolver lts-20.25
160+
--extra-dep acme-missiles-0.3
161+
-}
162+
163+
import Acme.Missiles -- from acme-missiles
164+
import Data.Time.Clock.System -- from time
165+
import System.Time.Extra -- from extra
166+
167+
...
168+
~~~
169+
170+
`acme-missiles` is not in the snapshot and so needs to be specified as an
171+
extra dep.
172+
173+
Stack can deduce that the module imports imply that the required packages
174+
are `acme-missiles`, `time` and `extra` (which is in the snapshot).
175+
176+
All the other dependencies required are either GHC boot packages (which have
177+
not been 'replaced') or in the snapshot.

0 commit comments

Comments
 (0)