windows.md 2.67 KB
Newer Older
1
# Building GHC on Windows
2

3 4
Here is how you can build GHC, from source, on Windows with minimal requirements.
We only assume that `git` and `stack` are installed (see
Andrey Mokhov's avatar
Andrey Mokhov committed
5
[prerequisites](https://gitlab.haskell.org/ghc/ghc/blob/master/hadrian/doc/windows.md#prerequisites)).
6

7 8
```
# Get GHC sources; git core.autocrlf should be set to false (see Prerequisites section)
9
git clone --recursive git@gitlab.haskell.org:ghc/ghc.git
10
cd ghc
11

12
# Download and install the bootstrapping GHC and MSYS2
Andrey Mokhov's avatar
Andrey Mokhov committed
13
cd hadrian
14
stack setup
15

16
# Install utilities required during the GHC build process
Andrey Mokhov's avatar
Andrey Mokhov committed
17
stack exec -- pacman -S autoconf automake-wrapper make patch python tar --noconfirm
18

19 20 21 22
# Build Hadrian and dependencies (including GHC dependencies Alex and Happy)
stack build

# Build GHC
23 24
# Note that the --configure flag is required only for the first build
stack exec hadrian -- --directory ".." -j --flavour=quickest --configure
25 26 27

# Test GHC
cd ..
28
_build\stage1\bin\ghc -e 1+2
Andrey Mokhov's avatar
Andrey Mokhov committed
29
```
30

31 32 33
The entire process should take about 20 minutes. Note, this will build GHC
without optimisations. If you need an optimised GHC, drop the `--flavour=quickest`
flag from the build command line (this will slow down the build to about an hour).
34 35

These are currently not the
36
[official GHC building instructions](https://gitlab.haskell.org/ghc/ghc/wikis/building/preparation/windows),
37 38
but are much simpler and may also be more robust.

39 40
The `stack build` and `stack exec hadrian` commands can be replaced by an
invocation of Hadrian's Stack-based build script:
41
`build-stack.bat -j --flavour=quickest`. Use this script if you plan to work on
42
Hadrian and/or rebuild GHC often.
43 44 45

## Prerequisites

46 47 48
The above works on a clean machine with `git` and `stack` installed (tested with
default installation settings), which you can get from
https://git-scm.com/download/win and
Andrey Mokhov's avatar
Andrey Mokhov committed
49
https://www.stackage.org/stack/windows-x86_64-installer.
50

51 52 53 54
Note that `git` should be configured to check out Unix-style line endings. The
default behaviour of `git` on Windows is to check out Windows-style line endings
which can cause issues during the build. This can be changed using the following
command:
Andrey Mokhov's avatar
Andrey Mokhov committed
55 56 57 58 59 60 61

    git config --global core.autocrlf false

If you would like to restore the default behaviour later run:

    git config --global core.autocrlf true

62 63 64
## Testing

These instructions have been tested on a clean Windows 10 machine using the
65 66 67
[free VirtualBox image](https://dev.windows.com/en-us/microsoft-edge/tools/vms/windows/).

**TODO:** It would be useful to test the instructions routinely on CI.
68 69 70

## Notes

71
Beware of the [current limitations of Hadrian](https://gitlab.haskell.org/ghc/ghc/blob/master/hadrian/README.md#current-limitations).