Search code examples
haskellhappyhaskell-stack

How can I make Stack call Happy, Alex and other build tools?


As part of my compiler, I need alex and happy to run as part of my build process. How does Stack support this scenario?

Bonus: how can I register alex and happy as compile-time dependencies?


Solution

  • cabal understand the suffixes .x for alex files and .y for happy files and will automatically use alex and happy to build the corresponding .hs files.

    Steps to undertake:

    1. Add the .x and .y files to your extra-source-files: section
    2. Add alex and happy to your build-tools: section
    3. If your source file is Foo.Bar.x, make sure that Foo.Bar is listed in exposed-module: or in other-modules:

    A good example of a package using alex and happy is the language-python package:

    https://github.com/bjpop/language-python/blob/master/language-python.cabal (permalink)

    Update: This is relevant to stack as well. In fact, stack will also build alex and happy for you.