Skip to content

Commit bac18fe

Browse files
committed
Merge branch 'stable'
Also updates stack.cabal for the new *.md file.
2 parents f062b87 + 0089ebb commit bac18fe

File tree

6 files changed

+395
-283
lines changed

6 files changed

+395
-283
lines changed

doc/GUIDE.md

Lines changed: 21 additions & 250 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<div class="hidden-warning"><a href="https://docs.haskellstack.org/"><img src="https://cdn.jsdelivr.net/gh/commercialhaskell/stack/doc/img/hidden-warning.svg"></a></div>
22

3-
# User guide
3+
# User guide (introductory)
44

55
Stack is a modern, cross-platform build tool for Haskell code.
66

7-
This guide takes a new Stack user through the typical workflows. This guide will
8-
not teach Haskell or involve much code, and it requires no prior experience with
9-
the Haskell packaging system or other build tools. Terms used in the guide are
10-
defined in the [glossary](glossary.md).
7+
This introductory guide takes a new Stack user through the typical workflows.
8+
This guide will not teach Haskell or involve much code, and it requires no prior
9+
experience with the Haskell packaging system or other build tools. Terms used in
10+
the guide are defined in the [glossary](glossary.md).
11+
12+
Some of Stack's features will not be needed regularly or by all users. See the
13+
[advanced user's guide](GUIDE_advanced.md) for information about those features.
1114

1215
## Stack's functions
1316

@@ -79,7 +82,9 @@ package name first:
7982

8083
We'll call our project `helloworld`, and we'll use the `new-template` project
8184
template. This template is used by default, but in our example we will refer to
82-
it expressly. From the root directory for all our Haskell projects, we command:
85+
it expressly. Other templates are available, see the `stack templates` command.
86+
87+
From the root directory for all our Haskell projects, we command:
8388

8489
$ stack new helloworld new-template
8590

@@ -730,6 +735,16 @@ The reason we have this structure is that:
730735
As you probably guessed, there can be multiple snapshot databases available. See
731736
the contents of the `snapshots` directory in the Stack root.
732737

738+
* On Unix-like operating systems, each snapshot is in the last of a sequence of
739+
three subdirectories named after the platform, a 256-bit hash of the source
740+
map (how the package should be built -- including the compiler, options, and
741+
immutable dependencies), and the GHC version.
742+
743+
* On Windows, each snapshot is in a subdirectory that is a shorter hash (eight
744+
characters) of the sequence of three directories used on Unix-like operating
745+
systems. This is done to avoid problems created by default limits on file
746+
path lengths on Windows systems.
747+
733748
These snapshot databases don't get layered on top of each other; they are each
734749
used separately.
735750

@@ -1598,250 +1613,6 @@ __Other tools for comparison (including active and historical)__
15981613
constraints and snapshots, it did not work as well as hoped. It is deprecated
15991614
in favor of Stack.
16001615

1601-
## Fun features
1602-
1603-
This is just a quick collection of fun and useful feature Stack supports.
1604-
1605-
### Templates
1606-
1607-
We started off using the `new` command to create a project. Stack provides
1608-
multiple templates to start a new project from. For more information, command:
1609-
1610-
$ stack templates
1611-
1612-
You can specify one of these templates following your project name
1613-
in the `stack new` command:
1614-
1615-
$ stack new my-rio-project rio
1616-
Downloading template "rio" to create project "my-rio-project" in my-rio-project/ ...
1617-
Looking for .cabal or package.yaml files to use to init the project.
1618-
Using cabal packages:
1619-
- my-rio-project/
1620-
1621-
Selecting the best among 18 snapshots...
1622-
1623-
* Matches ...
1624-
1625-
Selected resolver: ...
1626-
Initialising configuration using resolver: ...
1627-
Total number of user packages considered: 1
1628-
Writing configuration to file: my-rio-project/stack.yaml
1629-
All done.
1630-
<Stack root>\templates\rio.hsfiles: 10.10 KiB downloaded...
1631-
1632-
The default templates repository is
1633-
https://github.com/commercialhaskell/stack-templates. You can download templates
1634-
from a different Github user by prefixing the username and a slash:
1635-
1636-
$ stack new my-yesod-project yesodweb/simple
1637-
1638-
Then template file `simple.hsfiles` would be downloaded from GitHub repository
1639-
`yesodweb/stack-templates`.
1640-
1641-
You can even download templates from a service other that GitHub, such as
1642-
[GitLab](https://gitlab.com) or [Bitbucket](https://bitbucket.com). For example:
1643-
1644-
$ stack new my-project gitlab:user29/foo
1645-
1646-
Template file `foo.hsfiles` would be downloaded from GitLab, user account
1647-
`user29`, repository `stack-templates`.
1648-
1649-
If you need more flexibility, you can specify the full URL of the template:
1650-
1651-
$ stack new my-project https://my-site.com/content/template9.hsfiles
1652-
1653-
(The `.hsfiles` extension is optional; it will be added if it's not specified.)
1654-
1655-
Alternatively you can use a local template by specifying the path:
1656-
1657-
$ stack new project <path_to_template>/template.hsfiles
1658-
1659-
As a starting point for creating your own templates, you can use the
1660-
["simple" template](https://github.com/commercialhaskell/stack-templates/blob/master/simple.hsfiles).
1661-
The
1662-
[stack-templates repository](https://github.com/commercialhaskell/stack-templates#readme)
1663-
provides an introduction into creating templates.
1664-
1665-
### Editor integration
1666-
1667-
For editor integration, Stack has a related project called
1668-
[intero](https://github.com/commercialhaskell/intero). It is particularly well
1669-
supported by Emacs, but some other editors have integration for it as well.
1670-
1671-
### Visualizing dependencies
1672-
1673-
If you'd like to get some insight into the dependency tree of your packages, you
1674-
can use the `stack dot` command and Graphviz. More information is available in
1675-
the [Dependency visualization documentation](dependency_visualization.md).
1676-
1677-
### Travis with caching
1678-
1679-
This content has been moved to a dedicated
1680-
[Travis CI document](https://docs.haskellstack.org/en/stable/travis_ci/).
1681-
1682-
### Shell auto-completion
1683-
1684-
Love tab-completion of commands? You're not alone. If you're on bash, just run
1685-
the following (or add it to `.bashrc`):
1686-
1687-
eval "$(stack --bash-completion-script stack)"
1688-
1689-
For more information and other shells, see the
1690-
[Shell auto-completion wiki page](https://docs.haskellstack.org/en/stable/shell_autocompletion)
1691-
1692-
### Docker
1693-
1694-
Stack is able to build your code inside a Docker image, which means even more
1695-
reproducibility to your builds, since you and the rest of your team will always
1696-
have the same system libraries.
1697-
1698-
### Nix
1699-
1700-
Stack provides an integration with [Nix](http://nixos.org/nix), providing you
1701-
with the same two benefits as the first Docker integration discussed above:
1702-
1703-
* more reproducible builds, since fixed versions of any system libraries and
1704-
commands required to build the project are automatically built using Nix and
1705-
managed locally per-project. These system packages never conflict with any
1706-
existing versions of these libraries on your system. That they are managed
1707-
locally to the project means that you don't need to alter your system in any
1708-
way to build any odd project pulled from the Internet.
1709-
* implicit sharing of system packages between projects, so you don't have more
1710-
copies on-disk than you need to.
1711-
1712-
When using the Nix integration, Stack downloads and builds Haskell dependencies
1713-
as usual, but resorts on Nix to provide non-Haskell dependencies that exist in
1714-
the Nixpkgs.
1715-
1716-
Both Docker and Nix are methods to *isolate* builds and thereby make them more
1717-
reproducible. They just differ in the means of achieving this isolation. Nix
1718-
provides slightly weaker isolation guarantees than Docker, but is more
1719-
lightweight and more portable (Linux and macOS mainly, but also Windows). For
1720-
more on Nix, its command-line interface and its package description language,
1721-
read the [Nix manual](http://nixos.org/nix/manual). But keep in mind that the
1722-
point of Stack's support is to obviate the need to write any Nix code in the
1723-
common case or even to learn how to use the Nix tools (they're called under the
1724-
hood).
1725-
1726-
For more information, see
1727-
[the Nix-integration documentation](nix_integration.md).
1728-
1729-
## Power user commands
1730-
1731-
The following commands are a little more powerful, and won't be needed by all
1732-
users. Here's a quick rundown:
1733-
1734-
* `stack update` will download the most recent set of packages from your package
1735-
indices (e.g. Hackage). Generally, Stack runs this for you automatically
1736-
when necessary, but it can be useful to do this manually sometimes.
1737-
* `stack unpack` is a command we've already used quite a bit for examples, but
1738-
most users won't use it regularly. It does what you'd expect: downloads a
1739-
tarball and unpacks it. It accept optional `--to` argument to specify
1740-
the destination directory.
1741-
* `stack sdist` generates an uploading tarball containing your package code
1742-
* `stack upload` uploads an sdist to Hackage. As of version
1743-
[1.1.0](https://docs.haskellstack.org/en/v1.1.0/ChangeLog/) Stack will also
1744-
attempt to GPG sign your packages as per
1745-
[our blog post](https://www.fpcomplete.com/blog/2016/05/stack-security-gnupg-keys).
1746-
* `--no-signature` disables signing of packages
1747-
* `--candidate` upload a
1748-
[package candidate](http://hackage.haskell.org/upload#candidates)
1749-
* Hackage API key can be used instead of username and password. Usage
1750-
example:
1751-
1752-
```bash
1753-
HACKAGE_KEY=<api_key> stack upload .
1754-
```
1755-
1756-
* `username` and `password` can be read by environment
1757-
1758-
```bash
1759-
export $HACKAGE_USERNAME="<username>"
1760-
export $HACKAGE_PASSWORD="<password>"
1761-
```
1762-
1763-
* `stack upgrade` will build a new version of Stack from source.
1764-
* `--git` is a convenient way to get the most recent version from the
1765-
`master` branch, for those testing and living on the bleeding edge.
1766-
* `stack ls snapshots` will list all the local snapshots by default. You can
1767-
also view the remote snapshots using `stack ls snapshots remote`. It also
1768-
supports option for viewing only lts (`-l`) and nightly (`-n`) snapshots.
1769-
* `stack ls dependencies` lists all of the packages and versions used for a
1770-
project
1771-
* `stack list [PACKAGE]...` list the version of the specified package(s) in a
1772-
snapshot, or without an argument list all the snapshot's package versions.
1773-
If no resolver is specified the latest package version from Hackage is given.
1774-
* `stack sig` subcommand can help you with GPG signing & verification
1775-
* `sign` will sign an sdist tarball and submit the signature to
1776-
sig.commercialhaskell.org for storage in the sig-archive git repo.
1777-
(Signatures will be used later to verify package integrity.)
1778-
1779-
## Debugging
1780-
1781-
To profile a component of the current project, simply pass the `--profile`
1782-
flag to `stack`. The `--profile` flag turns on the `--enable-library-profiling`
1783-
and `--enable-executable-profiling` Cabal options _and_ passes the `+RTS -p`
1784-
runtime options to any testsuites and benchmarks.
1785-
1786-
For example the following command will build the `my-tests` testsuite with
1787-
profiling options and create a `my-tests.prof` file in the current directory
1788-
as a result of the test run.
1789-
1790-
$ stack test --profile my-tests
1791-
1792-
The `my-tests.prof` file now contains time and allocation info for the test run.
1793-
1794-
To create a profiling report for an executable, e.g. `my-exe`, you can run
1795-
1796-
$ stack exec --profile -- my-exe +RTS -p
1797-
1798-
For more fine-grained control of compilation options there are the
1799-
`--library-profiling` and `--executable-profiling` flags which will turn on the
1800-
`--enable-library-profiling` and `--enable-executable-profiling` Cabal
1801-
options respectively. Custom GHC options can be passed in with
1802-
`--ghc-options "more options here"`.
1803-
1804-
To enable compilation with profiling options by default you can add the
1805-
following snippet to your `stack.yaml` or `~/.stack/config.yaml`:
1806-
1807-
```yaml
1808-
build:
1809-
library-profiling: true
1810-
executable-profiling: true
1811-
```
1812-
1813-
### Further reading
1814-
1815-
For more commands and uses, see the
1816-
[official GHC chapter on profiling](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/profiling.html),
1817-
the [Haskell wiki](https://wiki.haskell.org/How_to_profile_a_Haskell_program),
1818-
and the
1819-
[chapter on profiling in Real World Haskell](http://book.realworldhaskell.org/read/profiling-and-optimization.html).
1820-
1821-
### Tracing
1822-
1823-
To generate a backtrace in case of exceptions during a test or benchmarks run,
1824-
use the `--trace` flag. Like `--profile` this compiles with profiling options,
1825-
but adds the `+RTS -xc` runtime option.
1826-
1827-
### Debugging symbols
1828-
1829-
Building with debugging symbols in the
1830-
[DWARF information](https://ghc.haskell.org/trac/ghc/wiki/DWARF) is supported by
1831-
Stack. This can be done by passing the flag `--ghc-options="-g"` and also to
1832-
override the default behaviour of stripping executables of debugging symbols by
1833-
passing either one of the following flags: `--no-strip`,
1834-
`--no-library-stripping` or `--no-executable-stripping`.
1835-
1836-
In Windows, GDB can be installed to debug an executable with
1837-
`stack exec -- pacman -S gdb`. Windows' Visual Studio compiler's debugging
1838-
format PDB is not supported at the moment. This might be possible by
1839-
[separating](https://stackoverflow.com/questions/866721/how-to-generate-gcc-debug-symbol-outside-the-build-target)
1840-
debugging symbols and
1841-
[converting](https://github.com/rainers/cv2pdb) their format. Or as an option
1842-
when
1843-
[using the LLVM backend](http://blog.llvm.org/2017/08/llvm-on-windows-now-supports-pdb-debug.html).
1844-
18451616
## More resources
18461617

18471618
There are lots of resources available for learning more about Stack:

0 commit comments

Comments
 (0)