wiki:Debugging/InstallingPackagesInplace

Version 8 (modified by slyfox, 4 years ago) (diff)

fixed typo

Installing packages in your test compiler

You have your compiler built, so you can use the inplace compiler to compile test programs. This lives in $(TOP)/inplace/bin/ghc-stage2 (see Commentary/SourceTree).

Every GHC, including the inplace one, comes with the boot libraries. But sometimes a test case will require the installation of some packages from Hackage. There are two routes.

Plan A: Cabal is up to date

If your installed cabal is sufficiently up to date, you can just use cabal install:

cabal install --with-ghc=<inplace-ghc> --global <package>

where <inplace ghc> is the path to your inplace GHC (usually $(TOP)/inplace/bin/ghc-stage2), and <package> is the name of the package.

Points to note:

  • This will install the package in your home directory (e.g. somewhere under ~/.cabal/lib on a Unix system) , so you'll probably want to remove it by hand when you've finished.
  • The --global says to register the package in the global database, which for the inplace compiler is something like $(TOP)/inplace/lib/package.conf.d/. The default is --local which registers the package in a (compiler-version-specific) directory in your home directly. The danger is that you you have many builds, the "compiler-version-specific" part might not be enough to keep all your builds separate.

Plan A can fail, because sometimes Cabal changes, so you might get a message like

cabal: failed to parse output of 'ghc-pkg dump'

In that case you need to use the Cabal code that comes with the new version of GHC (ie the one in your build tree). So use Plan B.

Plan B: Cabal is out of date

Go to a directory where you are happy to keep the newly-downloaded code.

cabal unpack <package>
cd <package>
<inplace-ghc> --make Setup.lhs -o Setup
./Setup configure --with-ghc=<inplace-ghc> --global
./Setup build
./Setup register --inplace

Points to note here:

  • The first step can be done manually, by downloading a zip file from Hackage, or by doing a darcs get from the appropriate repo. For example:
    darcs get http://darcs.haskell.org/packages/parallel
    
    Nevertheless, cabal unpack should work for any Hackage package, even if Cabal has changed a bit. (Because fetching and unpacking is one of Cabal's less sophisticated operations.)
  • It is important to compile Setup.lhs with your shiny new inplace GHC, not your installed GHC. Your inplace GHC has the most up-to-date Cabal library, and that is what you want to link Setup.lhs against.
  • The --global flag has the same purpose as in Plan A

  • The --inplace flag to register tells Cabal not to copy the compiled package, but rather to leave it right where it is, and register this location in the package database in your GHC build tree