@@ -1646,23 +1646,17 @@ running the file.
16461646An example will be easiest to understand:
16471647
16481648```
1649- michael@d30748af6d3d:~ $ cat turtle.hs
1649+ michael@d30748af6d3d:~ $ cat turtle-example .hs
16501650#!/usr/bin/env stack
1651- -- stack --resolver lts-3.2 --install-ghc runghc --package turtle
1651+ -- stack --resolver lts-6.25 script --package turtle
16521652{-# LANGUAGE OverloadedStrings #-}
16531653import Turtle
16541654main = echo "Hello World!"
1655- michael@d30748af6d3d:~ $ chmod +x turtle.hs
1656- michael@d30748af6d3d:~ $ ./turtle.hs
1657- Run from outside a project, using implicit global project config
1658- Using resolver: lts-3.2 specified on command line
1659- hashable-1.2.3.3: configure
1660- # installs some more dependencies
1661- Completed all 22 actions.
1655+ michael@d30748af6d3d:~ $ chmod +x turtle-example.hs
1656+ michael@d30748af6d3d:~ $ ./turtle-example.hs
1657+ Completed 5 action(s).
16621658Hello World!
1663- michael@d30748af6d3d:~ $ ./turtle.hs
1664- Run from outside a project, using implicit global project config
1665- Using resolver: lts-3.2 specified on command line
1659+ michael@d30748af6d3d:~ $ ./turtle-example.hs
16661660Hello World!
16671661```
16681662
@@ -1680,11 +1674,30 @@ ensure the turtle package is available.
16801674If you're on Windows: you can run `stack turtle.hs` instead of `./turtle.hs`.
16811675The shebang line is not required in that case.
16821676
1677+ ### Using multiple packages
1678+
1679+ You can also specify multiple packages, either with multiple `--package`
1680+ arguments, or by providing a comma or space separated list. For example:
1681+
1682+ ```
1683+ #!/usr/bin/env stack
1684+ {- stack
1685+ script
1686+ --resolver lts-6.25
1687+ --package turtle
1688+ --package "stm async"
1689+ --package http-client,http-conduit
1690+ -}
1691+ ```
1692+
16831693### Stack configuration for scripts
16841694
1685- If the current working directory is inside a project then that project's stack
1686- configuration is effective when running the script. Otherwise the script uses
1687- the global project configuration specified in
1695+ With the `script` command, all Stack configuration files are ignored to provide a
1696+ completely reliable script running experience. However, see the example below
1697+ with `runghc` for an approach to scripts which will respect your configuration
1698+ files. When using `runghc`, if the current working directory is inside a
1699+ project then that project's stack configuration is effective when running the
1700+ script. Otherwise the script uses the global project configuration specified in
16881701`~/.stack/global-project/stack.yaml`.
16891702
16901703### Specifying interpreter options
@@ -1703,50 +1716,61 @@ separating the stack options and ghc options with a `--`. Here is an example of
17031716a multi line block comment with ghc options:
17041717
17051718```
1706- #!/usr/bin/env stack
1707- {- stack
1708- --resolver lts-3.2
1709- --install-ghc
1710- runghc
1711- --package turtle
1712- --
1713- -hide-all-packages
1714- -}
1719+ #!/usr/bin/env stack
1720+ {- stack
1721+ script
1722+ --resolver lts-6.25
1723+ --package turtle
1724+ --
1725+ +RTS -s -RTS
1726+ -}
17151727```
17161728
17171729### Writing independent and reliable scripts
17181730
1719- Independent means that the script is independent of any prior deployment
1720- specific configuration. If required, the script will install everything it
1721- needs automatically on any machine that it runs on. To make a script always
1722- work irrespective of any specific environment configuration you can do the
1723- following:
1731+ With the release of Stack 1.2.1, there is a new command, `script`, which will
1732+ automatically:
1733+
1734+ * Install GHC and libraries if missing
1735+ * Require that all packages used be explicitly stated on the command line
1736+
1737+ This ensures that your scripts are _independent_ of any prior deployment
1738+ specific configuration, and are _reliable_ by using exactly the same version of
1739+ all packages every time it runs so that the script does not break by
1740+ accidentally using incompatible package versions.
1741+
1742+ In previous versions of Stack, the `runghc` command was used for scripts
1743+ instead. In order to achieve the same effect with the `runghc` command, you can
1744+ do the following:
17241745
172517461. Use the `--install-ghc` option to install the compiler automatically
172617472. Explicitly specify all packages required by the script using the
17271748`--package` option. Use `-hide-all-packages` ghc option to force
17281749explicit specification of all packages.
1750+ 3. Use the `--resolver` Stack option to ensure a specific GHC version and
1751+ package set is used.
17291752
1730- Reliable means the script will use exactly the same version of all packages
1731- every time it runs so that the script does not break by accidentally using
1732- incompatible package versions. To achieve that use an explicit `--resolver`
1733- stack option.
1734-
1735- Here is an interpreter comment for a completely self-contained and reproducible
1736- version of our toy example:
1737- ```
1738- #!/usr/bin/env stack
1739- {- stack
1740- --resolver lts-3.2
1741- --install-ghc
1742- runghc
1743- --package base
1744- --package turtle
1745- --
1746- -hide-all-packages
1753+ Even with this configuration, it is still possible for configuration
1754+ files to impact `stack runghc`, which is why `stack script` is strongly
1755+ recommended in general. For those curious, here is an example with `runghc`:
1756+
1757+ ```
1758+ #!/usr/bin/env stack
1759+ {- stack
1760+ --resolver lts-6.25
1761+ --install-ghc
1762+ runghc
1763+ --package base
1764+ --package turtle
1765+ --
1766+ -hide-all-packages
17471767 -}
17481768```
17491769
1770+ The `runghc` command is still very useful, especially when you're working on a
1771+ project and want to access the package databases and configurations used by
1772+ that project. See the next section for more information on configuration files.
1773+
17501774## Finding project configs, and the implicit global
17511775
17521776Whenever you run something with stack, it needs a `stack.yaml` project file. The
0 commit comments