Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Use Cabal directly in place of ghc-cabal + make build root configurable #531

Merged
merged 28 commits into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
df9ffa8
Use Cabal directly in place of ghc-cabal; make build root configurable.
alpmestan Feb 23, 2018
8298dad
fix documentation rules
alpmestan Mar 19, 2018
42f5b6f
remove some leftover unrelated, commented-out code
alpmestan Mar 19, 2018
0f85e35
more documentation fixes, address some feedback
alpmestan Mar 20, 2018
e23a3d9
cleanup
alpmestan Mar 21, 2018
c99df2c
more cleanup
alpmestan Mar 21, 2018
edb7fa9
boot and configure explicitly in travis CI scripts
alpmestan Mar 21, 2018
e8daefc
update cabal/ghc versions in .travis.yml (8.0.x not supported anymore)
alpmestan Mar 21, 2018
cab4c6d
temporarily disable dynamic ways in Settings.Default
alpmestan Mar 22, 2018
6c29fe2
update appveyor script
alpmestan Mar 22, 2018
e4204f1
travis: when booting with 8.2.2, build a complete stage2 compiler
alpmestan Mar 22, 2018
3c5da99
Fix CI?
angerman Mar 23, 2018
6052655
Update Quickest.hs
angerman Mar 23, 2018
7764235
Update .travis.yml
angerman Mar 23, 2018
9451654
Update .travis.yml
angerman Mar 23, 2018
81c736d
[travis] os x: test the freshly built ghc
alpmestan Mar 23, 2018
a89b21f
Get rid of two unused GhcCabalMode constructors
alpmestan Mar 26, 2018
7f5753c
fix ghc-split rule, get rid of Install/Wrappers rules
alpmestan Mar 27, 2018
6df0c57
address more feedback
alpmestan Mar 28, 2018
65de601
ConfiguredCabal -> PackageData, more comments, more feedback addressed
alpmestan Mar 28, 2018
cb4fbc7
make the complete stage 2 build the default
alpmestan Mar 28, 2018
7818701
use a dummy package instead of base in Rules.hs
alpmestan Mar 28, 2018
a736fde
update CI scripts
alpmestan Mar 28, 2018
75c6aac
attempt at fixing hadrian's -c option
alpmestan Mar 28, 2018
894a197
.travis.yml: use -c everywhere again
alpmestan Mar 29, 2018
03eda8a
travis: back to explicit './boot && ./configure'
alpmestan Mar 29, 2018
770be1c
update README.md and doc/user-settings.md to reflect configurable bui…
alpmestan Mar 30, 2018
c569957
some more feedback
alpmestan Mar 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 50 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,91 @@ sudo: true
matrix:
include:
- os: linux
env: MODE="--flavour=quickest inplace/bin/ghc-stage1"
compiler: "GHC 8.0.2"
env: MODE="selftest"
compiler: "GHC 8.2.2"
addons:
apt:
packages:
- ghc-8.0.2
- ghc-8.2.2
- cabal-install-2.0
- zlib1g-dev
sources: hvr-ghc

before_install:
- PATH="/opt/ghc/8.0.2/bin:$PATH"
- PATH="/opt/ghc/8.2.2/bin:$PATH"
- PATH="/opt/cabal/2.0/bin:$PATH"

script:
# boot & configure ghc source tree
- ./boot && ./configure
# Run internal Hadrian tests
- ./build.sh -c selftest
- hadrian/build.sh selftest

# Build GHC
- ./build.sh -j -c $MODE --no-progress --progress-colour=never --profile=-
- os: linux
env: MODE="--flavour=quickest"
compiler: "GHC 8.2.2"
addons:
apt:
packages:
- ghc-8.2.2
- cabal-install-2.0
- zlib1g-dev
sources: hvr-ghc

before_install:
- PATH="/opt/ghc/8.2.2/bin:$PATH"
- PATH="/opt/cabal/2.0/bin:$PATH"

script:
# boot & configure ghc source tree
- ./boot && ./configure

# Build GHC, letting hadrian boot & configure the ghc source tree
- hadrian/build.sh -j $MODE --no-progress --progress-colour=never --profile=-

- os: linux
env: MODE="--flavour=quickest --integer-simple"
compiler: "GHC 8.2.1"
compiler: "GHC 8.4.1"
addons:
apt:
packages:
- ghc-8.2.1
- cabal-install-1.22
- ghc-8.4.1
- cabal-install-2.2
- zlib1g-dev
sources: hvr-ghc

