Skip to content

Commit 6cfbe6a

Browse files
committed
wip
1 parent 2f7722e commit 6cfbe6a

File tree

8 files changed

+46
-14
lines changed

8 files changed

+46
-14
lines changed

Cabal-syntax/src/Distribution/Compiler.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ import Distribution.Parsec (Parsec (..))
6060
import Distribution.Pretty (Pretty (..), prettyShow)
6161
import qualified System.Info (compilerName, compilerVersion)
6262
import qualified Text.PrettyPrint as Disp
63+
import Distribution.Types.UnitId (UnitId)
64+
import Distribution.Package (PackageName)
6365

6466
data CompilerFlavor
6567
= GHC
@@ -213,6 +215,11 @@ data CompilerInfo = CompilerInfo
213215
-- ^ Supported language standards, if known.
214216
, compilerInfoExtensions :: Maybe [Extension]
215217
-- ^ Supported extensions, if known.
218+
, compilerInfoWiredInUnitIds :: Maybe [(PackageName, UnitId)]
219+
-- ^ 'UnitId's that the compiler doesn't support reinstalling.
220+
-- For instance, when using GHC plugins, one wants to use the
221+
-- exact same version of the `ghc` package as the one the
222+
-- compiler was linked against.
216223
}
217224
deriving (Generic, Show, Read)
218225

@@ -244,4 +251,4 @@ abiTagString (AbiTag tag) = tag
244251
-- compiler id's.
245252
unknownCompilerInfo :: CompilerId -> AbiTag -> CompilerInfo
246253
unknownCompilerInfo compilerId abiTag =
247-
CompilerInfo compilerId abiTag (Just []) Nothing Nothing
254+
CompilerInfo compilerId abiTag (Just []) Nothing Nothing Nothing

Cabal-tests/tests/UnitTests/Distribution/Simple/Program/GHC.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ tests = testGroup "Distribution.Simple.Program.GHC"
5454
, compilerLanguages = []
5555
, compilerExtensions = []
5656
, compilerProperties = Map.singleton "Support parallel --make" "YES"
57+
, compilerWiredInUnitIds = Nothing
5758
})
5859
(Platform X86_64 Linux)
5960
(mempty { ghcOptNumJobs = Flag (NumJobs (Just 4)) })

Cabal/src/Distribution/Simple/Compiler.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ import Distribution.Compiler
100100
import Distribution.Simple.Utils
101101
import Distribution.Utils.Path
102102
import Distribution.Version
103+
import Distribution.Types.UnitId (UnitId)
104+
import Distribution.Package (PackageName)
103105

104106
import Language.Haskell.Extension
105107

@@ -119,6 +121,11 @@ data Compiler = Compiler
119121
-- ^ Supported language standards.
120122
, compilerExtensions :: [(Extension, Maybe CompilerFlag)]
121123
-- ^ Supported extensions.
124+
, compilerWiredInUnitIds :: Maybe [(PackageName, UnitId)]
125+
-- ^ 'UnitId's that the compiler doesn't support reinstalling.
126+
-- For instance, when using GHC plugins, one wants to use the
127+
-- exact same version of the `ghc` package as the one the
128+
-- compiler was linked against.
122129
, compilerProperties :: Map String String
123130
-- ^ A key-value map for properties not covered by the above fields.
124131
}
@@ -177,6 +184,7 @@ compilerInfo c =
177184
(Just . compilerCompat $ c)
178185
(Just . map fst . compilerLanguages $ c)
179186
(Just . map fst . compilerExtensions $ c)
187+
(compilerWiredInUnitIds c)
180188

181189
-- ------------------------------------------------------------
182190

Cabal/src/Distribution/Simple/GHC.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,26 @@ configure verbosity hcPath hcPkgPath conf0 = do
248248
compilerId :: CompilerId
249249
compilerId = CompilerId GHC ghcVersion
250250

251+
projectUnitId :: Maybe String
252+
projectUnitId = Map.lookup "Project Unit Id" ghcInfoMap
253+
254+
-- The @AbiTag@ is the @Project Unit Id@ but with redundant information from the compiler version removed.
255+
-- For development versions of the compiler these look like:
256+
-- @Project Unit Id@: "ghc-9.13-inplace"
257+
-- @compilerId@: "ghc-9.13.20250413"
258+
-- So, we need to be careful to only strip the /common/ prefix.
259+
-- In this example, @AbiTag@ is "inplace".
251260
compilerAbiTag :: AbiTag
252261
compilerAbiTag = maybe NoAbiTag AbiTag (Map.lookup "Project Unit Id" ghcInfoMap >>= stripPrefix (prettyShow compilerId <> "-"))
253262

