cabal-ghc-dynflags- Conveniently configure GHC's dynamic flags for use with Cabal projects

Safe HaskellNone




One of the challenges of using the GHC API for external tooling is handling integration with Cabal. This library provides a simple interface for configuring GHC's DynFlags as Cabal would have, allowing seamless tooling use on Cabal projects.

A typical usage might look like,

import GHC
import qualified GHC.Paths
import qualified Distribution.Verbosity as Verbosity
import GHC.Cabal

main = runGhc (Just GHC.Paths.libdir) $ do
    dflags <- GHC.getSessionDynFlags
    -- Use default DynFlags if we aren't in a Cabal project
    dflags' <- fromMaybe dflags <$> liftIO (initCabalDynFlags Verbosity.normal dflags)
    GHC.setSessionDynFlags dflags'

    -- Standard GHC API usage goes here


Initializing GHC DynFlags for Cabal packages

initCabalDynFlags :: Verbosity -> DynFlags -> IO (Maybe DynFlags) Source

Modify a set of DynFlags to match what Cabal would produce.