Skip to content

Latest commit

 

History

History
171 lines (136 loc) · 2.92 KB

stack.md

File metadata and controls

171 lines (136 loc) · 2.92 KB

Stack

  • Stack is a build tool
  • Stack is not a package manager
  • Curated package lists known to have no conflicts: resolvers
  • Sandbox builds by default
  • Reproducible builds

Global

  • Install packages globally using a given resolver
# outside of any stack projects
stack --resolver=lts-10.10 install hindent
  • Common packages to install globally
stack --resolver=lts-10.10 install hlint hindent stylish-haskell

hpack

  • package.yaml

  • Other way to generate cabal config files

    • Simplicity
    • Focus on Essentials
    • Less boilerplate
  • Generate .cabal file with hpack

hpack

Cabal

  • Package and dependency manager
  • Organize package with .cabal file
  • Stack is a layer on top of cabal

Docker Integration

# stack.yaml

docker:
  enable: true
  • Pass environment variables to the docker container
stack ghci --docker-env "FOO=BAR"
stack ghci --docker-env "FOO=BAR" --docker-env "BAZ=FOOZ"

New project

  • Creating new stack project
stack new project-name

Build

  • Build a target
stack build <target>
  • Never use stack install

  • Build project without optimization, for development

stack build --fast
  • Run tests along with the code
stack test --fast
stack build --fast --test
  • Build documentation
stack test --fast --haddock-deps
  • Rerun tests as code changes
stack test --fast --haddock-deps --file-watch
  • Force everything to be re-built, removes local cache
stack clean

Execution

  • Run specified executable from latest build
stack exec name-exe
  • Run ghci
stack ghci

Documentation

  • Open local documentation
stack haddock --open lens
  • Build the Hoogle Search Index
stack hoogle -- generate --local
  • Start Hoogle local webserver
stack hoogle -- server --local --port=8080

Configuring Project

Editor Integration

  • Build ghc-mod, hlint, hoogle, ...
stack build ghc-mod hlint hoogle

stack ghc

  • GHC will create a program if there is a module named Main and a main function. Otherwise use the -is-main ghc flag.
stack ghc -- -O2 src/Map.hs -main-is Map.main && src/Map

GHC warnings

  • Incomplete Pattern Matching
-Wincomplete-uni-patterns
  • Runtime Failable Record Update
-Wincomplete-record-updates
  • Redundant Constraints
-Wredundant-constraints
  • Missing Export List
-Wmissing-export-lists
  • Treat Warnings as Errors (use in CI only)
-Werror

Resources