263+
wiredInUnitIds = do
264+
ghcInternalUnitId <- Map.lookup "ghc-internal Unit Id" ghcInfoMap
265+
ghcUnitId <- projectUnitId
266+
pure
267+
[ (mkPackageName "ghc", mkUnitId ghcUnitId)
268+
, (mkPackageName "ghc-internal", mkUnitId ghcInternalUnitId)
269+
]
270+
254271
let comp =
255272
Compiler
256273
{ compilerId
@@ -259,6 +276,7 @@ configure verbosity hcPath hcPkgPath conf0 = do
259276
, compilerLanguages = languages
260277
, compilerExtensions = extensions
261278
, compilerProperties = ghcInfoMap
279+
, compilerWiredInUnitIds = wiredInUnitIds
262280
}
263281
compPlatform = Internal.targetPlatform ghcInfo
264282
-- configure gcc and ld

Cabal/src/Distribution/Simple/GHCJS.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ configure verbosity hcPath hcPkgPath conf0 = do
203203
, compilerLanguages = languages
204204
, compilerExtensions = extensions
205205
, compilerProperties = ghcInfoMap
206+
, compilerWiredInUnitIds = Nothing
206207
}
207208
compPlatform = Internal.targetPlatform ghcjsInfo
208209
return (comp, compPlatform, progdb3)

Cabal/src/Distribution/Simple/UHC.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ configure verbosity hcPath _hcPkgPath progdb = do
7878
, compilerLanguages = uhcLanguages
7979
, compilerExtensions = uhcLanguageExtensions
8080
, compilerProperties = Map.empty
81+
, compilerWiredInUnitIds = Nothing
8182
}
8283
compPlatform = Nothing
8384
return (comp, compPlatform, progdb')

cabal-install/src/Distribution/Client/Dependency.hs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ import Distribution.Client.Utils
9898
import qualified Distribution.Compat.Graph as Graph
9999
import Distribution.Compiler
100100
( CompilerInfo (..)
101-
, AbiTag (..)
102101
)
103102
import Distribution.Package
104103
( Package (..)
@@ -108,8 +107,6 @@ import Distribution.Package
108107
, mkPackageName
109108
, packageName
110109
, packageVersion
111-
, UnitId
112-
, mkUnitId
113110
)
114111
import qualified Distribution.PackageDescription as PD
115112
import Distribution.PackageDescription.Configuration
@@ -438,19 +435,16 @@ setSolverVerbosity verbosity params =
438435
{ depResolverVerbosity = verbosity
439436
}
440437

441-
dependOnSpecificCompiler :: CompilerInfo -> DepResolverParams -> DepResolverParams
442-
dependOnSpecificCompiler compiler params = addConstraints extraConstraints params
438+
dependOnWiredIns :: CompilerInfo -> DepResolverParams -> DepResolverParams
439+
dependOnWiredIns compiler params = addConstraints extraConstraints params
443440
where
444441
extraConstraints =
445442
[ LabeledPackageConstraint
446-
(PackageConstraint (ScopeAnyQualifier (mkPackageName "ghc")) (PackagePropertyInstalledSpecificUnitId (compilerIdToUnitId ghc_lib_abi)))
443+
(PackageConstraint (ScopeAnyQualifier pkgName) (PackagePropertyInstalledSpecificUnitId unitId))
447444
ConstraintSourceNonReinstallablePackage
448-
| AbiTag ghc_lib_abi <- [compilerInfoAbiTag compiler]
445+
| (pkgName, unitId) <- fromMaybe [] $ compilerInfoWiredInUnitIds compiler
449446
]
450447

451-
compilerIdToUnitId :: String -> UnitId
452-
compilerIdToUnitId uid = mkUnitId (prettyShow (compilerInfoId compiler) ++ "-" ++ uid)
453-
454448
-- | Some packages are specific to a given compiler version and should never be
455449
-- reinstalled.
456450
dontInstallNonReinstallablePackages :: DepResolverParams -> DepResolverParams
@@ -856,9 +850,9 @@ resolveDependencies platform comp pkgConfigDB params =
856850
order
857851
verbosity
858852
) =
859-
if asBool (depResolverAllowBootLibInstalls params)
860-
then dependOnSpecificCompiler comp params
861-
else dontInstallNonReinstallablePackages (dependOnSpecificCompiler comp params)
853+
if isJust (compilerInfoWiredInUnitIds comp) || asBool (depResolverAllowBootLibInstalls params)
854+
then dependOnWiredIns comp params
855+
else dontInstallNonReinstallablePackages params
862856

863857
preferences :: PackageName -> PackagePreferences
864858
preferences = interpretPackagesPreference targets defpref prefs

cabal-install/tests/UnitTests/Distribution/Client/Store.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ testListEmpty =
4646
, compilerLanguages = []
4747
, compilerExtensions = []
4848
, compilerProperties = mempty
49+
, compilerWiredInUnitIds = Nothing
4950
}
5051

5152
unitid = mkUnitId "foo-1.0-xyz"
@@ -102,6 +103,7 @@ testInstallSerial =
102103
, compilerLanguages = []
103104
, compilerExtensions = []
104105
, compilerProperties = mempty
106+
, compilerWiredInUnitIds = Nothing
105107
}
106108

107109
unitid1 = mkUnitId "foo-1.0-xyz"

0 commit comments

Comments
 (0)