Skip to content

Commit 26389be

Browse files
committed
Patches for 9.12 for reinstallable libraries to build
the alex patch comes from a ghc MR so should not be needed in future https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13782 the Cabal one is inspired by the patch already applied for 9.10 to build with Cabal-3.11
1 parent ce5a92e commit 26389be

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

overlays/bootstrap.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ in {
310310
++ fromUntil "9.8.3" "9.8.4" ./patches/ghc/ghc-9.8.3-text-upper-bound.patch
311311
++ fromUntil "9.10" "9.10.2" ./patches/ghc/ghc-9.10-containers-upper-bound.patch
312312
++ fromUntil "9.10" "9.14" ./patches/ghc/ghc-9.10-merge-objects.patch
313+
++ fromUntil "9.12" "9.14" ./patches/ghc/ghc-9.12-Cabal-3.14.patch
314+
++ fromUntil "9.12" "9.14" ./patches/ghc/ghc-9.12-alex-3.5.2.0.patch
313315

314316
# This patch will make windows stop emitting absolute relocations. This is one way in which binutils 2.36+ (with ASLR enabled), will just choke on the
315317
# assembly we generate because it's always absolute (32bit) addressing modes.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
diff --git a/compiler/Setup.hs b/compiler/Setup.hs
2+
index c7c0850383..3ce6624307 100644
3+
--- a/compiler/Setup.hs
4+
+++ b/compiler/Setup.hs
5+
@@ -1,3 +1,4 @@
6+
+{-# LANGUAGE CPP #-}
7+
{-# LANGUAGE RecordWildCards #-}
8+
module Main where
9+
10+
@@ -11,6 +12,10 @@ import Distribution.Verbosity
11+
import Distribution.Simple.Program
12+
import Distribution.Simple.Utils
13+
import Distribution.Simple.Setup
14+
+import Distribution.Simple.PackageIndex
15+
+#if MIN_VERSION_Cabal(3,14,0)
16+
+import Distribution.Utils.Path (interpretSymbolicPath)
17+
+#endif
18+
19+
import System.IO
20+
import System.Process
21+
@@ -57,7 +62,11 @@ primopIncls =
22+
ghcAutogen :: Verbosity -> LocalBuildInfo -> IO ()
23+
ghcAutogen verbosity lbi@LocalBuildInfo{..} = do
24+
-- Get compiler/ root directory from the cabal file
25+
+#if MIN_VERSION_Cabal(3,14,0)
26+
+ let Just compilerRoot = takeDirectory . interpretSymbolicPath Nothing <$> pkgDescrFile
27+
+#else
28+
let Just compilerRoot = takeDirectory <$> pkgDescrFile
29+
+#endif
30+
31+
-- Require the necessary programs
32+
(gcc ,withPrograms) <- requireProgram normal gccProgram withPrograms
33+
@@ -77,10 +86,20 @@ ghcAutogen verbosity lbi@LocalBuildInfo{..} = do
34+
-- Call genprimopcode to generate *.hs-incl
35+
forM_ primopIncls $ \(file,command) -> do
36+
contents <- readProcess "genprimopcode" [command] primopsStr
37+
+#if MIN_VERSION_Cabal(3,14,0)
38+
+ rewriteFileEx verbosity (interpretSymbolicPath Nothing (buildDir lbi) </> file) contents
39+
+#elif MIN_VERSION_Cabal(3,11,0)
40+
+ rewriteFileEx verbosity (buildDir lbi </> file) contents
41+
+#else
42+
rewriteFileEx verbosity (buildDir </> file) contents
43+
+#endif
44+
45+
-- Write GHC.Platform.Constants
46+
+#if MIN_VERSION_Cabal(3,14,0)
47+
+ let platformConstantsPath = interpretSymbolicPath Nothing (autogenPackageModulesDir lbi) </> "GHC/Platform/Constants.hs"
48+
+#else
49+
let platformConstantsPath = autogenPackageModulesDir lbi </> "GHC/Platform/Constants.hs"
50+
+#endif
51+
targetOS = case lookup "target os" settings of
52+
Nothing -> error "no target os in settings"
53+
Just os -> os
54+
@@ -95,7 +114,11 @@ ghcAutogen verbosity lbi@LocalBuildInfo{..} = do
55+
_ -> error "Couldn't find unique cabal library when building ghc"
56+
57+
-- Write GHC.Settings.Config
58+
+#if MIN_VERSION_Cabal(3,14,0)
59+
+ configHsPath = interpretSymbolicPath Nothing (autogenPackageModulesDir lbi) </> "GHC/Settings/Config.hs"
60+
+#else
61+
configHsPath = autogenPackageModulesDir lbi </> "GHC/Settings/Config.hs"
62+
+#endif
63+
configHs = generateConfigHs cProjectUnitId settings
64+
createDirectoryIfMissingVerbose verbosity True (takeDirectory configHsPath)
65+
rewriteFileEx verbosity configHsPath configHs
66+
diff --git a/libraries/ghc-boot/Setup.hs b/libraries/ghc-boot/Setup.hs
67+
index 0995ee3f8f..73e6b3e5e7 100644
68+
--- a/libraries/ghc-boot/Setup.hs
69+
+++ b/libraries/ghc-boot/Setup.hs
70+
@@ -1,3 +1,4 @@
71+
+{-# LANGUAGE CPP #-}
72+
{-# LANGUAGE RecordWildCards #-}
73+
{-# LANGUAGE LambdaCase #-}
74+
{-# LANGUAGE LambdaCase #-}
75+
@@ -10,6 +11,9 @@ import Distribution.Verbosity
76+
import Distribution.Simple.Program
77+
import Distribution.Simple.Utils
78+
import Distribution.Simple.Setup
79+
+#if MIN_VERSION_Cabal(3,14,0)
80+
+import Distribution.Utils.Path (interpretSymbolicPath)
81+
+#endif
82+
83+
import System.IO
84+
import System.Directory
85+
@@ -32,12 +36,24 @@ main = defaultMainWithHooks ghcHooks
86+
ghcAutogen :: Verbosity -> LocalBuildInfo -> IO ()
87+
ghcAutogen verbosity lbi@LocalBuildInfo{..} = do
88+
-- Get compiler/ root directory from the cabal file
89+
+#if MIN_VERSION_Cabal(3,14,0)
90+
+ let Just compilerRoot = takeDirectory . interpretSymbolicPath Nothing <$> pkgDescrFile
91+
+#else
92+
let Just compilerRoot = takeDirectory <$> pkgDescrFile
93+
+#endif
94+
95+
let platformHostFile = "GHC/Platform/Host.hs"
96+
+#if MIN_VERSION_Cabal(3,14,0)
97+
+ platformHostPath = interpretSymbolicPath Nothing (autogenPackageModulesDir lbi) </> platformHostFile
98+
+#else
99+
platformHostPath = autogenPackageModulesDir lbi </> platformHostFile
100+
+#endif
101+
ghcVersionFile = "GHC/Version.hs"
102+
+#if MIN_VERSION_Cabal(3,14,0)
103+
+ ghcVersionPath = interpretSymbolicPath Nothing (autogenPackageModulesDir lbi) </> ghcVersionFile
104+
+#else
105+
ghcVersionPath = autogenPackageModulesDir lbi </> ghcVersionFile
106+
+#endif
107+
108+
-- Get compiler settings
109+
settings <- lookupEnv "HADRIAN_SETTINGS" >>= \case
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
diff --git a/compiler/GHC/Parser/Lexer.x b/compiler/GHC/Parser/Lexer.x
2+
index fe08dc69cd..57157cd8bb 100644
3+
--- a/compiler/GHC/Parser/Lexer.x
4+
+++ b/compiler/GHC/Parser/Lexer.x
5+
@@ -41,6 +41,7 @@
6+
-- Alex "Haskell code fragment top"
7+
8+
{
9+
+{-# LANGUAGE CPP #-}
10+
{-# LANGUAGE ViewPatterns #-}
11+
{-# LANGUAGE LambdaCase #-}
12+
{-# LANGUAGE MultiWayIf #-}
13+
@@ -3471,10 +3472,14 @@ topNoLayoutContainsCommas [] = False
14+
topNoLayoutContainsCommas (ALRLayout _ _ : ls) = topNoLayoutContainsCommas ls
15+
topNoLayoutContainsCommas (ALRNoLayout b _ : _) = b
16+
17+
+#ifdef MIN_TOOL_VERSION_alex
18+
+#if !MIN_TOOL_VERSION_alex(3,5,2)
19+
-- If the generated alexScan/alexScanUser functions are called multiple times
20+
-- in this file, alexScanUser gets broken out into a separate function and
21+
-- increases memory usage. Make sure GHC inlines this function and optimizes it.
22+
{-# INLINE alexScanUser #-}
23+
+#endif
24+
+#endif
25+
26+
lexToken :: P (PsLocated Token)
27+
lexToken = do

0 commit comments

Comments
 (0)