Teo Camarasu pushed to branch wip/T25282 at Glasgow Haskell Compiler / GHC
Commits:
-
6d791567
by Teo Camarasu at 2025-06-20T17:43:18+01:00
-
ae14bd72
by Teo Camarasu at 2025-06-20T17:43:35+01:00
4 changed files:
- compiler/GHC/Driver/Session.hs
- compiler/Setup.hs
- hadrian/src/Rules/Generate.hs
- linters/lint-whitespace/lint-whitespace.cabal
Changes:
| ... | ... | @@ -3460,6 +3460,7 @@ compilerInfo dflags |
| 3460 | 3460 | ("Project Patch Level1", cProjectPatchLevel1),
|
| 3461 | 3461 | ("Project Patch Level2", cProjectPatchLevel2),
|
| 3462 | 3462 | ("Project Unit Id", cProjectUnitId),
|
| 3463 | + ("ghc-internal Unit Id", cGhcInternalUnitId), -- See Note [Special unit-ids]
|
|
| 3463 | 3464 | ("Booter version", cBooterVersion),
|
| 3464 | 3465 | ("Stage", cStage),
|
| 3465 | 3466 | ("Build platform", cBuildPlatformString),
|
| ... | ... | @@ -3513,6 +3514,23 @@ compilerInfo dflags |
| 3513 | 3514 | expandDirectories :: FilePath -> Maybe FilePath -> String -> String
|
| 3514 | 3515 | expandDirectories topd mtoold = expandToolDir useInplaceMinGW mtoold . expandTopDir topd
|
| 3515 | 3516 | |
| 3517 | +-- Note [Special unit-ids]
|
|
| 3518 | +-- ~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 3519 | +-- Certain units are special to the compiler:
|
|
| 3520 | +-- - Wired-in identifiers reference a specific unit-id of `ghc-internal`.
|
|
| 3521 | +-- - GHC plugins must be linked against a specific unit-id of `ghc`,
|
|
| 3522 | +-- namely the same one as the compiler.
|
|
| 3523 | +-- - When using Template Haskell, splices refer to the Template Haskell
|
|
| 3524 | +-- interface defined in `ghc-internal`, and must be linked against the same
|
|
| 3525 | +-- unit-id as the compiler.
|
|
| 3526 | +--
|
|
| 3527 | +-- We therefore expose the unit-id of `ghc-internal` ("ghc-internal Unit Id") and
|
|
| 3528 | +-- ghc ("Project Unit Id") through `ghc --info`.
|
|
| 3529 | +--
|
|
| 3530 | +-- This allows build tools to act accordingly, eg, if a user wishes to build a
|
|
| 3531 | +-- GHC plugin, `cabal-install` might force them to use the exact `ghc` unit
|
|
| 3532 | +-- that the compiler was linked against.
|
|
| 3533 | + |
|
| 3516 | 3534 | {- -----------------------------------------------------------------------------
|
| 3517 | 3535 | Note [DynFlags consistency]
|
| 3518 | 3536 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -11,6 +11,7 @@ import Distribution.Verbosity |
| 11 | 11 | import Distribution.Simple.Program
|
| 12 | 12 | import Distribution.Simple.Utils
|
| 13 | 13 | import Distribution.Simple.Setup
|
| 14 | +import Distribution.Simple.PackageIndex
|
|
| 14 | 15 | |
| 15 | 16 | import System.IO
|
| 16 | 17 | import System.Process
|
| ... | ... | @@ -22,6 +23,7 @@ import qualified Data.Map as Map |
| 22 | 23 | import GHC.ResponseFile
|
| 23 | 24 | import System.Environment
|
| 24 | 25 | |
| 26 | + |
|
| 25 | 27 | main :: IO ()
|
| 26 | 28 | main = defaultMainWithHooks ghcHooks
|
| 27 | 29 | where
|
| ... | ... | @@ -56,7 +58,7 @@ primopIncls = |
| 56 | 58 | ]
|
| 57 | 59 | |
| 58 | 60 | ghcAutogen :: Verbosity -> LocalBuildInfo -> IO ()
|
| 59 | -ghcAutogen verbosity lbi@LocalBuildInfo{pkgDescrFile,withPrograms,componentNameMap}
|
|
| 61 | +ghcAutogen verbosity lbi@LocalBuildInfo{pkgDescrFile,withPrograms,componentNameMap,installedPkgs}
|
|
| 60 | 62 | = do
|
| 61 | 63 | -- Get compiler/ root directory from the cabal file
|
| 62 | 64 | let Just compilerRoot = takeDirectory <$> pkgDescrFile
|
| ... | ... | @@ -96,9 +98,14 @@ ghcAutogen verbosity lbi@LocalBuildInfo{pkgDescrFile,withPrograms,componentNameM |
| 96 | 98 | Just [LibComponentLocalBuildInfo{componentUnitId}] -> unUnitId componentUnitId
|
| 97 | 99 | _ -> error "Couldn't find unique cabal library when building ghc"
|
| 98 | 100 | |
| 101 | + let cGhcInternalUnitId = case lookupPackageName installedPkgs (mkPackageName "ghc-internal") of
|
|
| 102 | + -- We assume there is exactly one copy of `ghc-internal` in our dependency closure
|
|
| 103 | + [(_,[packageInfo])] -> unUnitId $ installedUnitId packageInfo
|
|
| 104 | + _ -> error "Couldn't find unique ghc-internal library when building ghc"
|
|
| 105 | + |
|
| 99 | 106 | -- Write GHC.Settings.Config
|
| 100 | 107 | configHsPath = autogenPackageModulesDir lbi </> "GHC/Settings/Config.hs"
|
| 101 | - configHs = generateConfigHs cProjectUnitId settings
|
|
| 108 | + configHs = generateConfigHs cProjectUnitId cGhcInternalUnitId settings
|
|
| 102 | 109 | createDirectoryIfMissingVerbose verbosity True (takeDirectory configHsPath)
|
| 103 | 110 | rewriteFileEx verbosity configHsPath configHs
|
| 104 | 111 | |
| ... | ... | @@ -110,8 +117,9 @@ getSetting settings kh kr = go settings kr |
| 110 | 117 | Just v -> Right v
|
| 111 | 118 | |
| 112 | 119 | generateConfigHs :: String -- ^ ghc's cabal-generated unit-id, which matches its package-id/key
|
| 120 | + -> String -- ^ ghc-internal's cabal-generated unit-id, which matches its package-id/key
|
|
| 113 | 121 | -> [(String,String)] -> String
|
| 114 | -generateConfigHs cProjectUnitId settings = either error id $ do
|
|
| 122 | +generateConfigHs cProjectUnitId cGhcInternalUnitId settings = either error id $ do
|
|
| 115 | 123 | let getSetting' = getSetting $ (("cStage","2"):) settings
|
| 116 | 124 | buildPlatform <- getSetting' "cBuildPlatformString" "Host platform"
|
| 117 | 125 | hostPlatform <- getSetting' "cHostPlatformString" "Target platform"
|
| ... | ... | @@ -127,6 +135,7 @@ generateConfigHs cProjectUnitId settings = either error id $ do |
| 127 | 135 | , " , cBooterVersion"
|
| 128 | 136 | , " , cStage"
|
| 129 | 137 | , " , cProjectUnitId"
|
| 138 | + , " , cGhcInternalUnitId"
|
|
| 130 | 139 | , " ) where"
|
| 131 | 140 | , ""
|
| 132 | 141 | , "import GHC.Prelude.Basic"
|
| ... | ... | @@ -150,4 +159,7 @@ generateConfigHs cProjectUnitId settings = either error id $ do |
| 150 | 159 | , ""
|
| 151 | 160 | , "cProjectUnitId :: String"
|
| 152 | 161 | , "cProjectUnitId = " ++ show cProjectUnitId
|
| 162 | + , ""
|
|
| 163 | + , "cGhcInternalUnitId :: String"
|
|
| 164 | + , "cGhcInternalUnitId = " ++ show cGhcInternalUnitId
|
|
| 153 | 165 | ] |
| ... | ... | @@ -601,6 +601,8 @@ generateConfigHs = do |
| 601 | 601 | -- 'pkgUnitId' on 'compiler' (the ghc-library package) to create the
|
| 602 | 602 | -- unit-id in both situations.
|
| 603 | 603 | cProjectUnitId <- expr . (`pkgUnitId` compiler) =<< getStage
|
| 604 | + |
|
| 605 | + cGhcInternalUnitId <- expr . (`pkgUnitId` ghcInternal) =<< getStage
|
|
| 604 | 606 | return $ unlines
|
| 605 | 607 | [ "module GHC.Settings.Config"
|
| 606 | 608 | , " ( module GHC.Version"
|
| ... | ... | @@ -610,6 +612,7 @@ generateConfigHs = do |
| 610 | 612 | , " , cBooterVersion"
|
| 611 | 613 | , " , cStage"
|
| 612 | 614 | , " , cProjectUnitId"
|
| 615 | + , " , cGhcInternalUnitId"
|
|
| 613 | 616 | , " ) where"
|
| 614 | 617 | , ""
|
| 615 | 618 | , "import GHC.Prelude.Basic"
|
| ... | ... | @@ -633,6 +636,9 @@ generateConfigHs = do |
| 633 | 636 | , ""
|
| 634 | 637 | , "cProjectUnitId :: String"
|
| 635 | 638 | , "cProjectUnitId = " ++ show cProjectUnitId
|
| 639 | + , ""
|
|
| 640 | + , "cGhcInternalUnitId :: String"
|
|
| 641 | + , "cGhcInternalUnitId = " ++ show cGhcInternalUnitId
|
|
| 636 | 642 | ]
|
| 637 | 643 | where
|
| 638 | 644 | stageString (Stage0 InTreeLibs) = "1"
|
| ... | ... | @@ -24,7 +24,7 @@ executable lint-whitespace |
| 24 | 24 | process
|
| 25 | 25 | ^>= 1.6,
|
| 26 | 26 | containers
|
| 27 | - >= 0.6 && <0.8,
|
|
| 27 | + >= 0.6 && <0.9,
|
|
| 28 | 28 | base
|
| 29 | 29 | >= 4.14 && < 5,
|
| 30 | 30 | text
|