Skip to content

Commit

Permalink
Support GHC built from source
Browse files Browse the repository at this point in the history
We can now specify a specific GHC to build from source in `stack.yaml`
with the following syntax:

```
compiler-build:
   git: GHC_GIT_REPO
   commit: COMMIT
   flavour: FLAVOUR
```

In the setup phase Stack uses Hadrian to build a GHC binary distribution
with the specified flavour and installs it into
STACK_ROOT/programs/ARCH/ghc-git-COMMIT-FLAVOUR.

The built compiler can be used with the following configuration:

```
compiler: ghc-git-COMMIT-FLAVOUR
```

As GHC may rely on unreleased version of the global packages (e.g.
Cabal), you may have to add some extra-deps as follows:

```
extra-deps:
- git: GHC_GIT_REPO
  commit: COMMIT
  subdirs:
    - libraries/Cabal/Cabal
    - libraries/...
```
  • Loading branch information
hsyl20 committed Mar 29, 2019
1 parent b0f7a68 commit 295e270
Show file tree
Hide file tree
Showing 18 changed files with 302 additions and 43 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ Major changes:
builds, this functionality is no longer useful. For an example, please see
[Building Haskell Apps with
Docker](https://www.fpcomplete.com/blog/2017/12/building-haskell-apps-with-docker).
* Support building GHC from source (experimental)
* `stack.yaml` now supports setup configuration to build and install GHC
from source. The built GHC is uniquely identified by a commit id and an
Hadrian flavour (Hadrian is the newer GHC build system).
* `compiler` can be set to use a GHC built from source with
`ghc-git-COMMIT-FLAVOUR`

Behavior changes:
* `stack.yaml` now supports `snapshot`: a synonym for `resolver`. See [#4256](https://github.com/commercialhaskell/stack/issues/4256)
Expand Down
51 changes: 51 additions & 0 deletions doc/yaml_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,57 @@ compiler: ghcjs-0.1.0.20150924_ghc-7.10.2
compiler-check: match-exact
```

### compiler-build (experimental)

(Since 1.10.0)

Build a GHC compiler from source during the "setup" phase. The version to build
is defined by a Git commit id and an Hadrian flavour (Hadrian is the build
system of GHC). For instance:

```yaml
compiler-build:
git: https://gitlab.haskell.org/ghc/ghc.git
commit: 5be7ad7861c8d39f60b7101fd8d8e816ff50353a
flavour: quick
```

To use a built compiler you have to select it by its name which has the the
following form: "ghc-git-COMMIT-FLAVOUR". For example:

```yaml
compiler: ghc-git-5be7ad7861c8d39f60b7101fd8d8e816ff50353a-quick
```

#### Global packages

The GHC compiler you build from sources may depend on unreleased versions of
some global packages (e.g. Cabal). It may be an issue if a package you try to
build with this compiler depends on such global packages because Stack may not
be able to find versions of those packages (on Hackage, etc.) that are
compatible with the compiler.

The easiest way to deal with this issue is to add the relevant packages as
`extra-deps` built from source. To avoid mismatching versions, you can use
exactly the same commit id you used to build GHC as follows:

```
extra-deps:
- git: https://gitlab.haskell.org/ghc/ghc.git
commit: 5be7ad7861c8d39f60b7101fd8d8e816ff50353a
subdirs:
- libraries/Cabal/Cabal
- libraries/...
```

#### Bootstrapping compiler

Building GHC from source requires a working GHC (known as the bootstrap
compiler). As we use a Stack based version of Hadrian (`hadrian/build.stack.sh` in
GHC sources), the bootstrap compiler is configured into `hadrian/stack.yaml` and
fully managed by Stack.


### ghc-options

(Since 0.1.4)
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ library:
- Stack.Types.Build
- Stack.Types.BuildPlan
- Stack.Types.CompilerBuild
- Stack.Types.CompilerGitBuild
- Stack.Types.Compiler
- Stack.Types.Config
- Stack.Types.Config.Build
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ configFromConfigMonoid
configHideTHLoading = fromFirstTrue configMonoidHideTHLoading

configGHCVariant = getFirst configMonoidGHCVariant
configCompilerGitBuild = getFirst configMonoidCompilerGitBuild
configGHCBuild = getFirst configMonoidGHCBuild
configInstallGHC = fromFirstTrue configMonoidInstallGHC
configSkipGHCCheck = fromFirstFalse configMonoidSkipGHCCheck
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Config/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ nixCompiler compilerVersion =
_ -> "haskell.compiler.ghc" <> T.concat (x : y : minor)
_ -> Left $ stringException "GHC major version not specified"
WCGhcjs{} -> Left $ stringException "Only GHC is supported by stack --nix"
WCGhcGit{} -> Left $ stringException "Only GHC is supported by stack --nix"

-- Exceptions thown specifically by Stack.Nix
data StackNixException
Expand Down
2 changes: 2 additions & 0 deletions src/Stack/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ allExposedModules gpd = do
checkCond (PD.Impl compiler range) = case curCompiler of
ACGhc version ->
pure $ compiler == GHC && version `withinRange` range
ACGhcGit {} ->
pure $ compiler == GHC
ACGhcjs version _ghcVersion ->
pure $ compiler == GHCJS && version `withinRange` range
-- currently we don't do flag checking here
Expand Down
Loading

0 comments on commit 295e270

Please sign in to comment.