From 8a06ddf68bb5a9985e3a7b8464dd04b928c36b90 Mon Sep 17 00:00:00 2001
From: Matthew Pickering <matthewtpickering@gmail.com>
Date: Wed, 17 Apr 2024 12:44:45 +0100
Subject: [PATCH] Linearise ghc-internal and base build

This is achieved by requesting the final package database for
ghc-internal, which mandates it is fully built as a dependency of
configuring the `base` package. This is at the expense of cross-package
parrallelism between ghc-internal and the base package.

Fixes #24436
---
 hadrian/src/Hadrian/Haskell/Cabal/Parse.hs | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs b/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
index 178bf8651874..a139eebb8d76 100644
--- a/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
+++ b/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
@@ -71,6 +71,7 @@ import System.Directory (getCurrentDirectory)
 import qualified Distribution.InstalledPackageInfo as CP
 import Distribution.Simple.Utils (writeUTF8File)
 import Utilities
+import Packages
 
 
 -- | Parse the Cabal file of a given 'Package'. This operation is cached by the
@@ -150,8 +151,20 @@ configurePackage context@Context {..} = do
 
     -- Stage packages are those we have in this stage.
     stagePkgs <- stagePackages stage
+
+
+    -- Normally we will depend on Inplace package databases which enables
+    -- cross-package parallelism, but see #24436 for why we lineariese the build
+    -- of base and ghc-internal.
+    let forceBaseAfterGhcInternal dep =
+           if dep == ghcInternal && package == base
+              then Final
+              else iplace
+
+
+
     -- We'll need those packages in our package database.
-    deps <- sequence [ pkgConfFile (context { package = pkg })
+    deps <- sequence [ pkgConfFile (context { package = pkg, iplace = forceBaseAfterGhcInternal pkg })
                      | pkg <- depPkgs, pkg `elem` stagePkgs ]
     need $ extraPreConfigureDeps ++ deps
 
-- 
GitLab