jamshidh
jamshidh

Reputation: 12060

How to avoid needless rebuilds with stack?

Stack usually caches package dependency builds to save time in future builds, but I've noticed many cases in practice where this doesn't happen. When it works, it can be a huge time-saver, as building dependencies can often take like half an hour or more.

After some work I've been able to isolate a simple example which illustrates this problem, and was wondering if someone could help me fix it. Note, this problem only refers to new builds, like after a clone.... The second build of the same clone does in fact go quickly.


If I compile this very simple Main.hs

import Network.Haskoin.Internals

main = undefined

using this stack.yaml

resolver: lts-2.15
packages:
- '.'
extra-deps: 
- haskoin-0.1.0.2
- json-rpc-0.2.1.6
- pbkdf-1.1.1.1
- text-1.1.1.4

flags: {}

and this .cabal file

name:                simple
version:             0.1.0.0
cabal-version:       >=1.10

executable simple-exe
  hs-source-dirs:      src
  main-is:             Main.hs
  build-depends:       base
                     , haskoin
  default-language:    Haskell2010

stack will rebuild every dependency every time I re-clone the source code.

I am guessing that it might have something to do with the extra-deps, in particular text-1.1.1.4, but don't know for sure.

Upvotes: 2

Views: 211

Answers (1)

ErikR
ErikR

Reputation: 52029

My understanding is that once you have selected a resolver, stack will "cache" a package if:

  1. The package is in Stackage for the resolver, and
  2. The package is built with exactly the same set of dependency-versions specified by the resolver.

The package-versions selected by the resolver LTS-2.15 may be found on this page:

https://www.stackage.org/lts-2.15

The "cache" on your machine for the resolver LTS-2.15 is located in a directory like:

~/.stack/snapshots/x86_64-osx/lts-2.15/7.8.4/pkgdb

For instance, your project uses blaze-builder-0.4.0.1 which is in Stackage LTS-2.15. However, blaze-builder depends on text, and if you were using the version of text in LTS-2.15 (namely text-1.2.0.6) then stack would cache blaze-builder-0.4.0.1 in the LTS-2.15 snapshot directory (assuming all of the other dependencies for blaze-builder matched the versions in LTS-2.15.) However, since you have specified version 1.1.1.4 for text, stack will not save the resulting blaze-builder in the LTS-2.15 snapshot directory. It will be saved in the .stack-work directory for the project.

Since so many packages depend on text, my recommendation would be to use a version of text which is listed in a Stackage resolver.

Upvotes: 4

Related Questions