Building GHC using cabal repl

Joachim Breitner mail at
Mon Apr 2 15:50:33 UTC 2018


when hacking on most Haskell projects these days, I enjoy having a
shell with

   ghcid -c 'cabal new-repl -w ghc-8.2'

open. I wondered if I can achieve the same when hacking on GHC. The
compiler/ directory has a Cabal file.

It does not work out-of-the box (in a fully built tree):

   $ cabal new-repl -w ../inplace/bin/ghc-stage2  -fstage2
   Build profile: -w ghc-8.5.20180320 -O1
   In order, the following will be built (use -v for more details):
    - ghc-8.5 (lib) (first run)
   Preprocessing library for ghc-8.5..
   cabal: can't find source for Config in backpack, basicTypes, cmm, codeGen,
   coreSyn, deSugar, ghci, hsSyn, iface, llvmGen, main, nativeGen, parser,
   prelude, profiling, rename, simplCore, simplStg, specialise, stgSyn, stranal,
   typecheck, types, utils, vectorise,

   cabal: repl failed for ghc-8.5.

It seems that the stage2/build directory is not registered as a source

   $ find -name Config.hs

But if I extend the section

        if flag(stage2)
            Include-Dirs: stage2

with these lines

            Include-Dirs: stage2/build
            hs-source-dirs: stage2/build
            ghc-options: -DSTAGE=2
            ghc-options: -fobject-code

and call cabal like so, it actually works:

   cabal new-repl -w ../inplace/bin/ghc-stage2  -fstage2

If I now make hdevtools use this line, then hacking on GHC will have a
bit less friction…

(BTW, does Hadrian have a “load all of GHC in GHCi” mode?)


Joachim “nomeata” Breitner
  mail at
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <>

More information about the ghc-devs mailing list