@@ -17,12 +17,6 @@ Unlike `stack ghc` and `stack runghc`, the command ignores all Stack YAML
17
17
configuration files (global and project-level). A snapshot must be specified on
18
18
the command line (with the ` --resolver ` option). For example:
19
19
20
- ~~~ text
21
- stack --resolver lts-20.19 MyScript.hs
22
- ~~~
23
-
24
- or, equivalently:
25
-
26
20
~~~ text
27
21
stack script --resolver lts-20.19 MyScript.hs
28
22
~~~
@@ -39,12 +33,36 @@ A package can be added to the snapshot on the command line with the
39
33
Each required package can be specified by name on the command line with the
40
34
` --package ` option (which can be specified multiple times). A single ` --package `
41
35
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
45
42
` import ` statements in the source file. The ` base ` package associated with the
46
43
version of GHC specified by the snapshot is always available.
47
44
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
+
48
66
The source file can be compiled by passing either the ` --compile ` flag (no
49
67
optimization) or the ` --optimize ` flag (compilation with optimization). If the
50
68
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
91
109
If compiled and run with the additional flag ` --use-root ` , all the compilation
92
110
outputs will be written to a directory named ` MyScript.hs ` at
93
111
` 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