Commit d7029cc0 authored by Sylvain Henry's avatar Sylvain Henry Committed by Marge Bot

Hadrian: refactor GMP in-tree build support (#17756)

* Hadrian doesn't use integer-gmp/config.mk file anymore to determine if
  building GMP in-tree is required.

  "config.mk" is created by Cabal when the integer-gmp package is
  configured and this file is still untracked by Hadrian. This led to a
  tricky configure "race" because "config.mk" is built by the
  "setup-config" rule, but this rule is also used to find dependencies,
  in particular the "ghc-gmp.h" header, but the creation of this file
  was depending (without being tracked) on "config.mk".

  Now Hadrian only builds in-tree GMP if `--with-intree-gmp` is passed
  to the top-level configure script.

* in-tree GMP isn't built once for all in a fixed stage (Stage1)
  anymore. It is built per stage which is required if we build a
  cross-compiler

* switching between in-tree and external GMP is now supported without
  having to clean the build directory first.

* "wrappers.c" now includes "ghc-gmp.h" instead of "ghc.h". It
  helps ensuring that the build system generates "ghc-gmp.h".

* build in-tree GMP in "<root>/stageN/gmp/gmpbuild" and produce useful
  artefacts (libgmp.a, gmp.h, objs/*.o) in "<root>/stageN/gmp"
parent b4a8ce52
Pipeline #15953 failed with stages
in 492 minutes and 10 seconds
......@@ -15,7 +15,6 @@ import Oracles.Flag
import Oracles.ModuleFiles
import Oracles.Setting
import Packages
import Rules.Gmp
import Rules.Libffi
import Settings
import Settings.Builders.DeriveConstants (deriveConstantsPairs)
......@@ -53,11 +52,11 @@ compilerDependencies = do
stage <- getStage
isGmp <- (== integerGmp) <$> getIntegerPackage
ghcPath <- expr $ buildPath (vanillaContext stage compiler)
gmpPath <- expr gmpBuildPath
gmpPath <- expr $ buildPath (vanillaContext stage integerGmp)
rtsPath <- expr (rtsBuildPath stage)
libDir <- expr $ stageLibPath stage
mconcat [ return $ (libDir -/-) <$> derivedConstantsFiles
, notStage0 ? isGmp ? return [gmpPath -/- gmpLibraryH]
, notStage0 ? isGmp ? return [gmpPath -/- "include/ghc-gmp.h"]
, notStage0 ? return ((rtsPath -/-) <$> libffiHeaderFiles)
, return $ fmap (ghcPath -/-)
[ "primop-can-fail.hs-incl"
......
This diff is collapsed.
......@@ -7,7 +7,7 @@ import qualified Text.Parsec as Parsec
import Base
import Context
import Expression hiding (way, package)
import Expression hiding (way, package, stage)
import Oracles.ModuleFiles
import Packages
import Rules.Gmp
......@@ -134,7 +134,7 @@ cObjects context = do
-- 'Context' is @integer-gmp@.
extraObjects :: Context -> Action [FilePath]
extraObjects context
| package context == integerGmp = gmpObjects
| package context == integerGmp = gmpObjects (stage context)
| otherwise = return []
-- | Return all the object files to be put into the library we're building for
......
......@@ -11,7 +11,6 @@ import Hadrian.Expression
import Hadrian.Haskell.Cabal
import Oracles.Setting
import Packages
import Rules.Gmp
import Rules.Rts
import {-# SOURCE #-} Rules.Library (needLibrary)
import Settings
......@@ -40,6 +39,9 @@ configurePackageRules = do
(stage, path) <- parsePath (parseSetupConfig root) "<setup config path parser>" out
let pkg = unsafeFindPackageByPath path
let ctx = Context stage pkg vanilla
buildP <- buildPath ctx
when (pkg == integerGmp) $
need [buildP -/- "include/ghc-gmp.h"]
needLibrary =<< contextDependencies ctx
Cabal.configurePackage ctx
......@@ -127,7 +129,9 @@ buildConf _ context@Context {..} conf = do
, path -/- "ghcplatform.h"
, path -/- "ghcversion.h" ]
when (package == integerGmp) $ need [path -/- gmpLibraryH]
-- we need to generate this file for GMP
when (package == integerGmp) $
need [path -/- "include/ghc-gmp.h"]
-- Copy and register the package.
Cabal.copyPackage context
......
......@@ -6,8 +6,8 @@ import Settings.Builders.Common
configureBuilderArgs :: Args
configureBuilderArgs = do
gmpPath <- expr gmpBuildPath
stage <- getStage
gmpPath <- expr (gmpBuildPath stage)
libffiPath <- expr (libffiBuildPath stage)
mconcat [ builder (Configure gmpPath) ? do
targetPlatform <- getSetting TargetPlatform
......
......@@ -10,7 +10,8 @@ import CommandLine
makeBuilderArgs :: Args
makeBuilderArgs = do
threads <- shakeThreads <$> expr getShakeOptions
gmpPath <- expr gmpBuildPath
stage <- getStage
gmpPath <- expr (gmpBuildPath stage)
libffiPaths <- forM [Stage1 ..] $ \s -> expr (libffiBuildPath s)
let t = show $ max 4 (threads - 2) -- Don't use all Shake's threads
mconcat $
......
......@@ -5,7 +5,6 @@ import Flavour
import Oracles.Setting
import Oracles.Flag
import Packages
import Rules.Gmp
import Settings
-- | Package-specific command-line arguments.
......@@ -16,9 +15,7 @@ packageArgs = do
path <- getBuildPath
intLib <- getIntegerPackage
compilerPath <- expr $ buildPath (vanillaContext stage compiler)
gmpBuildPath <- expr gmpBuildPath
let includeGmp = "-I" ++ gmpBuildPath -/- "include"
-- Do not bind the result to a Boolean: this forces the configure rule
let -- Do not bind the result to a Boolean: this forces the configure rule
-- immediately and may lead to cyclic dependencies.
-- See: https://gitlab.haskell.org/ghc/ghc/issues/16809.
cross = flag CrossCompiling
......@@ -150,17 +147,15 @@ packageArgs = do
------------------------------ integerGmp ------------------------------
, package integerGmp ? mconcat
[ builder Cc ? arg includeGmp
, builder (Cabal Setup) ? mconcat
[ builder (Cabal Setup) ? mconcat
[ flag GmpInTree ? arg "--configure-option=--with-intree-gmp"
-- Windows is always built with inplace GMP until we have dynamic
-- linking working.
, windowsHost ? arg "--configure-option=--with-intree-gmp"
, flag GmpFrameworkPref ?
arg "--configure-option=--with-gmp-framework-preferred"
, arg ("--configure-option=CFLAGS=" ++ includeGmp)
, arg ("--gcc-options=" ++ includeGmp) ] ]
]
]
---------------------------------- rts ---------------------------------
, package rts ? rtsPackageArgs -- RTS deserves a separate function
......
......@@ -12,6 +12,7 @@
#include "HsFFI.h"
#include "MachDeps.h"
#include "HsIntegerGmp.h"
#include "ghc-gmp.h"
#include <assert.h>
#include <stdbool.h>
......@@ -22,7 +23,6 @@
#include <float.h>
#include <stdio.h>
#include <gmp.h>
// GMP 4.x compatibility
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment