Stack cache builds with various flags

I have two different build commands that I use for my project

stack build -j8 --profile


stack build -j8  --ghc-options -DVERBOSE_SOLVING

There are hundreds of files in my projects. Whenever I change from one to the other command everything is rebuilt. Is there a way to keep the build increments of both?


  • You can tell stack where to keep the cache via --work-dir. The default is <project root>/.stack-work, but you can specify separate directories for your different build modes:

    stack build -j8 --profile --work-dir .stack-work-profile
    stack build -j8 --ghc-options -DVERBOSE_SOLVING --work-dir .stack-work-verbose-solving

    I don't think there is a way to have stack automatically figure out different caches based on flags. If you really need this, you could whip up a script that would take a hash of the flag combination and redirect work-dir to .stack-work-<hash> or something.