How does cabal convert flags to ghc options?

206 Views Asked by At

I have a cabal project, which I'm building with new-build. I have configured my library to use -O0 when I pass a dev flag, and to use -O2 for production builds.

The relevant stanza in my cabal file is

if (flag(dev)) || (flag(library-only))
  ghc-options: -O0
  cpp-options: -DDEVELOPMENT
else
  ghc-options: -O2

However, if I do cabal new-build -f dev, cabal passes the -O1 option for some reason.

I can get around this by passing in --disable-optimization, but I'm curious why -f dev behaves this way

1

There are 1 best solutions below

0
On

As far as I know, this is because cabal passes -O1 by default, and adding the -O0 flag doesn't tell it to not pass the other flag :-)