سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top