The dynamic-cabal package

[Tags: bsd3, library]

This library allows you to extract information from cabal files without depending on the Cabal library. Since GHC currently depends on Cabal, it's difficult to directly use Cabal if you also like to use the GHC API. This package solves that problem by using the GHC API itself to interface with Cabal, which means that it can use whatever Cabal version the user has installed, at run time (the version is not fixed at compile time). For a short tutorial, see Note: As of GHC 7.10, the ghc library no longer depends on Cabal. So you only need this package if you want to support older GHC versions.

[Skip to ReadMe]


Versions0.1, 0.2, 0.3, 0.3.1, 0.3.2, 0.3.3, 0.3.4, 0.3.5
Change logNone available
Dependenciesbase (>=4.4 && <5), containers, data-default, directory, filepath, ghc, ghc-paths, haskell-generate, haskell-src-exts, time, void [details]
CopyrightCopyright (C) 2013-2015 Benno Fünfstück
AuthorBenno Fünfstück
MaintainerBenno Fünfstück <>
Home page
Bug tracker
Source repositoryhead: git clone
UploadedSun Mar 29 15:29:34 UTC 2015 by BennoFuenfstueck
Downloads10631 total (48 in last 30 days)
0 []
StatusDocs available [build log]
Last success reported on 2015-03-29 [all 1 reports]




Maintainers' corner

For package maintainers and hackage trustees

Readme for dynamic-cabal-0.3.5


Build Status

Note: The problem this library solves no longer exists starting with GHC 7.10, since versions later than that do not depend on the Cabal library. You only need this library if you like to support older GHC versions.

If you've ever used Cabal together with the GHC-API, you know the problem. Because GHC depends on a version of Cabal, which is often outdated, there is no way to parse the setup-config file generated by newer cabal versions. This library attemps to solve the problem by dynamically generating code that performs the action you want, and then compiling and loading that with GHC. With this method, you don't need to depend on Cabal at compile time and so you can use any version of Cabal.


Currently, the library only allows two queries: Getting the targets (along with their dependencies, ghc options, etc) and the package databases. The first is easily achieved using the targets query provided by the library. To run the query, you can use the runQuery function, which takes the path to the setup-config file as an argument. For example, the following little program prints out the names of all test suites, when run in a configured cabal project root directory:

import Distribution.Client.Dynamic

main :: IO ()
main = do
  tgs <- runQuery (on localPkgDesc targets) "dist/setup-config"
  mapM_ putStrLn [ n | TestSuite n <- map name tgs ]

Because targets works on a PackageDescription, on localPkgDesc is used to get the current PackageDescription.


At the moment, I only implemented the functions I need myself. If you have more functions you want to implement, just send a pull request or open an issue.