[commit: ghc] master: Hadrian: simple targets for building libraries and executables (7491ced)

git at git.haskell.org git at git.haskell.org
Tue Dec 11 23:21:27 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/7491cedb20d15a54e905205c51aea72a13ac73aa/ghc

>---------------------------------------------------------------

commit 7491cedb20d15a54e905205c51aea72a13ac73aa
Author: Alp Mestanogullari <alpmestan at gmail.com>
Date:   Tue Dec 11 13:10:03 2018 -0500

    Hadrian: simple targets for building libraries and executables
    
    This patch introduces (phony) build targets of the form
    
        (1) stage<N>:<lib>:<name>   (e.g: stage1:lib:Cabal)
        (2) stage<N>:<exe>:<name>   (e.g: stage2:exe:ghc-bin)
    
    where (1) builds the given library with the stage N compiler and (2)
    builds the given executable with the stage N-1 compiler. This patch may
    be generating too many such targets but it's a first stab that we can
    refine.
    
    This fixes #15949.
    
    Test Plan: hadrian/build.sh stage1:exe:ghc-bin
    
    Reviewers: bgamari, snowleopard
    
    Reviewed By: bgamari
    
    Subscribers: rwbarton, carter
    
    GHC Trac Issues: #15949
    
    Differential Revision: https://phabricator.haskell.org/D5434


>---------------------------------------------------------------

7491cedb20d15a54e905205c51aea72a13ac73aa
 hadrian/README.md                  | 30 +++++++++++++++++++++++
 hadrian/hadrian.cabal              |  1 +
 hadrian/src/Rules.hs               |  2 ++
 hadrian/src/Rules/SimpleTargets.hs | 49 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 82 insertions(+)

diff --git a/hadrian/README.md b/hadrian/README.md
index b88d08d..7bd5fa8 100644
--- a/hadrian/README.md
+++ b/hadrian/README.md
@@ -110,6 +110,36 @@ by Shake oracles.
 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).
 
+#### Building libraries and executables
+
+You can build a specific library or executable for a given stage by doing
+`build stage<N>:<lib|exe>:<package name>`. Examples:
+
+``` sh
+# build the stage 1 GHC compiler (the executable), the binary will be placed
+# under _build/stage0/bin/ghc (because it is built by the stage0 compiler).
+build stage1:exe:ghc-bin
+
+# build the stage 2 GHC compiler, the binary will be placed under
+# _build/stage1/bin/ghc (because it is built by the stage1 compiler).
+build stage2:exe:ghc-bin
+
+# build the ghc library with the boot compiler, and register it
+# in the package database under _build/stage0/lib.
+build stage0:lib:ghc
+
+# build the Cabal library with the stage 1 compiler and register it
+# in the package database under _build/stage1/lib.
+
+# build the text library with the stage 2 compiler and register it
+# in the package database under _build/stage2/lib.
+build stage2:lib:text
+
+# build the stage 2 haddock executable and place the program under
+# _build/stage1/haddock.
+build stage2:exe:haddock
+```
+
 #### Clean and full rebuild
 
 * `build clean` removes all build artefacts.
diff --git a/hadrian/hadrian.cabal b/hadrian/hadrian.cabal
index c70c215..669d16c 100644
--- a/hadrian/hadrian.cabal
+++ b/hadrian/hadrian.cabal
@@ -67,6 +67,7 @@ executable hadrian
                        , Rules.Program
                        , Rules.Register
                        , Rules.Selftest
+                       , Rules.SimpleTargets
                        , Rules.SourceDist
                        , Rules.Test
                        , Settings
diff --git a/hadrian/src/Rules.hs b/hadrian/src/Rules.hs
index 69a151c..e51dae4 100644
--- a/hadrian/src/Rules.hs
+++ b/hadrian/src/Rules.hs
@@ -20,6 +20,7 @@ import qualified Rules.Libffi
 import qualified Rules.Library
 import qualified Rules.Program
 import qualified Rules.Register
+import qualified Rules.SimpleTargets
 import Settings
 import Target
 import UserSettings
@@ -109,6 +110,7 @@ packageRules = do
     let vanillaContexts = liftM2 vanillaContext allStages knownPackages
 
     forM_ vanillaContexts Rules.Generate.generatePackageCode
+    Rules.SimpleTargets.simplePackageTargets
 
 buildRules :: Rules ()
 buildRules = do
diff --git a/hadrian/src/Rules/SimpleTargets.hs b/hadrian/src/Rules/SimpleTargets.hs
new file mode 100644
index 0000000..d005043
--- /dev/null
+++ b/hadrian/src/Rules/SimpleTargets.hs
@@ -0,0 +1,49 @@
+module Rules.SimpleTargets (simplePackageTargets) where
+
+import Base
+import Context
+import Packages
+import Settings
+
+import Data.Foldable
+
+-- | Simple aliases for library and executable targets.
+--
+--  - @stage<N>:lib:<name>@ will build library @name@ with
+--    the stage N compiler, putting the result under
+--    @<build root>/stage<N>/lib at .
+--  - @stage<N>:exe:<name>@ will build executable @name@
+--    with the stage N-1 compiler, putting the result under
+--    @<build root>/stage<N-1>/bin.
+simplePackageTargets :: Rules ()
+simplePackageTargets = traverse_ simpleTarget targets
+
+  where targets = [ (stage, target)
+                  | stage <- [minBound..maxBound]
+                  , target <- knownPackages
+                  ]
+
+simpleTarget :: (Stage, Package) -> Rules ()
+simpleTarget (stage, target) = do
+  let tgt = intercalate ":" [stagestr, typ, pkgname]
+  tgt ~> do
+    p <- getTargetPath stage target
+    need [ p ]
+
+  where typ = if isLibrary target then "lib" else "exe"
+        stagestr = stageString stage
+        pkgname = pkgName target
+
+getTargetPath :: Stage -> Package -> Action FilePath
+getTargetPath stage pkg
+  | isLibrary pkg = getLibraryPath stage pkg
+  | otherwise     = getProgramPath stage pkg
+
+getLibraryPath :: Stage -> Package -> Action FilePath
+getLibraryPath stage pkg = pkgConfFile (vanillaContext stage pkg)
+
+getProgramPath :: Stage -> Package -> Action FilePath
+getProgramPath Stage0 _ =
+  error ("Cannot build a stage 0 executable target: " ++
+         "it is the boot compiler's toolchain")
+getProgramPath stage pkg = programPath (vanillaContext (pred stage) pkg)



More information about the ghc-commits mailing list