haskell stack to make executables for a project that do not use the library

Viewed 54

I have a haskell project that is mainly a library. To run some benchmarks I also have some small utilities for checking that some results are correct, also written in haskell. These utilities do not require the library to run and they are almost never built with debugging turned on. Here is an abbreviated version of package.yaml

name: mypkg
version: 0.1.0.1

library:
  source-dirs: src
  exposed-modules:
    - Data.MyPkg
  dependencies:
    - base >= 4.7 && < 5
    - ghc >= 8.6.5

benchmarks:
  benchmark:
    main: Main.hs
    source-dirs: tools/Benchmark
    ghc-options: -DSOME_STUFF
    dependencies:
      - base >= 4.7 && < 5
      - ghc >= 8.6.5
      - mypkg

executables:
  checkresult:
    main: Main.hs
    source-dirs: tools/CheckResult
    dependencies:
      - base >= 4.7 && < 5
      - ghc >= 8.6.5

I run the benchmarks with a script that looks like this:

#!/bin/bash

echo "Building the benchmark"
if [[ "$1" = "verbose" ]]; then
  stack --work-dir .verbose-stack-dir/ build -j 4 --ghc-options -DMYPKG_VERBOSE mypkg:bench:benchmark;
else
  stack --work-dir .nonverbose-stack-dir/ build -j 4 mypkg:bench:benchmark
endif

echo "Checking results"
stack run mypkg:exe:checkresult

But when stack run mypkg:exe:checkresult runs the library is rebuilt even though checkresult does not depend on the library. Is there a way to disable that?

0 Answers
Related