@@ -50,7 +50,8 @@ If we command:
5050stack build
5151~~~
5252
53- Stack will report error [ S-7282] during the build:
53+ Stack will report Stack error [ S-7282] during the build, with output like the
54+ following:
5455
5556~~~ text
5657...
@@ -72,7 +73,8 @@ Error: [S-7282]
7273 While executing the build plan, Stack encountered the error:
7374
7475 [S-7011]
75- While building package helloworld-0.1.0.0 (scroll up to its section to see the error) using:
76+ While building package helloworld-0.1.0.0 (scroll up to its section to
77+ see the error) using:
7678 ...
7779 Process exited with code: ExitFailure 1
7880~~~
@@ -90,7 +92,7 @@ dependencies:
9092- text # added
9193~~~
9294
93- Now, if we command again :
95+ Now, if we command :
9496
9597~~~text
9698stack build
@@ -153,8 +155,8 @@ someFunc = launchMissiles
153155~~~
154156
155157As before, to tell Stack that the ` acme-missiles ` package is a dependency of the
156- ` helloworld ` package, we can update the package description file
157- (` package.yaml ` ). The relevant part of the file now looks like this:
158+ ` helloworld ` package, we must update the package description file
159+ (` package.yaml ` ). The relevant part of that file now looks like this:
158160
159161~~~ yaml
160162dependencies :
@@ -165,44 +167,53 @@ dependencies:
165167- acme-missiles # added
166168~~~
167169
168- If we command :
170+ However, if we command :
169171
170172~~~text
171173stack build
172174~~~
173175
174- Stack will report error [ S-4804] :
176+ Stack will report Stack error [ S-4804] during the build, with output like the
177+ following:
175178
176179~~~ text
177180Error: [S-4804]
178181 Stack failed to construct a build plan.
179182
180- While constructing the build plan, Stack encountered the following errors. The
181- 'Stack configuration' refers to the set of package versions specified by the
182- snapshot (after any dropped packages, or pruned GHC boot packages; if a boot
183- package is replaced, Stack prunes all other such packages that depend on it) and
184- any extra-deps:
183+ While constructing the build plan, Stack encountered the following
184+ errors. The 'Stack configuration' refers to the set of package versions
185+ specified by the snapshot (after any dropped packages, or pruned GHC boot
186+ packages; if a boot package is replaced, Stack prunes all other such
187+ packages that depend on it) and any extra-deps:
185188
186189 In the dependencies for helloworld-0.1.0.0:
187- * acme-missiles needed, but no version is in the Stack configuration (latest
188- matching version is 0.3).
190+ * acme-missiles needed, but no version is in the Stack configuration
191+ (latest matching version is 0.3).
189192 The above is/are needed since helloworld is a build target.
190193
191194 Some different approaches to resolving some or all of this:
192195
193196 * Recommended action: try adding the following to your extra-deps in
194197 ...\helloworld\stack.yaml (project-level configuration):
195198
196- - acme-missiles-0.3@sha256:2ba66a092a32593880a87fb00f3213762d7bca65a687d45965778deb8694c5d1,613
199+ - acme-missiles-0.3@sha256:2ba66a092a32593880a87fb00f3213762d7bca65a6
200+ 87d45965778deb8694c5d1,613
197201~~~
198202
199- It says that Stack was unable to construct the build plan.
203+ The error message explains that Stack was unable to construct a build plan and
204+ why: the package ` acme-missiles ` was needed but no version of that package is
205+ in the set of package versions specified by the snapshot. Stack makes a
206+ suggestion to fix that.
200207
201208This brings us to the next major topic in using Stack.
202209
203210## Extending snapshots
204211
205- A snapshot specifies a version of GHC and a set of package versions.
212+ A snapshot specifies a version of GHC and a set of package versions chosen to
213+ work well together. However, sometimes you will want to use package versions
214+ that are not specified by the snapshot. That may be because the package is not
215+ in the snapshot or because a different version of the package is in the
216+ snapshot.
206217
207218Remember above when ` stack new ` selected some
208219[ LTS snapshot] ( https://github.com/commercialhaskell/lts-haskell#readme ) for us?
@@ -211,8 +222,8 @@ That defined our build plan and available packages. When we tried using the
211222
212223We have updated the description of the ` helloworld ` package (in ` package.yaml ` )
213224to specify that it depends on the ` acme-missiles ` package, but ` acme-missiles `
214- is not a member of the set of packages specified by the snapshot. So building
215- failed.
225+ is not a member of the set of package versions specified by the snapshot. So
226+ building failed.
216227
217228To add a version of ` acme-missiles ` to the available package versions, we'll use
218229the ` extra-deps ` key in Stack's project-level configuration file (` stack.yaml ` ).
@@ -224,14 +235,16 @@ extra-deps:
224235- acme-missiles-0.3 # not in the LTS snapshot
225236~~~
226237
227- Now, if we command again :
238+ Now, if we command :
228239
229240~~~text
230241stack build
231242~~~
232243
233244we should get a successful result.
234245
246+ ## Stackage snapshots
247+
235248With that out of the way, let's dig a little bit more into these snapshots. We
236249mentioned the LTS snapshots, and you can get information about it at
237250[ https://www.stackage.org/lts ] ( https://www.stackage.org/lts ) , including:
@@ -252,29 +265,31 @@ about them on the
252265If you're not sure which to use, start with LTS Haskell (which Stack will lean
253266towards by default as well).
254267
255- ## Available snapshots
268+ ## Snapshots and GHC versions
256269
257- Let's explore package sets a bit further. Instead of ` lts-22.13 ` , let's change
258- our ` stack.yaml ` file to use the
259- [ latest nightly] ( https://www.stackage.org/nightly ) . Right now, this is currently
260- 2024-03-20 - please see the snapshot from the link above to get the latest.
270+ As mentioned, a snapshot specifies a version of GHC as well as a set of package
271+ versions.
261272
262- Then, commanding ` stack build ` again will produce:
273+ Let's try using an older LTS snapshot. We'll use the Stackage LTS Haskell 21.25
274+ snapshot with the command:
263275
264276~~~ text
265- stack build
266- # Downloaded nightly-2024-03-20 build plan.
267- # build output ...
277+ stack --snapshot lts-21.25 build
268278~~~
269279
270- We can also change snapshots on the command line, which can be useful in a
271- Continuous Integration (CI) setting, like on Travis. For example, command:
280+ Stackage LTS Haskell 21.25 specifies GHC 9.4.8. If that version of GHC is not
281+ already available, Stack will try to fetch it and install it before starting the
282+ rest of the build.
272283
273- ~~~ text
274- stack --snapshot lts-21.25 build
275- # Downloaded lts-21.25 build plan.
276- # build output ...
277- ~~~
284+ ## Specifying a snapshot
285+
286+ A snapshot must be specified in Stack's project-level configuration file
287+ (` stack.yaml ` , by default). For further information, see the
288+ [ ` snapshot ` ] ( ../configure/yaml/project.md#snapshot ) project-specific
289+ configuration option documentation.
290+
291+ As we have seen, a snapshot can also be specified on the command line. That can
292+ be useful in a Continuous Integration (CI) setting.
278293
279294When passed on the command line, you also get some additional "short-cut"
280295versions of snapshots: ` --snapshot nightly ` will use the newest Nightly snapshot
@@ -287,36 +302,15 @@ on the command line and not in your `stack.yaml` file is that using them:
2873022 . Produces unreliable results (since a build run today may proceed differently
288303 tomorrow because of changes outside of your control)
289304
290- We've mentioned ` nightly-YYYY-MM-DD ` and ` lts-X.Y ` values for the snapshot.
291- There are actually other options available, and the list will grow over time.
292- At the time of writing:
305+ ## Cleaning up your project
293306
294- * ` ghc-X.Y.Z ` , for requiring a specific GHC version but no additional packages
295- * Experimental custom snapshot support
307+ Stack creates files during the build process and stores those files in
308+ directories within a local project or package directory known as
309+ [ Stack work directories] ( ../topics/stack_work.md ) . Stack can be used without an
310+ understanding of the content of those directories.
296311
297- The most up-to-date information can always be found in the
298- [ stack.yaml documentation] ( ../configure/yaml/project.md#snapshot ) .
299-
300- ## Snapshots and GHC versions
301-
302- As mentioned, a snapshot specifies a version of GHC as well as a set of package
303- versions.
304-
305- Let's try using an older LTS snapshot. We'll use the newest 21.x snapshot with
306- the command:
307-
308- ~~~ text
309- stack --snapshot lts-21 build
310- ~~~
311-
312- This succeeds, automatically installing the necessary GHC along the way. So, we
313- see that different LTS versions use different GHC versions and Stack can handle
314- that.
315-
316- ## Cleaning your project
317-
318- You can clean up build artifacts for your project using the ` stack clean ` and
319- ` stack purge ` commands.
312+ if you wish, you can clean up files created during the build process for your
313+ project using the ` stack clean ` and ` stack purge ` commands.
320314
321315### The ` stack clean ` command
322316
@@ -333,4 +327,6 @@ _specific-package_ only.
333327git dependencies and the compiler output (including logs). It does not delete
334328any snapshot packages, compilers or programs installed using ` stack install ` .
335329This essentially reverts the project to a completely fresh state, as if it had
336- never been built. ` stack purge ` is just a shortcut for ` stack clean --full `
330+ never been built.
331+
332+ ` stack purge ` is a shortcut for ` stack clean --full ` .
0 commit comments