Skip to content

Commit ca76ced

Browse files
committed
Move GHC from source to its own topic, online
1 parent 1488a7f commit ca76ced

File tree

4 files changed

+170
-157
lines changed

4 files changed

+170
-157
lines changed

doc/configure/global_flags.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ for the [`skip-msys`](yaml/non-project.md#skip-msys) configuration option.
174174
Pass the option `--jobs <number_of_jobs>` to specify the number of concurrent
175175
jobs (Stack actions during building) to run.
176176

177-
When [building GHC from source](yaml/non-project.md#building-ghc-from-source),
178-
specifies the `-j[<n>]` flag of GHC's Hadrian build system.
177+
When [building GHC from source](../topics/GHC_from_source.md), specifies the
178+
`-j[<n>]` flag of GHC's Hadrian build system.
179179

180180
By default, Stack specifies a number of concurrent jobs equal to the number of
181181
CPUs (cores) that the machine has. In some circumstances, that default can cause

doc/configure/yaml/non-project.md

Lines changed: 4 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -305,164 +305,13 @@ compiler: ghc-9.8.3
305305
compiler-check: match-exact
306306
~~~
307307

308-
### Building GHC from source
309-
310308
:octicons-beaker-24: Experimental
311309

312310
[:octicons-tag-24: 2.1.1](https://github.com/commercialhaskell/stack/releases/tag/v2.1.1)
313311

314-
Stack supports building the GHC compiler from source, using
315-
[Hadrian](https://gitlab.haskell.org/ghc/ghc/blob/master/hadrian/README.md) (the
316-
build system for GHC). The GHC version to build and to use is defined by a a Git
317-
commit ID and a Hadrian "flavour", with the following syntax:
318-
319-
~~~yaml
320-
compiler: ghc-git-<commit_id>-<Hadrian_flavour>
321-
~~~
322-
323-
In the following example the commit ID is "5be7ad..." and the flavour is
324-
"quick":
325-
326-
~~~yaml
327-
compiler: ghc-git-5be7ad7861c8d39f60b7101fd8d8e816ff50353a-quick
328-
~~~
329-
330-
By default, the code is retrieved from the main GHC repository. If you want to
331-
select another repository, use the `compiler-repository` option:
332-
333-
~~~yaml
334-
compiler-repository: git://my/ghc/repository
335-
# default
336-
# compiler-repository: https://gitlab.haskell.org/ghc/ghc.git
337-
~~~
338-
339-
Stack does not check the compiler version when it uses a compiler built from
340-
source. It is assumed that the built compiler is recent enough as Stack does not
341-
enable any known workaround to make older compilers work.
342-
343-
Building the compiler can take a very long time (more than one hour). For faster
344-
build times, use Hadrian flavours that disable documentation generation.
345-
346-
### Bootstrap compiler
347-
348-
Building GHC from source requires a working GHC (known as the bootstrap
349-
compiler). As we use a Stack based version of Hadrian (`hadrian/build-stack` in
350-
GHC sources), the bootstrap compiler is configured into `hadrian/stack.yaml` and
351-
fully managed by Stack.
352-
353-
!!! note
354-
355-
For some commit IDs, the snapshot specified in `hadrian/stack.yaml`
356-
specifies a version of GHC that cannot be used to build GHC. This results in
357-
GHC's `configure` script reporting messages similar to the following before
358-
aborting:
359-
360-
~~~text
361-
checking version of ghc... 9.0.2
362-
configure: error: GHC version 9.2 or later is required to compile GHC.
363-
~~~
364-
365-
The resolution is: (1) to specify an alternative snapshot (one that
366-
specifies a sufficiently recent version of GHC) on the command line, using
367-
Stack's option `--snapshot <snapshot>`. Stack will use that snapshot when
368-
running GHC's `configure` script; and (2) to set the contents of the `STACK`
369-
environment variable to be `stack --snapshot <snapshot>`. Hadrian's
370-
`build-stack` script wil refer to that environment variable for the Stack
371-
command it uses.
372-
373-
### Hadrian prerequisites
374-
375-
The Hadrian build system has certain
376-
[prerequisites](https://gitlab.haskell.org/ghc/ghc/-/wikis/building/preparation).
377-
It requires certain versions of the `happy` and `alex` executables on the PATH.
378-
Stack will build and install `happy` and `alex`, if not already on the PATH.
379-
380-
=== "macOS"
381-
382-
Hadrian requires, or case use, certain tools or Python packages that do not
383-
come with macOS by default and that need to be installed using `brew` or
384-
`pip3` (Python). Hadrian's LaTeX documentation also requires the
385-
[DejaVu fonts](https://dejavu-fonts.github.io/) to be installed.
386-
387-
~~~zsh
388-
brew install [email protected]
389-
# GHC uses a Python script named `boot`.
390-
brew install automake
391-
# Tool for generating GNU Standards-compliant Makefiles.
392-
brew install texinfo
393-
# Official documentation format of the GNU project.
394-
pip3 install -U sphinx
395-
# Sphinx is the Python documentation generator.
396-
brew install --cask mactex
397-
# MacTeX: Full TeX Live distribution with GUI applications
398-
~~~
399-
400-
=== "Windows"
401-
402-
Hadrian requires, or can use, certain MSYS2 or Python packages that do not
403-
come with the Stack-supplied MSYS2 by default and need to be installed
404-
using `pacman` (MSYS2) or `pip` (Python). Hadrian's LaTeX documentation also
405-
requires the [DejaVu fonts](https://dejavu-fonts.github.io/) to be
406-
installed.
407-
408-
~~~pwsh
409-
stack exec -- pacman --sync --refresh
410-
# Synchronize MSYS2 package databases
411-
stack exec -- pacman --sync mingw-w64-x86_64-python-pip
412-
# The PyPA recommended tool (pip) for installing Python packages. Also
413-
# installs Python as a dependency. GHC uses a Python script named `boot`.
414-
# The package must be the one from the `mingw64` MSYS2 repository, as Python
415-
# from the `msys` repository cannot interpret Windows file paths correctly.
416-
stack exec -- pacman --sync mingw-w64-x86_64-autotools
417-
# The GNU autotools build system, including `autoreconf`, `aclocal`
418-
# and `make`. GHC uses a sh script named `configure` which is itself created
419-
# from a file named `configure.ac`.
420-
stack exec -- pacman --sync patch
421-
# A utility to apply patch files to original sources.
422-
stack exec -- pacman --sync texinfo
423-
# Utilities to work with and produce manuals, ASCII text, and on-line
424-
# documentation from a single source file, including `makeinfo`.
425-
stack exec -- pacman --sync mingw-w64-x86_64-ca-certificates
426-
# Common CA (certificate authority) certificates.
427-
stack exec -- pip install -U sphinx
428-
# Sphinx is the Python documentation generator.
429-
~~~
430-
431-
Hadrian may require certain LaTeX packages and may prompt for these to be
432-
installed duing the build process.
433-
434-
### Global packages
435-
436-
The GHC compiler you build from sources may depend on unreleased versions of
437-
some global packages (e.g. Cabal). It may be an issue if a package you try to
438-
build with this compiler depends on such global packages because Stack may not
439-
be able to find versions of those packages (on Hackage, etc.) that are
440-
compatible with the compiler.
441-
442-
The easiest way to deal with this issue is to use the
443-
[`drop-packages`](project.md#drop-packages) project-specific configuration
444-
option to drop the offending packages as follows. Instead of using the packages
445-
specified in the snapshot, the global packages bundled with GHC will be used.
446-
447-
~~~yaml
448-
drop-packages:
449-
- Cabal
450-
- ...
451-
~~~
452-
453-
Another way to deal with this issue is to add the relevant packages as
454-
[`extra-deps`](project.md#extra-deps) built from source. To avoid mismatching
455-
versions, you can use exactly the same commit id you used to build GHC as
456-
follows:
457-
458-
~~~
459-
extra-deps:
460-
- git: https://gitlab.haskell.org/ghc/ghc.git
461-
commit: '5be7ad7861c8d39f60b7101fd8d8e816ff50353a'
462-
subdirs:
463-
- libraries/Cabal/Cabal
464-
- libraries/...
465-
~~~
312+
Stack also supports building the GHC compiler from source. For further
313+
information, see the [building GHC from source](../../topics/GHC_from_source.md)
314+
documentation.
466315

467316
## compiler-check
468317

@@ -915,7 +764,7 @@ Command line equivalent (takes precedence):
915764
Specifies the number of concurrent jobs (principally, Stack actions during
916765
building - see further below) to run.
917766

918-
When [building GHC from source](#building-ghc-from-source), specifies the
767+
When [building GHC from source](../../topics/GHC_from_source.md), specifies the
919768
`-j[<n>]` flag of GHC's Hadrian build system.
920769

921770
In some circumstances, the default can cause some machines to run out of memory

doc/topics/GHC_from_source.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<div class="hidden-warning"><a href="https://docs.haskellstack.org/"><img src="https://cdn.jsdelivr.net/gh/commercialhaskell/stack/doc/img/hidden-warning.svg"></a></div>
2+
3+
# Building GHC from source
4+
5+
:octicons-beaker-24: Experimental
6+
7+
[:octicons-tag-24: 2.1.1](https://github.com/commercialhaskell/stack/releases/tag/v2.1.1)
8+
9+
Stack supports building the GHC compiler from source, using
10+
[Hadrian](https://gitlab.haskell.org/ghc/ghc/blob/master/hadrian/README.md) (the
11+
build system for GHC). The GHC version to build and to use is defined by a a Git
12+
commit ID and a Hadrian "flavour", with the following syntax in a YAML
13+
configuration file:
14+
15+
~~~yaml
16+
compiler: ghc-git-<commit_id>-<Hadrian_flavour>
17+
~~~
18+
19+
In the following example the commit ID is "5be7ad..." and the flavour is
20+
"quick":
21+
22+
~~~yaml
23+
compiler: ghc-git-5be7ad7861c8d39f60b7101fd8d8e816ff50353a-quick
24+
~~~
25+
26+
By default, the code is retrieved from the main GHC repository. If you want to
27+
select another repository, use the `compiler-repository` option in a YAML
28+
configuration file:
29+
30+
~~~yaml
31+
compiler-repository: git://my/ghc/repository
32+
# default
33+
# compiler-repository: https://gitlab.haskell.org/ghc/ghc.git
34+
~~~
35+
36+
Stack does not check the compiler version when it uses a compiler built from
37+
source. It is assumed that the built compiler is recent enough as Stack does not
38+
enable any known workaround to make older compilers work.
39+
40+
Building the compiler can take a very long time (more than one hour). For faster
41+
build times, use Hadrian flavours that disable documentation generation.
42+
43+
### Bootstrap compiler
44+
45+
Building GHC from source requires a working GHC (known as the bootstrap
46+
compiler). As we use a Stack based version of Hadrian (`hadrian/build-stack` in
47+
GHC sources), the bootstrap compiler is configured into `hadrian/stack.yaml` and
48+
fully managed by Stack.
49+
50+
!!! note
51+
52+
For some commit IDs, the snapshot specified in `hadrian/stack.yaml`
53+
specifies a version of GHC that cannot be used to build GHC. This results in
54+
GHC's `configure` script reporting messages similar to the following before
55+
aborting:
56+
57+
~~~text
58+
checking version of ghc... 9.0.2
59+
configure: error: GHC version 9.2 or later is required to compile GHC.
60+
~~~
61+
62+
The resolution is: (1) to specify an alternative snapshot (one that
63+
specifies a sufficiently recent version of GHC) on the command line, using
64+
Stack's option `--snapshot <snapshot>`. Stack will use that snapshot when
65+
running GHC's `configure` script; and (2) to set the contents of the `STACK`
66+
environment variable to be `stack --snapshot <snapshot>`. Hadrian's
67+
`build-stack` script wil refer to that environment variable for the Stack
68+
command it uses.
69+
70+
### Hadrian prerequisites
71+
72+
The Hadrian build system has certain
73+
[prerequisites](https://gitlab.haskell.org/ghc/ghc/-/wikis/building/preparation).
74+
It requires certain versions of the `happy` and `alex` executables on the PATH.
75+
Stack will build and install `happy` and `alex`, if not already on the PATH.
76+
77+
=== "macOS"
78+
79+
Hadrian requires, or case use, certain tools or Python packages that do not
80+
come with macOS by default and that need to be installed using `brew` or
81+
`pip3` (Python). Hadrian's LaTeX documentation also requires the
82+
[DejaVu fonts](https://dejavu-fonts.github.io/) to be installed.
83+
84+
~~~zsh
85+
brew install [email protected]
86+
# GHC uses a Python script named `boot`.
87+
brew install automake
88+
# Tool for generating GNU Standards-compliant Makefiles.
89+
brew install texinfo
90+
# Official documentation format of the GNU project.
91+
pip3 install -U sphinx
92+
# Sphinx is the Python documentation generator.
93+
brew install --cask mactex
94+
# MacTeX: Full TeX Live distribution with GUI applications
95+
~~~
96+
97+
=== "Windows"
98+
99+
Hadrian requires, or can use, certain MSYS2 or Python packages that do not
100+
come with the Stack-supplied MSYS2 by default and need to be installed
101+
using `pacman` (MSYS2) or `pip` (Python). Hadrian's LaTeX documentation also
102+
requires the [DejaVu fonts](https://dejavu-fonts.github.io/) to be
103+
installed.
104+
105+
~~~pwsh
106+
stack exec -- pacman --sync --refresh
107+
# Synchronize MSYS2 package databases
108+
stack exec -- pacman --sync mingw-w64-x86_64-python-pip
109+
# The PyPA recommended tool (pip) for installing Python packages. Also
110+
# installs Python as a dependency. GHC uses a Python script named `boot`.
111+
# The package must be the one from the `mingw64` MSYS2 repository, as Python
112+
# from the `msys` repository cannot interpret Windows file paths correctly.
113+
stack exec -- pacman --sync mingw-w64-x86_64-autotools
114+
# The GNU autotools build system, including `autoreconf`, `aclocal`
115+
# and `make`. GHC uses a sh script named `configure` which is itself created
116+
# from a file named `configure.ac`.
117+
stack exec -- pacman --sync patch
118+
# A utility to apply patch files to original sources.
119+
stack exec -- pacman --sync texinfo
120+
# Utilities to work with and produce manuals, ASCII text, and on-line
121+
# documentation from a single source file, including `makeinfo`.
122+
stack exec -- pacman --sync mingw-w64-x86_64-ca-certificates
123+
# Common CA (certificate authority) certificates.
124+
stack exec -- pip install -U sphinx
125+
# Sphinx is the Python documentation generator.
126+
~~~
127+
128+
Hadrian may require certain LaTeX packages and may prompt for these to be
129+
installed duing the build process.
130+
131+
### Global packages
132+
133+
The GHC compiler you build from sources may depend on unreleased versions of
134+
some global packages (e.g. Cabal). It may be an issue if a package you try to
135+
build with this compiler depends on such global packages because Stack may not
136+
be able to find versions of those packages (on Hackage, etc.) that are
137+
compatible with the compiler.
138+
139+
The easiest way to deal with this issue is to use the
140+
[`drop-packages`](../configure/yaml/project.md#drop-packages)
141+
project-specific configuration option to drop the offending packages as follows.
142+
Instead of using the packages specified in the snapshot, the global packages
143+
bundled with GHC will be used.
144+
145+
~~~yaml
146+
drop-packages:
147+
- Cabal
148+
- ...
149+
~~~
150+
151+
Another way to deal with this issue is to add the relevant packages as
152+
[`extra-deps`](../configure/yaml/project.md#extra-deps) built from source. To
153+
avoid mismatching versions, you can use exactly the same commit id you used to
154+
build GHC as follows:
155+
156+
~~~
157+
extra-deps:
158+
- git: https://gitlab.haskell.org/ghc/ghc.git
159+
commit: '5be7ad7861c8d39f60b7101fd8d8e816ff50353a'
160+
subdirs:
161+
- libraries/Cabal/Cabal
162+
- libraries/...
163+
~~~

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ nav:
114114
- Docker integration: topics/docker_integration.md
115115
- Nix integration: topics/nix_integration.md
116116
- Non-standard project initialization: topics/nonstandard_project_init.md
117+
- Building GHC from source: topics/GHC_from_source.md
117118
- Debugging: topics/debugging.md
118119
- Editor integration: topics/editor_integration.md
119120
- Stack and Visual Studio Code: topics/Stack_and_VS_Code.md

0 commit comments

Comments
 (0)