before_install:
- PATH="/opt/ghc/8.2.1/bin:$PATH"
- PATH="/opt/cabal/1.22/bin:$PATH"
- PATH="/opt/ghc/8.4.1/bin:$PATH"
- PATH="/opt/cabal/2.2/bin:$PATH"

script:
# Build GHC
- ./build.sh -j -c $MODE --no-progress --progress-colour=never --profile=-
# boot & configure ghc source tree
- ./boot && ./configure

# build GHC
- hadrian/build.sh -j $MODE --no-progress --progress-colour=never --profile=-

# Test GHC binary
- cd ..
- inplace/bin/ghc-stage2 -e 1+2
- _build/stage1/bin/ghc -e 1+2

- os: osx
osx_image: xcode8
env: MODE="--flavour=quickest --integer-simple inplace/bin/ghc-stage1"
env: MODE="--flavour=quickest --integer-simple"
before_install:
- brew update
- brew install ghc cabal-install python3
- brew install ghc cabal-install
- brew upgrade python

script:
# boot and configure ghc source tree
- ./boot && ./configure

# 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=-
- hadrian/build.sh -j -c $MODE --no-progress --progress-colour=never --profile=-

# Test GHC binary
- _build/stage1/bin/ghc -e 1+2

install:
# Add Cabal to PATH
Expand All @@ -83,8 +113,7 @@ install:
# 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
- cd ghc/hadrian && git reset --hard HEAD && cd ..

cache:
directories:
Expand Down
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ are placed into `_build` and `inplace` directories.
In addition to standard Shake flags (try `--help`), the build system
currently supports several others:

* `--build-root=PATH` or `-oPATH`: specify the directory in which you want to store all
the build artifacts. If none is specified by the user, hadrian will store everything
under `_build/` at the top of ghc's source tree. Unlike GHC's make build system,
hadrian doesn't have any "inplace" logic left anymore. This option is therefore
useful for GHC developers who want to build GHC in different ways or at different
commits, from the same directory, and have the build products sit in different,
isolated folders.

* `--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):
Expand Down Expand Up @@ -119,17 +127,6 @@ are currently not supported.

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`
Expand Down
11 changes: 8 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ install:
- appveyor-retry stack exec -- pacman -S autoconf automake-wrapper make patch python tar --noconfirm

build_script:
# Boot and configure ghc source tree
- cd ..
- python boot && configure --enable-tarballs-autodownload
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why explicit booting and configuration? Doesn't -c flag work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, with my changes -c does not seem to run the boot/configure scripts anymore, or not in time for reading some settings apparently. I could not figure out why the boot/configure rules don't fire.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to figure this out. The dependency mechanism is via the configFile. It is built by configureRules and is needed via lookupValueOrError configFile in Oracles.Setting.

not in time for reading some settings apparently

Which setting is it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, takes a time to go through all the feedback. I went back to the travis CI run where we boot with 8.2, last commit before I removed -c and did the configure phase explicitly, you can see the error right here. So this branch somehow requires data from the cabal files very early on (apparently before we get a chance to fire the configure rules), but those cabal files are supposed to be generated from .cabal.in files during configure.

Copy link
Owner

@snowleopard snowleopard Mar 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think I know what's going on! We haven't included compiler/ghc.cabal into the result of configureRules. We need to modify this line:

https://github.com/snowleopard/hadrian/blob/master/src/Rules/Configure.hs#L15

If you add compiler/ghc.cabal into the list of resulting files I bet it will work. Note that this will also add a dependency on compiler/ghc.cabal.in, so if this file is edited, the configure script will be automatically rerun to produce an up-to-date compiler/ghc.cabal.

Right now, Hadrian doesn't know that compiler/ghc.cabal is built by us!

- cd hadrian

# Build Hadrian and run internal Hadrian tests
- build -c selftest
- build selftest
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you simply undo all changes to this script it should go all the way to the build.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, unfortunately -c seems a bit broken with these changes but I have not figured out why. If you have any idea why, that'd be great!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, happy to help -- let's discuss in the above comment. I'm sure this can be easily fixed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I linked to the error we get when we use hadrian's -c to run boot and configure, in the above thread.


