A seemingly simple question… how does one compile a Cabal project with optimisations? At first, I thought it was just a matter of adding -O2
to ghc-options
; my only question was whether this needed to be added to library stanzas or not.
However, when I asked that question on the Discord server, I was pointed towards something quite different instead: the optimization
field in cabal.project
. What’s more, the documentation for that includes some rather worrying verbiage:
Note that as of GHC 8.0, GHC does not recompile when optimization levels change (see GHC issue #10923), so if you change the optimization level for a local package you may need to blow away your old build products in order to rebuild with the new optimization level.
This is quite vague about what kind of ‘blowing away’ is necessary. It almost sounds like it’s asking me to rm -rf ~/.cabal
… unless cabal clean
is sufficient? This is really confusing me.
So, my question is: what, precisely, do I need to do/change, in order to compile my Cabal project and all its dependencies with optimisations?