I posted this related topic a while ago:
So I’d say the optimization
field in cabal.project
files should be preferred over -O
in ghc-options
. To enable “-O2
” optimizations for all local and non-local dependencies I think you’d have to make a cabal.project file with these contents (note that all packages are already built with optimization level 1 by default):
packages: .
optimization: 2
package *
optimization: 2
(The difference between non-local and local is essentially whether it is from Hackage or directly from your machine.)
I think the remark about caching is only for local packages and blowing away the old build products should be as easy as running cabal clean
. For packages in the cabal store, cabal already tracks configuration options which I think includes optimization level to choose the right built package to use.