Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
-
49f44e52
by Teo Camarasu at 2025-06-26T04:19:51-04:00
3 changed files:
Changes:
... | ... | @@ -3463,6 +3463,7 @@ compilerInfo dflags |
3463 | 3463 | ("Project Patch Level1", cProjectPatchLevel1),
|
3464 | 3464 | ("Project Patch Level2", cProjectPatchLevel2),
|
3465 | 3465 | ("Project Unit Id", cProjectUnitId),
|
3466 | + ("ghc-internal Unit Id", cGhcInternalUnitId), -- See Note [Special unit-ids]
|
|
3466 | 3467 | ("Booter version", cBooterVersion),
|
3467 | 3468 | ("Stage", cStage),
|
3468 | 3469 | ("Build platform", cBuildPlatformString),
|
... | ... | @@ -3516,6 +3517,26 @@ compilerInfo dflags |
3516 | 3517 | expandDirectories :: FilePath -> Maybe FilePath -> String -> String
|
3517 | 3518 | expandDirectories topd mtoold = expandToolDir useInplaceMinGW mtoold . expandTopDir topd
|
3518 | 3519 | |
3520 | +-- Note [Special unit-ids]
|
|
3521 | +-- ~~~~~~~~~~~~~~~~~~~~~~~
|
|
3522 | +-- Certain units are special to the compiler:
|
|
3523 | +-- - Wired-in identifiers reference a specific unit-id of `ghc-internal`.
|
|
3524 | +-- - GHC plugins must be linked against a specific unit-id of `ghc`,
|
|
3525 | +-- namely the same one as the compiler.
|
|
3526 | +-- - When using Template Haskell, the result of executing splices refer to
|
|
3527 | +-- the Template Haskell ASTs created using constructors from `ghc-internal`,
|
|
3528 | +-- and must be linked against the same `ghc-internal` unit-id as the compiler.
|
|
3529 | +--
|
|
3530 | +-- We therefore expose the unit-id of `ghc-internal` ("ghc-internal Unit Id") and
|
|
3531 | +-- ghc ("Project Unit Id") through `ghc --info`.
|
|
3532 | +--
|
|
3533 | +-- This allows build tools to act accordingly, eg, if a user wishes to build a
|
|
3534 | +-- GHC plugin, `cabal-install` might force them to use the exact `ghc` unit
|
|
3535 | +-- that the compiler was linked against.
|
|
3536 | +-- See:
|
|
3537 | +-- - https://github.com/haskell/cabal/issues/10087
|
|
3538 | +-- - https://github.com/commercialhaskell/stack/issues/6749
|
|
3539 | + |
|
3519 | 3540 | {- -----------------------------------------------------------------------------
|
3520 | 3541 | Note [DynFlags consistency]
|
3521 | 3542 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
... | ... | @@ -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
|
... | ... | @@ -56,7 +57,7 @@ primopIncls = |
56 | 57 | ]
|
57 | 58 | |
58 | 59 | ghcAutogen :: Verbosity -> LocalBuildInfo -> IO ()
|
59 | -ghcAutogen verbosity lbi@LocalBuildInfo{pkgDescrFile,withPrograms,componentNameMap}
|
|
60 | +ghcAutogen verbosity lbi@LocalBuildInfo{pkgDescrFile,withPrograms,componentNameMap,installedPkgs}
|
|
60 | 61 | = do
|
61 | 62 | -- Get compiler/ root directory from the cabal file
|
62 | 63 | let Just compilerRoot = takeDirectory <$> pkgDescrFile
|
... | ... | @@ -96,9 +97,14 @@ ghcAutogen verbosity lbi@LocalBuildInfo{pkgDescrFile,withPrograms,componentNameM |
96 | 97 | Just [LibComponentLocalBuildInfo{componentUnitId}] -> unUnitId componentUnitId
|
97 | 98 | _ -> error "Couldn't find unique cabal library when building ghc"
|
98 | 99 | |
100 | + let cGhcInternalUnitId = case lookupPackageName installedPkgs (mkPackageName "ghc-internal") of
|
|
101 | + -- We assume there is exactly one copy of `ghc-internal` in our dependency closure
|
|
102 | + [(_,[packageInfo])] -> unUnitId $ installedUnitId packageInfo
|
|
103 | + _ -> error "Couldn't find unique ghc-internal library when building ghc"
|
|
104 | + |
|
99 | 105 | -- Write GHC.Settings.Config
|
100 | 106 | configHsPath = autogenPackageModulesDir lbi </> "GHC/Settings/Config.hs"
|
101 | - configHs = generateConfigHs cProjectUnitId settings
|
|
107 | + configHs = generateConfigHs cProjectUnitId cGhcInternalUnitId settings
|
|
102 | 108 | createDirectoryIfMissingVerbose verbosity True (takeDirectory configHsPath)
|
103 | 109 | rewriteFileEx verbosity configHsPath configHs
|
104 | 110 | |
... | ... | @@ -110,8 +116,9 @@ getSetting settings kh kr = go settings kr |
110 | 116 | Just v -> Right v
|
111 | 117 | |
112 | 118 | generateConfigHs :: String -- ^ ghc's cabal-generated unit-id, which matches its package-id/key
|
119 | + -> String -- ^ ghc-internal's cabal-generated unit-id, which matches its package-id/key
|
|
113 | 120 | -> [(String,String)] -> String
|
114 | -generateConfigHs cProjectUnitId settings = either error id $ do
|
|
121 | +generateConfigHs cProjectUnitId cGhcInternalUnitId settings = either error id $ do
|
|
115 | 122 | let getSetting' = getSetting $ (("cStage","2"):) settings
|
116 | 123 | buildPlatform <- getSetting' "cBuildPlatformString" "Host platform"
|
117 | 124 | hostPlatform <- getSetting' "cHostPlatformString" "Target platform"
|
... | ... | @@ -127,6 +134,7 @@ generateConfigHs cProjectUnitId settings = either error id $ do |
127 | 134 | , " , cBooterVersion"
|
128 | 135 | , " , cStage"
|
129 | 136 | , " , cProjectUnitId"
|
137 | + , " , cGhcInternalUnitId"
|
|
130 | 138 | , " ) where"
|
131 | 139 | , ""
|
132 | 140 | , "import GHC.Prelude.Basic"
|
... | ... | @@ -150,4 +158,7 @@ generateConfigHs cProjectUnitId settings = either error id $ do |
150 | 158 | , ""
|
151 | 159 | , "cProjectUnitId :: String"
|
152 | 160 | , "cProjectUnitId = " ++ show cProjectUnitId
|
161 | + , ""
|
|
162 | + , "cGhcInternalUnitId :: String"
|
|
163 | + , "cGhcInternalUnitId = " ++ show cGhcInternalUnitId
|
|
153 | 164 | ] |
... | ... | @@ -607,6 +607,8 @@ generateConfigHs = do |
607 | 607 | -- 'pkgUnitId' on 'compiler' (the ghc-library package) to create the
|
608 | 608 | -- unit-id in both situations.
|
609 | 609 | cProjectUnitId <- expr . (`pkgUnitId` compiler) =<< getStage
|
610 | + |
|
611 | + cGhcInternalUnitId <- expr . (`pkgUnitId` ghcInternal) =<< getStage
|
|
610 | 612 | return $ unlines
|
611 | 613 | [ "module GHC.Settings.Config"
|
612 | 614 | , " ( module GHC.Version"
|
... | ... | @@ -616,6 +618,7 @@ generateConfigHs = do |
616 | 618 | , " , cBooterVersion"
|
617 | 619 | , " , cStage"
|
618 | 620 | , " , cProjectUnitId"
|
621 | + , " , cGhcInternalUnitId"
|
|
619 | 622 | , " ) where"
|
620 | 623 | , ""
|
621 | 624 | , "import GHC.Prelude.Basic"
|
... | ... | @@ -639,6 +642,9 @@ generateConfigHs = do |
639 | 642 | , ""
|
640 | 643 | , "cProjectUnitId :: String"
|
641 | 644 | , "cProjectUnitId = " ++ show cProjectUnitId
|
645 | + , ""
|
|
646 | + , "cGhcInternalUnitId :: String"
|
|
647 | + , "cGhcInternalUnitId = " ++ show cGhcInternalUnitId
|
|
642 | 648 | ]
|
643 | 649 | where
|
644 | 650 | stageString (Stage0 InTreeLibs) = "1"
|