How to pass command-line options to Alex in Cabal
Asked Answered
I

1

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?

Illbred answered 13/1, 2014 at 20:29 Comment(0)
P
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.

Polyzoan answered 13/1, 2014 at 21:33 Comment(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.Reinareinald
Just for further reference, here is the source file where the flags passed to Happy and Alex can be found. As @GabrielGonzalez mentioned, the -agc flags are passed automatically.Tandem

© 2022 - 2024 — McMap. All rights reserved.