Building GHC on Windows
This guide should get you running in ~5 minutes, modulo download speeds.
Download and run the 64-bit MSYS2 installer. Be sure to open a mingw64 shell (see below).
Download and run the 32-bit MSYS2 installer. Be sure to open a mingw32 shell (see below).
The result of attempting to create a 32-bit build on a 64-bit machine has not been documented yet. Building on a 32-bit version of Windows works, of course.
Configuring MinGW properly
IMPORTANT: The MSYS2 installer creates multiple shortcuts, "MSYS2 Shell", "MinGW-w64 Win32 Shell" and "MinGW-w64 Win64 Shell". You do not want the "MSYS2 Shell." 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 $MSYSTEM. It should show either MINGW32 or MINGW64. You can also tell by examining the $PATH.
Consider upgrading all installed packages to the latest versions. See MSYS2 installation instructions (section III) for details.
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 docbook-xsl
Note: dblatex isn't available as a MSYS2 package, so the user's guide won't be build in ps and pdf format (only html).
It may be necessary to explicitly set the XML_CATALOG_FILES environment variable to convince configure that docbook is usable,
export XML_CATALOG_FILES="/etc/xml/docbook-xml /etc/xml/catalog"
Host GHC setup
A host GHC binary is required for bootstrapping. In order to keep different architectures separate, download and install a prebuilt GHC into /mingw64 or /mingw32:
So for 64-bit you'd run
curl -L http://www.haskell.org/ghc/dist/7.8.4/ghc-7.8.4-x86_64-unknown-mingw32.tar.xz | tar -xJ -C /mingw64 --strip-components=1
and for 32-bit you'd run
curl -L http://www.haskell.org/ghc/dist/7.8.4/ghc-7.8.4-i386-unknown-mingw32.tar.xz | tar -xJ -C /mingw32 --strip-components=1
Note: --strip-components=1 places everything within the archive's "ghc-7.8.4" folder directly into the target directory.
curl -L https://www.haskell.org/cabal/release/cabal-install-18.104.22.168/cabal-22.214.171.124-i386-unknown-mingw32.tar.gz | tar -xz -C /usr/local/bin && # for some version of cabal you may need to rename the exe to cabal.exe 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
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 --enable-tarballs-autodownload && 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/projects/mingw/files/MSYS/Extension/rebase/rebase-4.0.1_1-1/ and again http://sourceforge.net/p/msys2/tickets/74/. Alternatively, run shutdown //r.
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. (no longer supported)
- Using SSH on Windows.
- Guidance on how to use Haskell on Windows