Building GHC on Windows
This page documents the instructions for setting up a Windows build using MSYS2, which is a fairly complete build of MinGW + the MSYS2 tools.
This guide should get you running in ~5 minutes, modulo download speeds.
IMPORTANT: the msys2 installer creates multiple shortcuts, "MSYS2 Shell", "MinGW-w64 Win32 Shell" and "MinGW-w64 Win64 Shell". You need the latter one (or the middle one for 32-bit). The MSYS2 shell is set up for building applications with Cygwin which provides an additional POSIX compatibility layer, while MinGW is set up for building native Windows applications which is what we need for GHC.
An easy way to check that you are running the right shell is to check the output of echo $PATH. The first item of the list should be /mingw64/bin. Also, echo $MSYSTEM should show either MINGW32 or MINGW64.
If you are using a preexisting msys2 installation, consider upgrading all installed packages to the latest versions. That takes a few steps, see MSYS2 installation instructions (section III).
Installing packages & tools
The msys2 package uses pacman (the venerable ArchLinux package manager) to manage packages. Let's install system dependencies required for building GHC:
pacman -Sy git tar binutils autoconf make libtool automake python2 p7zip patch gcc
Host GHC setup
A host GHC binary is required for bootstrapping. Let's download and install a prebuilt GHC into /usr/local:
curl -L http://www.haskell.org/ghc/dist/7.8.3/ghc-7.8.3-$(uname -m | sed -e s/686/386/)-unknown-mingw32.tar.xz | tar -xJ -C /tmp && mkdir -p /usr/local && mv /tmp/ghc-7.8.3/* /usr/local && rmdir /tmp/ghc-7.8.3
curl -L http://www.haskell.org/cabal/release/cabal-install-126.96.36.199/cabal-188.8.131.52-i386-unknown-mingw32.tar.gz | tar -xz -C /usr/local/bin && cabal update && cabal install -j --prefix=/usr/local alex happy
A Quick Build
You should now be able to build GHC:
cd ~ && git clone --recursive git://git.haskell.org/ghc.git && cd ghc && ./sync-all get
Consider setting up mk/build.mk here (cp mk/build.mk.sample mk/build.mk && vim mk/build.mk).
Finally, to perform the actual build:
./boot && ./configure && make
Running parallel make (e.g., make -j5) is faster, but appears to cause segfaults during the build sometimes. The reasons are not clear yet.
Msys2 is known to be glitchy in some situations. If you see errors related to fork(), try closing and reopening the shell; see also msys2 issue #74. Also there have been issues with the build process segfaulting. The reason is not known (we're looking into it). If that happens, simply rerunning make will continue the build process.
Alternatively, to run a pristine build and tests (takes a while):
NOTE: You may see an error like make 7628 child_info_fork::abort: ... make: fork: Resource temporarily unavailable when running make. To fix this, go to the root of your MSYS dir and run autorebase.bat; see http://sourceforge.net/p/msys2/tickets/74/ as well.
Other documentation for Windows includes:
- MinGW/MSYS/Cygwin information for people new to using UNIX tools on Windows.
- Setting up a SSH Daemon on CygWin/MinGW and let's you treat Windows as yet another remote SSH session.
- Using MSYS1 to build GHC (not recommended any more)
- Using Cygwin to build GHC.
- Using SSH on Windows.
- Guidance on how to use Haskell on Windows