Commit 7733e44d authored by Ben Gamari's avatar Ben Gamari 🐢

Rip out hadrian subtree

Sadly subtrees haven't worked quite as well as we would have liked for
developers. See Hadrian #440.
parent 5695f462
:set -Wall -fno-warn-name-shadowing -isrc -i../libraries/Cabal/Cabal
:set -XDeriveFunctor
:set -XDeriveGeneric
:set -XFlexibleInstances
:set -XGeneralizedNewtypeDeriving
:set -XLambdaCase
:set -XRecordWildCards
:set -XScopedTypeVariables
:set -XTupleSections
:load Main
# generated by the configure script
cfg/system.config
# build.bat and build.sh specific
/bin/
# build.cabal.sh specific
/dist/
/.cabal-sandbox/
cabal.sandbox.config
# build.cabal-new.sh specific
/dist-newstyle/
.ghc.environment.*
# build.stack.sh and build.stack.bat specific
/.stack-work/
# the user settings
/UserSettings.hs
# Mostly temp file by emacs
*~
# ghcid output
/ghcid.txt
\ No newline at end of file
sudo: true
matrix:
include:
- os: linux
env: MODE="--flavour=quickest inplace/bin/ghc-stage1"
compiler: "GHC 8.0.2"
addons:
apt:
packages:
- ghc-8.0.2
- cabal-install-2.0
- zlib1g-dev
sources: hvr-ghc
before_install:
- PATH="/opt/ghc/8.0.2/bin:$PATH"
- PATH="/opt/cabal/2.0/bin:$PATH"
script:
# Run internal Hadrian tests
- ./build.sh -c selftest
# Build GHC
- ./build.sh -j -c $MODE --no-progress --progress-colour=never --profile=-
- os: linux
env: MODE="--flavour=quickest --integer-simple"
compiler: "GHC 8.2.1"
addons:
apt:
packages:
- ghc-8.2.1
- cabal-install-1.22
- zlib1g-dev
sources: hvr-ghc
before_install:
- PATH="/opt/ghc/8.2.1/bin:$PATH"
- PATH="/opt/cabal/1.22/bin:$PATH"
script:
# Build GHC
- ./build.sh -j -c $MODE --no-progress --progress-colour=never --profile=-
# Test GHC binary
- cd ..
- inplace/bin/ghc-stage2 -e 1+2
- os: osx
osx_image: xcode8
env: MODE="--flavour=quickest --integer-simple inplace/bin/ghc-stage1"
before_install:
- brew update
- brew install ghc cabal-install python3
script:
# Due to timeout limit of OS X build on Travis CI,
# we will ignore selftest and build only stage1
- ./build.sh -j -c $MODE --no-progress --progress-colour=never --profile=-
install:
# Add Cabal to PATH
- PATH="$HOME/.cabal/bin:$PATH"
- export PATH
- env
# Fetch GHC sources into ./ghc
- git --version
- git config --global url."git://github.com/ghc/packages-".insteadOf git://github.com/ghc/packages/
- git clone --depth 1 --recursive git://github.com/ghc/ghc
# --shallow-submodules is not supported on travis standard git 1.8 (linux), but it is supported
# on Travis Mac OS X machines. But it does not work with github mirrors because it cannot
# find commits.
# Install all Hadrian and GHC build dependencies
- cabal update
- cabal install alex happy
# GHC comes with an older version of Hadrian, so we delete it
- rm -r ghc/hadrian/*
# Travis has already cloned Hadrian into ./ and we need to move it
# to ./ghc/hadrian -- one way to do it is to move the .git directory
# and perform a hard reset in order to regenerate Hadrian files
- mv .git ghc/hadrian
- cd ghc/hadrian
- git reset --hard HEAD
cache:
directories:
- $HOME/.cabal
- $HOME/.ghc
MIT License
Copyright (c) 2014-2017 Andrey Mokhov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Hadrian
=======
[![Linux & OS X status](https://img.shields.io/travis/snowleopard/hadrian/master.svg?label=Linux%20%26%20OS%20X)](https://travis-ci.org/snowleopard/hadrian) [![Windows status](https://img.shields.io/appveyor/ci/snowleopard/hadrian/master.svg?label=Windows)](https://ci.appveyor.com/project/snowleopard/hadrian) [![OS X status](https://img.shields.io/circleci/project/github/snowleopard/hadrian.svg?label=OS%20X)](https://circleci.com/gh/snowleopard/hadrian)
Hadrian is a new build system for the [Glasgow Haskell Compiler][ghc]. It is based
on [Shake][shake] and we hope that it will soon replace the current
[Make-based build system][make]. If you are curious about the rationale behind the
project and the architecture of the build system you can find more details in
this [Haskell Symposium 2016 paper][paper] and this [Haskell eXchange 2016 talk][talk].
The new build system can work side-by-side with the existing build system. Note, there is
some interaction between them: they put (some) build results in the same directories,
e.g. the resulting GHC is `inplace/bin/ghc-stage2`.
Your first build
----------------
Beware, the build system is in the alpha development phase. Things are shaky and sometimes
break; there are numerous [known issues][issues]. Not afraid? Then put on the helmet and
run the following command from root of the GHC tree:
```
hadrian/build.sh -j
```
or on Windows:
```
hadrian/build.bat -j
```
Here flag `-j` enables parallelism and is optional. We will further refer to the build script
simply as `build`. Note that Hadrian can also run the `boot` and `configure` scripts
automatically if you pass the flag `--configure`, or simply `-c`. See the overview of
command line flags below.
Notes:
* If the default build script doesn't work, you might want to give a try to another one, e.g. based
on Cabal sandboxes (`build.cabal.*`), Stack (`build.stack.*`) or the global package database
(`build.global-db.*`). Also see [instructions for building GHC on Windows using Stack][windows-build].
* Hadrian is written in Haskell and depends on the following packages:
`ansi-terminal extra mtl quickcheck shake`.
* If you have never built GHC before, start with the [preparation guide][ghc-preparation].
Using the build system
----------------------
Once your first build is successful, simply run `build` to rebuild. Build results
are placed into `_build` and `inplace` directories.
#### Command line flags
In addition to standard Shake flags (try `--help`), the build system
currently supports several others:
* `--configure` or `-c`: use this flag to run the `boot` and `configure` scripts
automatically, so that you don't have to remember to run them manually as you normally
do when using Make (typically only in the first build):
```bash
./boot
./configure # On Windows run ./configure --enable-tarballs-autodownload
```
Beware that with this flag Hadrian may do network I/O on Windows to download necessary
tarballs, which may sometimes be undesirable.
* `--flavour=FLAVOUR`: choose a build flavour. The following settings are currently supported:
`default`, `quick`, `quickest`, `perf`, `prof`, `devel1` and `devel2`. As an example, the
`quickest` flavour adds `-O0` flag to all GHC invocations and builds libraries only in the
`vanilla` way, which speeds up builds by 3-4x. Build flavours are documented
[here](https://github.com/snowleopard/hadrian/blob/master/doc/flavours.md).
* `--freeze1`: freeze Stage1 GHC, i.e. do not rebuild it even if some of its source files
are out-of-date. This allows to significantly reduce the rebuild time when you are working
on a feature that affects both Stage1 and Stage2 compilers, but may lead to incorrect
build results. To unfreeze Stage1 GHC simply drop the `--freeze1` flag and Hadrian will
rebuild all out-of-date files.
* `--integer-simple`: build GHC using the `integer-simple` integer library (instead
of `integer-gmp`).
* `--progress-colour=MODE`: choose whether to use colours when printing build progress
info. There are three settings: `never` (do not use colours), `auto` (attempt to detect
whether the console supports colours; this is the default setting), and `always` (use
colours).
* `--progress-info=STYLE`: choose how build progress info is printed. There are four
settings: `none`, `brief` (one line per build command; this is the default setting),
`normal` (typically a box per build command), and `unicorn` (when `normal` just won't do).
* `--split-objects`: generate split objects, which are switched off by default. Due to
a GHC [bug][ghc-split-objs-bug], you need a full clean rebuild when using this flag.
* `--verbose`: run Hadrian in verbose mode. In particular this prints diagnostic messages
by Shake oracles.
#### User settings
The Make-based build system uses `mk/build.mk` to specify user build settings. We
use `hadrian/UserSettings.hs` for the same purpose, see [documentation](doc/user-settings.md).
#### Clean and full rebuild
* `build clean` removes all build artefacts.
* `build -B` forces Shake to rerun all rules, even if the previous build results are
are still up-to-date.
#### Documentation
To build GHC documentation, run `build docs`. Note that finer-grain documentation
targets (e.g. building only HTML documentation or only the GHC User's Guide)
are currently not supported.
#### Source distribution
To build a GHC source distribution tarball, run `build sdist-ghc`.
#### Installation
To build and install GHC artifacts, run `build install`.
By default, GHC will be installed to the specified _prefix_ path on your system,
relative to the root of the file system. For example on UNIX, GHC will be installed
to `/usr/local/bin`. By setting the command line flag `--install-destdir=[DESTDIR]`,
you can install GHC to path `DESTDIR/<prefix>` instead. Make sure you use correct
absolute path as `DESTDIR` on Windows, e.g. `C:/path`, which installs GHC
into `C:/path/usr/local`.
#### Testing
* `build validate` runs GHC tests by simply executing `make fast` in `testsuite/tests`
directory. This can be used instead of `sh validate --fast --no-clean` in the existing
build system. Note: this will rebuild Stage2 GHC, `ghc-pkg` and `hpc` if they are out of date.
* `build test` runs GHC tests by calling the `testsuite/driver/runtests.py` python
script with appropriate flags. The current implementation is limited and cannot
replace the `validate` script (see [#187][validation-issue]).
* `build selftest` runs tests of the build system. Current test coverage is close to
zero (see [#197][test-issue]).
Current limitations
-------------------
The new build system still lacks many important features:
* Validation is not implemented: [#187][validation-issue].
* Dynamic linking on Windows is not supported [#343][dynamic-windows-issue].
* There is no support for binary distribution: [#219][bin-dist-issue].
Check out [milestones] to see when we hope to resolve the above limitations.
How to contribute
-----------------
The best way to contribute is to try the new build system, report the issues
you found, and attempt to fix them. Please note: the codebase is very unstable
at present and we expect a lot of further refactoring. If you would like to
work on a particular issue, please let everyone know by adding a comment about
this. The issues that are currently on the critical path and therefore require
particular attention are listed in [#239](https://github.com/snowleopard/hadrian/issues/239).
Also have a look at [projects](https://github.com/snowleopard/hadrian/projects)
where open issues and pull requests are grouped into categories.
Acknowledgements
----------------
I started this project as part of my 6-month research visit to Microsoft
Research Cambridge, which was funded by Newcastle University, EPSRC, and
Microsoft Research. I would like to thank Simon Peyton Jones, Neil Mitchell
and Simon Marlow for kick-starting the project and for their guidance.
Zhen Zhang has done fantastic work on Hadrian as part of his Summer of
Haskell 2017 [project](https://summer.haskell.org/ideas.html#hadrian-ghc),
solving a few heavy and long-overdue issues. Last but not least, big thanks
to all other project [contributors][contributors], who helped me endure and
enjoy the project.
[ghc]: https://en.wikipedia.org/wiki/Glasgow_Haskell_Compiler
[shake]: https://github.com/ndmitchell/shake
[make]: https://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
[paper]: https://www.staff.ncl.ac.uk/andrey.mokhov/Hadrian.pdf
[talk]: https://skillsmatter.com/skillscasts/8722-meet-hadrian-a-new-build-system-for-ghc
[issues]: https://github.com/snowleopard/hadrian/issues
[ghc-preparation]: https://ghc.haskell.org/trac/ghc/wiki/Building/Preparation
[ghc-windows-quick-build]: https://ghc.haskell.org/trac/ghc/wiki/Building/Preparation/Windows#AQuickBuild
[windows-build]: https://github.com/snowleopard/hadrian/blob/master/doc/windows.md
[ghc-split-objs-bug]: https://ghc.haskell.org/trac/ghc/ticket/11315
[test-issue]: https://github.com/snowleopard/hadrian/issues/197
[validation-issue]: https://github.com/snowleopard/hadrian/issues/187
[dynamic-windows-issue]: https://github.com/snowleopard/hadrian/issues/343
[bin-dist-issue]: https://github.com/snowleopard/hadrian/issues/219
[milestones]: https://github.com/snowleopard/hadrian/milestones
[contributors]: https://github.com/snowleopard/hadrian/graphs/contributors
clone_folder: "c:\\new-hadrian"
environment:
global:
STACK_ROOT: "c:\\sr"
cache:
- "c:\\sr -> appveyor.yml"
install:
# Get Stack
- curl -ostack.zip -LsS --insecure https://www.stackage.org/stack/windows-x86_64
- 7z x stack.zip stack.exe
# Note: AppVeyor has already cloned Hadrian into c:\new-hadrian
# Fetch GHC sources into c:\ghc
- cd ..
- git clone --recursive git://git.haskell.org/ghc.git
# GHC comes with an older version of Hadrian, so we delete it
- rm -rf ghc\hadrian
# Copy new Hadrian into ./ghc/hadrian
- cp -r new-hadrian ghc\hadrian
# Install Alex and Happy
- set PATH=C:\Users\appveyor\AppData\Roaming\local\bin;%PATH%
- ghc\hadrian\stack install --install-ghc alex happy > nul
# Install all Hadrian and GHC build dependencies
- cd ghc\hadrian
- stack setup > nul
- appveyor-retry stack exec -- pacman -S autoconf automake-wrapper make patch python tar --noconfirm
build_script:
# Build Hadrian and run internal Hadrian tests
- build -c selftest
# Build GHC
- build -j -c --flavour=quickest --no-progress --progress-colour=never --profile=-
# Test GHC binary
- cd ..
- inplace\bin\ghc-stage2 -e 1+2
@echo off
setlocal
cd %~dp0
rem By default on Windows we build Hadrian using Stack
./build.stack.bat %*
#!/usr/bin/env bash
CABAL=cabal
set -euo pipefail
# readlink on os x, doesn't support -f, to prevent the
# need of installing coreutils (e.g. through brew, just
# for readlink, we use the follownig substitute.
#
# source: http://stackoverflow.com/a/1116890
function rl {
TARGET_FILE="$1"
cd "$(dirname "$TARGET_FILE")"
TARGET_FILE="$(basename "$TARGET_FILE")"
# Iterate down a (possible) chain of symlinks
while [ -L "$TARGET_FILE" ]
do
TARGET_FILE="$(readlink "$TARGET_FILE")"
cd "$(dirname "$TARGET_FILE")"
TARGET_FILE="$(basename "$TARGET_FILE")"
done
# Compute the canonicalized name by finding the physical path
# for the directory we're in and appending the target file.
PHYS_DIR="$(pwd -P)"
RESULT="$PHYS_DIR/$TARGET_FILE"
echo "$RESULT"
}
absoluteRoot="$(dirname "$(rl "$0")")"
cd "$absoluteRoot"
if ! type "$CABAL" > /dev/null; then
echo "Please make sure 'cabal' is in your PATH"
exit 2
fi
CABVERSTR=$("$CABAL" --numeric-version)
CABVER=( ${CABVERSTR//./ } )
if [ "${CABVER[0]}" -gt 2 -o "${CABVER[0]}" -eq 2 -a "${CABVER[1]}" -ge 1 ]; then
# New enough Cabal version detected, so let's use the superior new-build + new-run
# modes. Note that pre-2.1 Cabal does not support passing additional parameters
# to the executable (hadrian) after the separator '--', see #438.
"$CABAL" new-build --disable-profiling --disable-documentation -j exe:hadrian
"$CABAL" new-run hadrian -- \
--lint \
--directory "$absoluteRoot/.." \
"$@"
else
# The logic below is quite fragile, but it's better than nothing for pre-2.1 Cabal.
echo "Old pre cabal 2.1 version detected. Falling back to legacy 'cabal sandbox' mode."
# Initialize sandbox if necessary
if ! ( "$CABAL" sandbox hc-pkg list > /dev/null 2>&1); then
"$CABAL" sandbox init
"$CABAL" sandbox add-source ../libraries/Cabal/Cabal
"$CABAL" install \
--dependencies-only \
--disable-library-profiling \
--disable-shared
fi
"$CABAL" run hadrian -- \
--lint \
--directory "$absoluteRoot/.." \
"$@"
fi
@echo off
setlocal
cd %~dp0
mkdir bin 2> nul
set ghcArgs=--make ^
-Wall ^
-fno-warn-name-shadowing ^
-XRecordWildCards ^
src\Main.hs ^
-threaded ^
-isrc ^
-i..\libraries\Cabal\Cabal ^
-rtsopts ^
-with-rtsopts=-I0 ^
-outputdir=bin ^
-j ^
-O ^
-o bin\hadrian
set hadrianArgs=--lint ^
--directory ^
".." ^
%*
ghc %ghcArgs%
if %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
rem Unset GHC_PACKAGE_PATH variable, as otherwise ghc-cabal complains
set GHC_PACKAGE_PATH=
bin\hadrian %hadrianArgs%
#!/usr/bin/env bash
set -euo pipefail
# readlink on os x, doesn't support -f, to prevent the
# need of installing coreutils (e.g. through brew, just
# for readlink, we use the follownig substitute.
#
# source: http://stackoverflow.com/a/1116890
function rl {
TARGET_FILE="$1"
cd "$(dirname "$TARGET_FILE")"
TARGET_FILE="$(basename "$TARGET_FILE")"
# Iterate down a (possible) chain of symlinks
while [ -L "$TARGET_FILE" ]
do
TARGET_FILE="$(readlink "$TARGET_FILE")"
cd "$(dirname "$TARGET_FILE")"
TARGET_FILE="$(basename "$TARGET_FILE")"
done
# Compute the canonicalized name by finding the physical path
# for the directory we're in and appending the target file.
PHYS_DIR="$(pwd -P)"
RESULT="$PHYS_DIR/$TARGET_FILE"
echo "$RESULT"
}
root="$(dirname "$(rl "$0")")"
mkdir -p "$root/bin"
ghc \
"$root/src/Main.hs" \
-Wall \
-fno-warn-name-shadowing \
-XRecordWildCards \
-i"$root/src" \
-i"$root/../libraries/Cabal/Cabal" \
-rtsopts \
-with-rtsopts=-I0 \
-threaded \
-outputdir="$root/bin" \
-j -O \
-o "$root/bin/hadrian"
"$root/bin/hadrian" \
--lint \
--directory "$root/.." \
"$@"
\ No newline at end of file
#!/usr/bin/env bash
set -euo pipefail
# readlink on os x, doesn't support -f, to prevent the
# need of installing coreutils (e.g. through brew, just
# for readlink, we use the follownig substitute.
#
# source: http://stackoverflow.com/a/1116890
function rl {
TARGET_FILE="$1"
cd "$(dirname "$TARGET_FILE")"
TARGET_FILE="$(basename "$TARGET_FILE")"
# Iterate down a (possible) chain of symlinks
while [ -L "$TARGET_FILE" ]
do
TARGET_FILE="$(readlink "$TARGET_FILE")"
cd "$(dirname "$TARGET_FILE")"
TARGET_FILE="$(basename "$TARGET_FILE")"
done
# Compute the canonicalized name by finding the physical path
# for the directory we're in and appending the target file.
PHYS_DIR="$(pwd -P)"
RESULT="$PHYS_DIR/$TARGET_FILE"
echo "$RESULT"
}