6

In my current project I have a file Tokens.x that needs to be compiled to Tokens.hs by Alex. In my .cabal file I have listed Tokens in the other-modules section and cabal build happily creates the file.

However it does so without the -g option that instructs Alex to create a GHC optimized version of the file. This option represents a 10x speed up in scanning when used with GHC and is also an order of magnitude faster to compile.

How do I tell cabal to included the -g option when compiling using GHC?

John F. Miller
  • 26,961
  • 10
  • 71
  • 121

1 Answers1

5

AFAIK, with Cabal you can currently only specify program options in the configuration file or via the command line, but not in a .cabal file.

There's an open issue about this: https://github.com/haskell/cabal/issues/1223

However, looking at the sources for Cabal, I find that your particular problem seems to be solved by default. In Distribution.Simple.PreProcess, there's:

ppAlex :: BuildInfo -> LocalBuildInfo -> PreProcessor
ppAlex _ lbi = pp { platformIndependent = True }
  where pp = standardPP lbi alexProgram (hcFlags hc)
        hc = compilerFlavor (compiler lbi)
        hcFlags GHC = ["-g"]
        hcFlags _ = []

This means that if Cabal is used with GHC, then -g is automatically passed to Alex when it's being used as a preprocessor.

kosmikus
  • 19,549
  • 3
  • 51
  • 66
  • 2
    I came across this when searching for the same answer for Happy and discover that Cabal also automatically supplies `-a -g -c` to all Happy invocations as recommended by the Happy manual. – Gabriella Gonzalez Sep 01 '14 at 03:17
  • 1
    Just for further reference, [here](https://github.com/haskell/cabal/blob/e28abb9ca321b74c82931d23d1e1cc75574ce4b9/Cabal/Distribution/Simple/PreProcess.hs) is the source file where the flags passed to Happy and Alex can be found. As @GabrielGonzalez mentioned, the `-agc` flags are passed automatically. – Damian Nadales Jul 17 '17 at 12:15