htmue
htmue

Reputation: 51

How do the various ways of setting GHC options in haskell-stack work together

While setting up a deploy pipeline for optimised builds of a server application, I ran into some trouble getting the GHC options right with stack-1.6.5.

In particular, from the docs it doesn't get clear to me how the various ways to specify GHC options work together and when and how they are applied.

As far as I can tell, there are X ways of specifying GHC options:

I'd like to know which options are applied in the different build phases snapshots/locals/targets in which order and in which cases they are additive or override options given elsewhere.

Upvotes: 5

Views: 2563

Answers (1)

mgsloan
mgsloan

Reputation: 3295

good question, this is not adequately documented. These tend to be additive. Most of the logic for this is here: https://github.com/commercialhaskell/stack/blob/657937b0ac5dbef29114b43e9c69e2b57198af85/src/Stack/Build/Source.hs#L131 . Here's the order, where later items in the list come later in the options provided to ghc:

  • Options specified in the package.yaml / cabal file.
  • $everything in ghc-options in stack.yaml
  • $locals in ghc-options in stack.yaml
  • $targets in ghc-options in stack.yaml
  • Special options like -fhpc (--coverage) / fprof-auto -fprof-cafs (--profile) / -g (--no-strip).
  • Options specified via --ghc-options on the CLI

There is currently an issue where $everything / $locals / $targets ghc-options specified in .stack/config.yaml are not additive. Instead they are currently shadowed by the project stack.yaml. There is a PR fixing this, it will probably get merged at some point: https://github.com/commercialhaskell/stack/pull/3781

Upvotes: 4

Related Questions