Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit d9e1d80

Browse files
authored
Merge pull request #1200 from power-fungus/build-system-documentation
expand documentation on the build system
2 parents f00f674 + 35a4b4b commit d9e1d80

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

docs/Build.md

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,69 @@ The design of the build system has the following main goals:
1010

1111
* works identically on every platform
1212
* has minimal run-time dependencies:
13-
- a working installation of `stack`
13+
- `stack`
1414
- `git`
15-
* is completely functional right after simple `git clone`
16-
* one-stop-shop for building all executables required for using `hie` in IDEs.
15+
* is completely functional right after a simple `git clone` and after every `git pull`
16+
* one-stop-shop for building and naming all executables required for using `hie` in IDEs.
17+
* prevents certain build failures by either identifying a failed precondition (such as wrong `stack` version) or by performing the necessary steps so users can't forget them (such as invoking `git` to update submodules)
18+
19+
20+
* is able to modify the environment such that `hie` can be run
21+
- setup `hoogle` database
22+
- setup `hlint` data-files
1723

1824
See the project's `README` for detailed information about installing `hie`.
1925

20-
### Tradeoffs
26+
### Targets
2127

22-
#### `shake.yaml`
28+
The build script `install.hs` defines several targets using the `shake` build system. The targets are roughly:
2329

24-
A `shake.yaml` is required for executing the `install.hs` file.
30+
* `hie-*`: builds and installs the `hie` binaries. Also renames the binaries to contain the correct version-number.
31+
* `build`: builds and installs `hie` binaries for all supported `ghc` versions.
32+
* `build-doc`: builds the hoogle-db required by `hie`
33+
* `cabal-*`: execute the same task as the original target, but with `cabal` instead of `stack`
2534

26-
* It contains the required version of `shake`.
27-
* In contrast to the other `*.yaml` it does not contain the submodules, which is necessary for `stack` to work even before the submodules have been initialized.
35+
Each `stack-*.yaml` contains references to packages in the submodules. Calling `stack` with one of those causes the build to fail if the submodules have not been initialized already. The file `shake.yaml` solves this issue invoking the `git` binary itself to update the submodules. Moreover, it specifies the correct version of `shake` and is used for installing all run-time dependencies such as `cabal` and `hoogle` if necessary.
2836

29-
It is necessary to update the `resolver` field of the `shake.yaml` if the script should run with a different `GHC`.
37+
### Run-time dependencies
3038

31-
#### `install.hs` installs a GHC
39+
`hie` depends on a correct environment in order to function properly:
3240

33-
Before the code in `install.hs` can be executed, `stack` installs a `GHC`, depending on the `resolver` field in `shake.yaml`. This is necessary if `install.hs` should be completely functional right after a fresh `git clone` without further configuration.
41+
* `cabal-install`: If no `cabal` executable can be found or has an outdated version, `cabal-install` is installed via `stack`.
42+
* The `hoogle` database: `hoogle generate` needs to be called with the most-recent `hoogle` version.
3443

35-
This may lead to an extra `GHC` to be installed by `stack` if not all versions of `haskell-ide-engine` are installed.
44+
### Steps to build `hie`
45+
46+
Installing `hie` is a multi-step process:
47+
48+
1. `git submodule sync && git submodule update --init`
49+
2. `hoogle generate` (`hoogle>=5.0.17` to be safe)
50+
3. ensure that `cabal-install` is installed in the correct version
51+
4. `stack --stack-yaml=stack-<X>.yaml install` or `cabal new-install -w ghc-<X>`
52+
5. rename `hie` binary to `hie-<X>` in `$HOME/.local/bin`, where `<X>` is the GHC version used
53+
6. repeat step 4 and 5 for all desired GHC versions
54+
55+
This ensures that a complete install is always possible after each `git pull` or a `git clone`.
56+
57+
### Safety checks
58+
59+
The `install.hs` script performs some checks to ensure that a correct installation is possible and provide meaningful error messages for known issues.
60+
61+
* `stack` needs to be up-to-date. Version `1.9.3` is required
62+
* `ghc-8.6.3` is broken on windows. Trying to install `hie-8.6.3` on windows is not possible.
63+
* `cabal new-build` does not work on windows at the moment. All `cabal-*` targets exit with an error message about that.
64+
* When the build fails, an error message, that suggests to remove `.stack-work` directory, is displayed.
65+
66+
### Tradeoffs
3667

3768
#### `stack` is a build dependency
3869

3970
Currently, it is not possible to build all `hie-*` executables automatically without `stack`, since the `install.hs` script is executed by `stack`.
4071

41-
Other parts of the script also depend on `stack`:
42-
43-
* finding the local install-dir `stack path --local-bin`
44-
* finding and installing different `ghc` versions
72+
We are open to suggestions of other build systems that honor the requirements above, but are executable without `stack`.
4573

46-
#### `install.hs` executes `cabal install Cabal`
74+
#### `install.hs` installs a GHC before running
4775

48-
`ghc-mod` installs `cabal-helper` at runtime depending on the `ghc` used by the project, which can take a long time upon startup of `hie`. The `install.hs` script speeds up this process by calling `cabal install Cabal` upon build.
76+
Before the code in `install.hs` can be executed, `stack` installs a `GHC`, depending on the `resolver` field in `shake.yaml`. This is necessary if `install.hs` should be completely functional right after a fresh `git clone` without further configuration.
4977

50-
Hopefully, this behaviour can be removed in the future.
78+
This may lead to an extra `GHC` to be installed by `stack` if not all versions of `haskell-ide-engine` are installed.

0 commit comments

Comments
 (0)