Skip to content

Commit 93b235d

Browse files
committed
Fix #6820 Update building GHC from source
1 parent fd667d6 commit 93b235d

File tree

7 files changed

+250
-121
lines changed

7 files changed

+250
-121
lines changed

ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Behavior changes:
1919
`ls dependencies` command, so that the nodes of
2020
`stack dot --external --depth 0` are the same as the packages listed by
2121
`stack ls dependencies --depth 0`.
22+
* When building GHC from source, on Windows, the default Hadrian build target is
23+
`reloc-binary-dist` and the default path to the GHC built by Hadrian is
24+
`_build/reloc-bindist`.
2225

2326
Other enhancements:
2427

@@ -33,6 +36,10 @@ Other enhancements:
3336
specified).
3437
* Add option `-w` as synonym for `--stack-yaml`.
3538
* `stack new` now allows `codeberg:` as a service for template downloads
39+
* In YAML configuration files, the `compiler-target` and
40+
`compiler-bindist-path` keys are introduced to allow, when building GHC from
41+
source, the Hadrian build target and Hadrian path to the built GHC to be
42+
specified.
3643

3744
Bug fixes:
3845

doc/topics/GHC_from_source.md

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ In the following example the commit ID is "5be7ad..." and the flavour is
2323
compiler: ghc-git-5be7ad7861c8d39f60b7101fd8d8e816ff50353a-quick
2424
~~~
2525

26+
The [`-j`, `--jobs` option](../configure/global_flags.md#-jobs-or-j-option) at
27+
the command line or the [`jobs`](../configure/yaml/non-project.md#jobs) option
28+
in a YAML configuraton file can be used to specify Hadrian's `-j[<n>]` flag.
29+
2630
By default, the code is retrieved from the main GHC repository. If you want to
2731
select another repository, use the `compiler-repository` option in a YAML
2832
configuration file:
@@ -33,6 +37,40 @@ compiler-repository: git://my/ghc/repository
3337
# compiler-repository: https://gitlab.haskell.org/ghc/ghc.git
3438
~~~
3539

40+
By default, the Hadrian build target is `reloc-binary-dist` on Windows and
41+
`binary-dist` on other operating systems. If you want to specify another
42+
Hadrian build target, use the `compiler-target` option in a YAML configuration
43+
file:
44+
45+
~~~yaml
46+
compiler-target: binary-dist
47+
# default (Windows)
48+
# compiler-target: reloc-binary-dist
49+
# default (non-Windows)
50+
# compiler-target: binary-dist
51+
~~~
52+
53+
By default, Stack assumes that the path to the binary distribution built by
54+
Hadrian is `_build/reloc-bindist` on Windows and `_build/bindist` on other
55+
operating systems. If you want to specify another path, use the
56+
`compiler-bindist-path` option in a YAML configuration file:
57+
58+
~~~yaml
59+
compiler-bindist-path: _build/bindist
60+
# default (Windows)
61+
# compiler-bindist-path: _build/reloc-bindist
62+
# default (non-Windows)
63+
# compiler-bindist-path: _build/bindist
64+
~~~
65+
66+
!!! note
67+
68+
The Hadrian build target `reloc-binary-dist` was introduced with Git commit
69+
id
70+
[`fe23629b147d419053052e6e881f6e8ddfbf3bae`](https://gitlab.haskell.org/ghc/ghc/-/commit/fe23629b147d419053052e6e881f6e8ddfbf3bae).
71+
72+
Once introduced, the target must be used on Windows.
73+
3674
Stack does not check the compiler version when it uses a compiler built from
3775
source. It is assumed that the built compiler is recent enough as Stack does not
3876
enable any known workaround to make older compilers work.
@@ -65,13 +103,17 @@ fully managed by Stack.
65103
configure: error: GHC version 9.2 or later is required to compile GHC.
66104
~~~
67105

68-
The resolution is: (1) to specify an alternative snapshot (one that
69-
specifies a sufficiently recent version of GHC) on the command line, using
70-
Stack's option `--snapshot <snapshot>`. Stack will use that snapshot when
71-
running GHC's `configure` script; and (2) to set the contents of the `STACK`
72-
environment variable to be `stack --snapshot <snapshot>`. Hadrian's
73-
`build-stack` script wil refer to that environment variable for the Stack
74-
command it uses.
106+
The resolution is:
107+
108+
1. to specify an alternative snapshot (one that specifies a sufficiently
109+
recent version of GHC) on the command line, using Stack's option
110+
`--snapshot <snapshot>`. Stack will use that snapshot when running GHC's
111+
`configure` script; and
112+
113+
2. to set the contents of the `STACK` environment variable to be
114+
`stack --snapshot <snapshot>`. If `<snapshot>` is a path to a local YAML
115+
file, it needs to be an absolute one. Hadrian's `build-stack` script
116+
will refer to that environment variable for the Stack command it uses.
75117

76118
### Hadrian prerequisites
77119

@@ -127,8 +169,10 @@ Stack will build and install `happy` and `alex`, if not already on the PATH.
127169
# documentation from a single source file, including `makeinfo`.
128170
stack exec -- pacman --sync mingw-w64-x86_64-ca-certificates
129171
# Common CA (certificate authority) certificates.
130-
stack exec -- pip install -U sphinx
172+
stack exec -- pacman -sync mingw-w64-x86_64-python-sphinx
131173
# Sphinx is the Python documentation generator.
174+
stack exec -- pacman -sync mingw-w64-x86_64-texlive-full
175+
# The TeX Live distribution.
132176
~~~
133177

134178
Hadrian may require certain LaTeX packages and may prompt for these to be

src/Stack/Config.hs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ import Stack.Types.Build.Exception
113113
import Stack.Types.BuildConfig ( BuildConfig (..) )
114114
import Stack.Types.BuildOpts ( BuildOpts (..) )
115115
import Stack.Types.ColorWhen ( ColorWhen (..) )
116-
import Stack.Types.Compiler ( defaultCompilerRepository )
116+
import Stack.Types.Compiler
117+
( defaultCompilerBindistPath, defaultCompilerRepository
118+
, defaultCompilerTarget
119+
)
117120
import Stack.Types.Config
118121
( Config (..), HasConfig (..), askLatestSnapshotUrl
119122
, configProjectRoot, stackRootL, workDirL
@@ -286,6 +289,12 @@ configFromConfigMonoid
286289
compilerRepository = fromFirst
287290
defaultCompilerRepository
288291
configMonoid.compilerRepository
292+
compilerTarget = fromFirst
293+
defaultCompilerTarget
294+
configMonoid.compilerTarget
295+
compilerBindistPath = fromFirst
296+
defaultCompilerBindistPath
297+
configMonoid.compilerBindistPath
289298
ghcBuild = getFirst configMonoid.ghcBuild
290299
installGHC = fromFirstTrue configMonoid.installGHC
291300
installMsys = fromFirst installGHC configMonoid.installMsys
@@ -595,6 +604,8 @@ configFromConfigMonoid
595604
, msysEnvironment
596605
, compilerCheck
597606
, compilerRepository
607+
, compilerTarget
608+
, compilerBindistPath
598609
, localBin
599610
, fileWatchHook
600611
, requireStackVersion

0 commit comments

Comments
 (0)