# Build GHC
- build -j -c --flavour=quickest --no-progress --progress-colour=never --profile=-
- build -j --flavour=quickest --no-progress --progress-colour=never --profile=-

# Test GHC binary
- cd ..
- inplace\bin\ghc-stage2 -e 1+2
- _build/stage1/bin/ghc -e 1+2
10 changes: 0 additions & 10 deletions doc/user-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ You can customise Hadrian by copying the file `hadrian/src/UserSettings.hs` to
copy the file your changes will be tracked by `git` and you can accidentally commit
them). Here we document currently supported settings.

## Build directory

Hadrian puts build results into `_build` directory by default, which is
specified by `userBuildRoot`:
```haskell
-- | All build results are put into the 'buildRoot' directory.
userBuildRoot :: BuildRoot
userBuildRoot = BuildRoot "_build"
```

## Build flavour

Build _flavour_ is a collection of build settings that fully define a GHC build
Expand Down
19 changes: 4 additions & 15 deletions hadrian.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ executable hadrian
, Builder
, CommandLine
, Context
, Context.Paths
, Context.Type
, Environment
, Expression
, Expression.Type
, Flavour
, GHC
, GHC.Packages
, Hadrian.Builder
, Hadrian.Builder.Ar
, Hadrian.Builder.Sphinx
, Hadrian.Builder.Tar
, Hadrian.Expression
, Hadrian.Haskell.Cabal
, Hadrian.Haskell.Cabal.PackageData
, Hadrian.Haskell.Cabal.Parse
, Hadrian.Haskell.Cabal.Type
, Hadrian.Oracles.ArgsHash
Expand All @@ -47,7 +50,6 @@ executable hadrian
, Oracles.Flag
, Oracles.Setting
, Oracles.ModuleFiles
, Oracles.PackageData
, Rules
, Rules.Clean
, Rules.Compile
Expand All @@ -57,15 +59,13 @@ executable hadrian
, Rules.Documentation
, Rules.Generate
, Rules.Gmp
, Rules.Install
, Rules.Libffi
, Rules.Library
, Rules.Program
, Rules.Register
, Rules.Selftest
, Rules.SourceDist
, Rules.Test
, Rules.Wrappers
, Settings
, Settings.Builders.Alex
, Settings.Builders.Common
Expand All @@ -91,19 +91,8 @@ executable hadrian
, Settings.Flavours.Quick
, Settings.Flavours.QuickCross
, Settings.Flavours.Quickest
, Settings.Packages.Base
, Settings.Packages.Cabal
, Settings.Packages.Compiler
, Settings.Packages.Ghc
, Settings.Packages.GhcCabal
, Settings.Packages.Ghci
, Settings.Packages.GhcPkg
, Settings.Packages.GhcPrim
, Settings.Packages.Haddock
, Settings.Packages.Haskeline
, Settings.Packages.IntegerGmp
, Settings.Packages
, Settings.Packages.Rts
, Settings.Packages.RunGhc
, Settings.Warnings
, Stage
, Target
Expand Down
91 changes: 41 additions & 50 deletions src/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ module Base (
module Stage,
module Way,

-- * Files
configH, ghcVersionH,
-- * Paths
hadrianPath, configPath, configFile, sourcePath, configH, shakeFilesDir,
generatedDir, inplaceBinPath, inplaceLibBinPath, inplaceLibPath,
inplaceLibCopyTargets, haddockHtmlResourcesStamp, templateHscPath,
stage0PackageDbDir, inplacePackageDbPath, packageDbPath, packageDbStamp,
ghcSplitPath
hadrianPath, configPath, configFile, sourcePath, shakeFilesDir,
generatedDir, generatedPath,
stageBinPath, stageLibPath,
templateHscPath, ghcDeps,
relativePackageDbPath, packageDbPath, packageDbStamp, ghcSplitPath
) where

import Control.Applicative
Expand Down Expand Up @@ -65,71 +67,60 @@ sourcePath = hadrianPath -/- "src"
configH :: FilePath
configH = "mk/config.h"

ghcVersionH :: Action FilePath
ghcVersionH = generatedPath <&> (-/- "ghcversion.h")

-- | The directory in 'buildRoot' containing the Shake database and other
-- auxiliary files generated by Hadrian.
shakeFilesDir :: FilePath
shakeFilesDir = "hadrian"

