Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass command-line options to Alex in Cabal

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?

like image 427
John F. Miller Avatar asked Jan 13 '14 20:01

John F. Miller


1 Answers

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.

like image 108
kosmikus Avatar answered Sep 19 '22 15:09

kosmikus