Sven Tennie pushed to branch wip/supersven/refactor-system-cxx-std-lib-hadrian-rules at Glasgow Haskell Compiler / GHC
Commits:
-
a9529a75
by Matthew Pickering at 2026-05-30T09:02:21+02:00
6 changed files:
- + changelog.d/hadrian-system-cxx-std-lib-25303
- hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
- hadrian/src/Hadrian/Haskell/Cabal/Type.hs
- hadrian/src/Main.hs
- hadrian/src/Rules/Generate.hs
- hadrian/src/Rules/Register.hs
Changes:
| 1 | +section: packaging
|
|
| 2 | +synopsis: Fix Hadrian rules for system-cxx-std-lib package dependency
|
|
| 3 | +issues: #25303
|
|
| 4 | +mrs: !16013
|
|
| 5 | +description: {
|
|
| 6 | + Hadrian's handling of the `system-cxx-std-lib` virtual package has been
|
|
| 7 | + fixed and made more uniform.
|
|
| 8 | + |
|
| 9 | + Previously, `text` had an ad-hoc rule outside of `configurePackage` to
|
|
| 10 | + declare a dependency on `system-cxx-std-lib`, the dependency was not
|
|
| 11 | + discovered from cabal files, and the package database was not recached after
|
|
| 12 | + the `.conf` file was generated.
|
|
| 13 | + |
|
| 14 | + The dependency is now read from cabal files via a new
|
|
| 15 | + `dependsOnSystemCxxStdLib` field in `PackageData`, and the `.conf` file
|
|
| 16 | + is needed inside `configurePackage` alongside all other package
|
|
| 17 | + dependencies, consistent with how every other package is handled.
|
|
| 18 | + |
|
| 19 | + `shakeVersion` has been bumped to ensure existing build databases are
|
|
| 20 | + invalidated when upgrading, preventing binary deserialisation errors due to
|
|
| 21 | + the changed `PackageData` type.
|
|
| 22 | +} |
| ... | ... | @@ -81,10 +81,11 @@ parsePackageData pkg = do |
| 81 | 81 | sorted = sort [ C.unPackageName p | C.Dependency p _ _ <- allDeps ]
|
| 82 | 82 | deps = nubOrd sorted \\ [name]
|
| 83 | 83 | depPkgs = mapMaybe findPackageByName deps
|
| 84 | + cxxStdLib = elem "system-cxx-std-lib" deps
|
|
| 84 | 85 | return $ PackageData name version
|
| 85 | 86 | (C.fromShortText (C.synopsis pd))
|
| 86 | 87 | (C.fromShortText (C.description pd))
|
| 87 | - depPkgs gpd
|
|
| 88 | + depPkgs cxxStdLib gpd
|
|
| 88 | 89 | where
|
| 89 | 90 | -- Collect an overapproximation of dependencies by ignoring conditionals
|
| 90 | 91 | collectDeps :: Maybe (C.CondTree v [C.Dependency] a) -> [C.Dependency]
|
| ... | ... | @@ -138,7 +139,9 @@ configurePackage :: Context -> Action () |
| 138 | 139 | configurePackage context@Context {..} = do
|
| 139 | 140 | putProgressInfo $ "| Configure package " ++ quote (pkgName package)
|
| 140 | 141 | gpd <- pkgGenericDescription package
|
| 141 | - depPkgs <- packageDependencies <$> readPackageData package
|
|
| 142 | + pd <- readPackageData package
|
|
| 143 | + let depPkgs = packageDependencies pd
|
|
| 144 | + needSystemCxxStdLib = dependsOnSystemCxxStdLib pd
|
|
| 142 | 145 | |
| 143 | 146 | -- Stage packages are those we have in this stage.
|
| 144 | 147 | stagePkgs <- stagePackages stage
|
| ... | ... | @@ -157,7 +160,12 @@ configurePackage context@Context {..} = do |
| 157 | 160 | -- We'll need those packages in our package database.
|
| 158 | 161 | deps <- sequence [ pkgConfFile (context { package = pkg, iplace = forceBaseAfterGhcInternal pkg })
|
| 159 | 162 | | pkg <- depPkgs, pkg `elem` stagePkgs ]
|
| 160 | - need $ extraPreConfigureDeps ++ deps
|
|
| 163 | + -- system-cxx-std-lib is magic.. it doesn't have a cabal file or source code, so we have
|
|
| 164 | + -- to treat it specially as `pkgConfFile` uses `readPackageData` to compute the version.
|
|
| 165 | + systemCxxStdLib <- sequence [ systemCxxStdLibConfPath (PackageDbLoc stage iplace) | needSystemCxxStdLib ]
|
|
| 166 | + need $ extraPreConfigureDeps
|
|
| 167 | + ++ deps
|
|
| 168 | + ++ systemCxxStdLib
|
|
| 161 | 169 | |
| 162 | 170 | -- Figure out what hooks we need.
|
| 163 | 171 | let configureFile = replaceFileName (pkgCabalFile package) "configure"
|
| ... | ... | @@ -30,6 +30,7 @@ data PackageData = PackageData |
| 30 | 30 | , synopsis :: String
|
| 31 | 31 | , description :: String
|
| 32 | 32 | , packageDependencies :: [Package]
|
| 33 | + , dependsOnSystemCxxStdLib :: Bool
|
|
| 33 | 34 | , genericPackageDescription :: GenericPackageDescription
|
| 34 | 35 | } deriving (Eq, Generic, Show)
|
| 35 | 36 |
| ... | ... | @@ -63,7 +63,13 @@ main = do |
| 63 | 63 | shakeColor <- shouldUseColor
|
| 64 | 64 | let options :: ShakeOptions
|
| 65 | 65 | options = shakeOptions
|
| 66 | - { shakeChange = ChangeModtimeAndDigest
|
|
| 66 | + { -- Bump shakeVersion whenever a type stored in the Shake oracle
|
|
| 67 | + -- changes its Binary representation (e.g. fields added/removed
|
|
| 68 | + -- from PackageData or other oracle value types). This forces
|
|
| 69 | + -- Shake to wipe the stale database instead of crashing on
|
|
| 70 | + -- deserialisation.
|
|
| 71 | + shakeVersion = "2"
|
|
| 72 | + , shakeChange = ChangeModtimeAndDigest
|
|
| 67 | 73 | , shakeFiles = buildRoot -/- Base.shakeFilesDir
|
| 68 | 74 | , shakeProgress = Progress.hadrianProgress cwd
|
| 69 | 75 | , shakeRebuild = rebuild
|
| ... | ... | @@ -242,9 +242,6 @@ copyRules = do |
| 242 | 242 | prefix -/- "html/**" <~ return "utils/haddock/haddock-api/resources"
|
| 243 | 243 | prefix -/- "latex/**" <~ return "utils/haddock/haddock-api/resources"
|
| 244 | 244 | |
| 245 | - forM_ [Inplace, Final] $ \iplace ->
|
|
| 246 | - root -/- relativePackageDbPath (PackageDbLoc stage iplace) -/- systemCxxStdLibConf %> \file -> do
|
|
| 247 | - copyFile ("mk" -/- "system-cxx-std-lib-1.0.conf") file
|
|
| 248 | 245 | |
| 249 | 246 | generateRules :: Rules ()
|
| 250 | 247 | generateRules = do
|
| ... | ... | @@ -6,7 +6,6 @@ module Rules.Register ( |
| 6 | 6 | |
| 7 | 7 | import Base
|
| 8 | 8 | import Context
|
| 9 | -import Flavour
|
|
| 10 | 9 | import Oracles.Setting
|
| 11 | 10 | import Hadrian.BuildPath
|
| 12 | 11 | import Hadrian.Expression
|
| ... | ... | @@ -48,14 +47,6 @@ configurePackageRules = do |
| 48 | 47 | isGmp <- (== "gmp") <$> interpretInContext ctx getBignumBackend
|
| 49 | 48 | when isGmp $
|
| 50 | 49 | need [buildP -/- "include/ghc-gmp.h"]
|
| 51 | - when (pkg == text) $ do
|
|
| 52 | - simdutf <- textWithSIMDUTF <$> flavour
|
|
| 53 | - when simdutf $ do
|
|
| 54 | - -- This is required, otherwise you get Error: hadrian:
|
|
| 55 | - -- Encountered missing or private dependencies:
|
|
| 56 | - -- system-cxx-std-lib ==1.0
|
|
| 57 | - cxxStdLib <- systemCxxStdLibConfPath $ PackageDbLoc stage Inplace
|
|
| 58 | - need [cxxStdLib]
|
|
| 59 | 50 | Cabal.configurePackage ctx
|
| 60 | 51 | |
| 61 | 52 | root -/- "**/autogen/cabal_macros.h" %> \out -> do
|
| ... | ... | @@ -105,6 +96,12 @@ registerPackageRules rs stage iplace = do |
| 105 | 96 | target (Context stage compiler vanilla iplace) (GhcPkg Recache stage) [] []
|
| 106 | 97 | writeFileLines stamp []
|
| 107 | 98 | |
| 99 | + -- Special rule for registering system-cxx-std-lib
|
|
| 100 | + root -/- relativePackageDbPath (PackageDbLoc stage iplace) -/- systemCxxStdLibConf %> \file -> do
|
|
| 101 | + copyFile ("mk" -/- "system-cxx-std-lib-1.0.conf") file
|
|
| 102 | + buildWithResources rs $
|
|
| 103 | + target (Context stage compiler vanilla iplace) (GhcPkg Recache stage) [] []
|
|
| 104 | + |
|
| 108 | 105 | -- Register a package.
|
| 109 | 106 | root -/- relativePackageDbPath (PackageDbLoc stage iplace) -/- "*.conf" %> \conf -> do
|
| 110 | 107 | historyDisable
|