-- | Directory for binaries that are built "in place".
inplaceBinPath :: FilePath
inplaceBinPath = "inplace/bin"

-- | Directory for libraries that are built "in place".
inplaceLibPath :: FilePath
inplaceLibPath = "inplace/lib"

-- | Directory for binary wrappers, and auxiliary binaries such as @touchy@.
inplaceLibBinPath :: FilePath
inplaceLibBinPath = inplaceLibPath -/- "bin"

-- | The directory in 'buildRoot' containing generated source files that are not
-- package-specific, e.g. @ghcplatform.h@.
generatedDir :: FilePath
generatedDir = "generated"

-- | The directory in 'buildRoot' containing the 'Stage0' package database.
stage0PackageDbDir :: FilePath
stage0PackageDbDir = "stage0/bootstrapping.conf"
generatedPath :: Action FilePath
generatedPath = buildRoot <&> (-/- generatedDir)

-- | Path to the inplace package database used in 'Stage1' and later.
inplacePackageDbPath :: FilePath
inplacePackageDbPath = inplaceLibPath -/- "package.conf.d"
-- | Path to the package database for the given stage of GHC,
-- relative to the build root.
relativePackageDbPath :: Stage -> FilePath
relativePackageDbPath stage = stageString stage -/- "lib" -/- "package.conf.d"

-- | Path to the package database used in a given 'Stage'.
-- | Path to the package database used in a given 'Stage', including
-- the build root.
packageDbPath :: Stage -> Action FilePath
packageDbPath Stage0 = buildRoot <&> (-/- stage0PackageDbDir)
packageDbPath _ = return inplacePackageDbPath
packageDbPath stage = buildRoot <&> (-/- relativePackageDbPath stage)

-- | We use a stamp file to track the existence of a package database.
packageDbStamp :: FilePath
packageDbStamp = ".stamp"

-- ref: GHC_DEPENDENCIES in ghc/ghc.mk
-- ref: INSTALL_LIBS in driver/ghc.mk
-- TODO: Derive this from Builder.runtimeDependencies
-- | Files that need to be copied over to 'inplaceLibPath'.
inplaceLibCopyTargets :: [FilePath]
inplaceLibCopyTargets = map (inplaceLibPath -/-)
[ "ghc-usage.txt"
, "ghci-usage.txt"
, "llvm-targets"
, "platformConstants"
, "settings"
, "template-hsc.h" ]

-- TODO: This is fragile and will break if @README.md@ is removed. We need to
-- improve the story of program runtime dependencies on directories.
-- See: https://github.com/snowleopard/hadrian/issues/492.
-- | Path to a file in Haddock's HTML resource library.
haddockHtmlResourcesStamp :: FilePath
haddockHtmlResourcesStamp = inplaceLibPath -/- "html/README.md"
-- | @bin@ directory for the given 'Stage' (including the build root)
stageBinPath :: Stage -> Action FilePath
stageBinPath stage = buildRoot <&> (-/- stageString stage -/- "bin")

-- | @lib@ directory for the given 'Stage' (including the build root)
stageLibPath :: Stage -> Action FilePath
stageLibPath stage = buildRoot <&> (-/- stageString stage -/- "lib")

-- | Files the `ghc` binary depends on
ghcDeps :: Stage -> Action [FilePath]
ghcDeps stage = mapM (\f -> stageLibPath stage <&> (-/- f))
[ "ghc-usage.txt"
, "ghci-usage.txt"
, "llvm-targets"
, "platformConstants"
, "settings" ]

-- ref: utils/hsc2hs/ghc.mk
-- | Path to 'hsc2hs' template.
templateHscPath :: FilePath
templateHscPath = inplaceLibPath -/- "template-hsc.h"
templateHscPath :: Stage -> Action FilePath
templateHscPath stage = stageLibPath stage <&> (-/- "template-hsc.h")

-- | @ghc-split@ is a Perl script used by GHC when run with @-split-objs@ flag.
-- It is generated in "Rules.Generate".
ghcSplitPath :: FilePath
ghcSplitPath = inplaceLibBinPath -/- "ghc-split"
-- It is generated in "Rules.Generate". This function returns the path relative
-- to the build root under which we will copy @ghc-split@.
ghcSplitPath :: Stage -> FilePath
ghcSplitPath stage = stageString stage -/- "bin" -/- "ghc-split"
Loading