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