4

What is the difference between adding package_name under the build-depends: section in a project's .cabal file, versus doing stack install package_name within that project's directory?

duplode
  • 33,731
  • 7
  • 79
  • 150
Nicholas Montaño
  • 935
  • 10
  • 24
  • 1
    You may want to modify your question title, since "`import NAME` in project.cabal file" isn't very clear. Import statements belong in Haskell files, not .cabal files. – chreekat Sep 01 '15 at 00:27

1 Answers1

4

stack install will just install the package to the appropriate place (the current snapshot database for libraries in Stackage, the sandbox in ./.stack-work for other libraries, ~/.local/bin or your system's equivalent thereof for executables). Adding a library to build-depends specifies it as a dependency of your project, and leads to the library being installed next time you do a stack build. If you are actually using the library in your project you must add it to build-depends, otherwise you won't be able to build the project (or even play with the library using stack ghci).

N.B.: As of stack-0.1.3.1, stack install NAME is just a synonym for stack build --copy-bins NAME. The --copy-bins option tells stack to copy any executables to ~/.local/bin. If your package is just a library with no executables, stack install NAME is the same as stack build NAME.

duplode
  • 33,731
  • 7
  • 79
  • 150
  • Does that also pick the newest resolver each time, or does it read the closest stack.yaml, or does it use ~/.stack/config.yaml even if I'm in ~/src/my-stack-project? – unhammer Jun 16 '16 at 09:00
  • Also, can I put "dependencies" into the global config for `~` s.t. on a new computer I can just copy over my stack config file and `stack build` to get stuff like hindent, stylish-haskell and hlint? – unhammer Jun 16 '16 at 09:01