This page documents the instructions for setting up a Windows build using MSYS2, which contains MinGW-w64 compilers and the MSYS2 shell utilities. This guide should get you running in ~5 minutes, modulo download speeds.
After installing or extracting MSYS2 you should start MSYS2 by executing msys2_shell.cmd. (if you did not use an installer and this is first time running of MSYS2 after unpacking, then at this point it will create the files and settings necessary for it to function properly. After this initial run you MUST restart MSYS2 so that the settings are correct)
The result of attempting to create a 32-bit build of GHC on a 64-bit machine has not been documented yet. Building 32-bit GHC on a 32-bit version of Windows works, of course.
Launch the MinGW shell using the shortcuts added to Start Menu: MinGW-w64 Win32 Shell or MinGW-w64 Win64 Shell.
Do not use the MSYS2 Shell shortcut. MSYS2 Shell is for building applications that utilize an additional POSIX compatibility layer akin to Cygwin, while the MinGW-w64 shells are for building native Windows applications. The latter is the correct environment for building GHC. For details on the distinction between the two, read the introduction to MSYS2. 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.
After starting the shell, make sure /mingw64/bin (or /mingw32/bin depending on the arch you're building for) is the first thing on $PATH. If using Bash, echo "export PATH=/mingw<bitness>/bin:\$PATH" >>~/.bash_profile can be run to append your profile. Replace <bitness> with either 64 or 32 depending on platform.
This is required to ensure that the mingw-w64 variant of tools get priority over the msys versions.
Method B: Via Stack
This method has been reported to be unreliable, so use this at your own risk. The recommended method we use ourselves is "Method A" described above.
It is possible to set up MSYS indirectly through Stack:
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):