Skip to content

Updating the Bootstrap Compiler

PÁLI Gábor János edited this page Mar 25, 2014 · 10 revisions

Generic Notes

GHC needs a working GHC in order to be built. This is currently solved by having a pre-built binary distribution of GHC prepared that is first installed and then used to build the sources.

  • GHC has some requirement on the version of the bootstrap compiler, something like version N.M can be only built with a compiler of version N.(M - 2) at least. For example, building the GHC 7.6.x ports requires a GHC 7.4.x bootstrap compiler at minimum. Usually it is fine to have the same version as the port itself, but since rolling a new version of the bootstrap out takes time and space, it is a good idea to change it only when it is really required.

  • The version of the bootstrap compiler is controlled by the BOOT_GHC_VERSION variable in the Makefile of lang/ghc. This should be always in sync with the bootstraps available in the distinfo file.

  • Optionally, the user may use the existing GHC by choosing the BOOT option at configure. Note that this is only available if ${LOCALBASE}/bin/ghc exists.

  • The bootstrap compiler is a lite version of the original compiler, without documentation and with the less (base system and port) dependencies as possible. However, those dependencies may change inevitably. In this case, the bootstrap for the affected versions and architectures must be rebuilt and lang/ghc must be updated.

  • The bootstraps shall be available for all supported operating system versions and architectures. As of the time of writing, this is 8.x (8.4), 9.x (9.1), 10.x (10.0), and head, for i386 (32-bit) and amd64 (64-bit). This means one shall maintain the bootstraps separately for every possible combination.

  • A pre-built binary for the compiler may be fetched from the GHC web site which may be then used for bootstrapping. It shall work for 8.4-RELEASE or later systems, although one may need to hack it around a bit (like installing the misc/compat8x port on non-8.x systems) to make it work.

Building the Bootstrap Compiler

Here are the recommended steps for rebuilding the bootstrap compiler.

Prerequisites

The following assumptions must be held for the build environment:

  • It must be a clean build environment, containing only the software components there are indispensable for the build. Hence setting up a separate jail(8) or chroot(8) environment for this purpose is highly recommended. The details of this is not elaborated here.

  • All the build tools must be available. This also means that if any of the run-time dependencies change in any incompatible way, a new bootstrap is needed. Currently this is only libiconv, but only on pre-10.x systems.

    • converters/libiconv (on pre-10.x systems only)
    • devel/autoconf
    • devel/automake
    • devel/binutils
    • devel/gmake
    • lang/gcc
    • lang/perl5.16
    • Some working version of GHC (see the Generic Notes above).

Note that the most problems will probably be with the last item, the working version of GHC. For this, there is no generic recipe. Try to make it work at all costs, otherwise it will not be possible to rebuild the bootstrap for the port.

Getting the GHC Sources

GHC sources, along with the pre-built binaries, can be found at its web site, in the dist directory by the versions:

http://www.haskell.org/ghc/dist/

For example, fetching the sources for version 7.6.3 can be done by:

# fetch http://www.haskell.org/ghc/dist/7.6.3/ghc-7.6.3-src.tar.bz2

Note that only the ghc-${GHC_VERSION}-src.tar.bz2 file is needed. Once it is downloaded, just unpack it:

# tar -xf ghc-7.6.3-src.tar.bz2

Configuring the Build

Before running the associated configure script, a customized build.mk file shall be created under the mk directory in the GHC source tree. This will help to cut down on the dependencies and build the lite version of the compiler. Note that the full list of build loptions can be found in the mk/build.mk.sample file.

# cd ghc-7.6.3
# echo GhcLibWays = v > mk/build.mk
# echo XMLDocWays = >> mk/build.mk
# echo HADDOCK_DOCS = >> mk/build.mk
# echo HSCOLOUR_SRCS = >> mk/build.mk
# echo INTEGER_LIBRARY = integer-simple >> mk/build.mk
# echo 'BIN_DIST_NAME = ghc-$(ProjectVersion)-boot' >> mk/build.mk
# echo 'BIN_DIST_TAR  = ghc-$(ProjectVersion)-boot.tar' >> mk/build.mk

Now the configure script may be run. On pre-10.x systems, the path of include and library directories for iconv(3) must be also specified:

# env CC=gcc47 ./configure --with-iconv-includes=$LOCALBASE/include --with-iconv-libraries=$LOCALBASE/lib \

so as the path for GCC and ld(1) from binutils:

  --with-gcc=gcc47 --with-ld=$LOCALBASE/bin/ld

where $LOCALBASE is usually /usr/local/.