34

With respect to how packages are created, installed and used in Haskell, what is the relationship between ghc-pkg and cabal?

What are their roles - when would you use one, over the other, or use both?

Are they complementary tools, competitive tools, or simply tools that do different jobs?

Ben Lever
  • 2,023
  • 7
  • 26
  • 34

2 Answers2

26

Graphically, the dependencies are:

Packages GHC can use
    | 
Are registered with "ghc-pkg register"
    |
And (almost always) built with Cabal
    |
With build dependencies resolved by cabal-install
    |
From Hackage.
Don Stewart
  • 137,316
  • 36
  • 365
  • 468
  • Is it true then that any package registerable with ghc-pkg must have been built with Cabal? – Norman Ramsey Apr 25 '10 at 03:31
  • 3
    No, that's not true. In the bad old days there was no Cabal, and we registered all our packages with make. 'make register' scripts abounded. See `ghc-pkg register` – Don Stewart Apr 25 '10 at 04:13
8

ghc-pkg is a direct interface to GHC's package database. Cabal is a tool that provides a consistent distribution structure for packages and a way to specify metadata such as dependencies between packages, version numbers, and build information.

Using Cabal to install a package will register it with ghc for you (among other things), but that's the extent of the overlap, really.

Note that ghc-pkg also provides functionality that (as far as I know) Cabal doesn't, such as hiding installed packages.

C. A. McCann
  • 76,893
  • 19
  • 209
  • 302