From 59b2b3fb07673d85fa07645308eb565f31ffead6 Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Thu, 12 Oct 2023 13:58:36 +0700 Subject: [PATCH] Include the compiler ABI tag in nix-style package hashes --- Cabal/src/Distribution/Simple/GHC.hs | 12 ++++++++++-- cabal-install/src/Distribution/Client/PackageHash.hs | 10 +++++++++- .../src/Distribution/Client/ProjectPlanning.hs | 1 + changelog.d/pr-9325 | 3 +++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 changelog.d/pr-9325 diff --git a/Cabal/src/Distribution/Simple/GHC.hs b/Cabal/src/Distribution/Simple/GHC.hs index 3c380a41a86..c06fd7bdfc3 100644 --- a/Cabal/src/Distribution/Simple/GHC.hs +++ b/Cabal/src/Distribution/Simple/GHC.hs @@ -1,6 +1,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiWayIf #-} +{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TupleSections #-} @@ -83,6 +84,7 @@ import Prelude () import Control.Monad (forM_, msum) import Data.Char (isLower) +import Data.List (stripPrefix) import qualified Data.Map as Map import Distribution.CabalSpecVersion import Distribution.InstalledPackageInfo (InstalledPackageInfo) @@ -246,10 +248,16 @@ configure verbosity hcPath hcPkgPath conf0 = do filterExt ext = filter ((/= EnableExtension ext) . fst) + compilerId :: CompilerId + compilerId = CompilerId GHC ghcVersion + + compilerAbiTag :: AbiTag + compilerAbiTag = maybe NoAbiTag AbiTag (Map.lookup "Project Unit Id" ghcInfoMap >>= stripPrefix (prettyShow compilerId <> "-")) + let comp = Compiler - { compilerId = CompilerId GHC ghcVersion - , compilerAbiTag = NoAbiTag + { compilerId + , compilerAbiTag , compilerCompat = [] , compilerLanguages = languages , compilerExtensions = extensions diff --git a/cabal-install/src/Distribution/Client/PackageHash.hs b/cabal-install/src/Distribution/Client/PackageHash.hs index 18be444cde7..2b8210f890a 100644 --- a/cabal-install/src/Distribution/Client/PackageHash.hs +++ b/cabal-install/src/Distribution/Client/PackageHash.hs @@ -38,7 +38,8 @@ import Distribution.Package , mkComponentId ) import Distribution.Simple.Compiler - ( CompilerId + ( AbiTag (..) + , CompilerId , DebugInfoLevel (..) , OptimisationLevel (..) , PackageDB @@ -191,6 +192,7 @@ type PackageSourceHash = HashValue -- package hash. data PackageHashConfigInputs = PackageHashConfigInputs { pkgHashCompilerId :: CompilerId + , pkgHashCompilerAbiTag :: AbiTag , pkgHashPlatform :: Platform , pkgHashFlagAssignment :: FlagAssignment -- complete not partial , pkgHashConfigureScriptArgs :: [String] -- just ./configure for build-type Configure @@ -301,6 +303,7 @@ renderPackageHashInputs pkgHashDirectDeps , -- and then all the config entry "compilerid" prettyShow pkgHashCompilerId + , entry "compiler-abi-tag" renderAbiTag pkgHashCompilerAbiTag , entry "platform" prettyShow pkgHashPlatform , opt "flags" mempty showFlagAssignment pkgHashFlagAssignment , opt "configure-script" [] unwords pkgHashConfigureScriptArgs @@ -352,3 +355,8 @@ renderPackageHashInputs opt key def format value | value == def = Nothing | otherwise = entry key format value + +renderAbiTag :: AbiTag -> String +renderAbiTag abiTag = case abiTag of + NoAbiTag -> "unknown" + AbiTag tag -> tag diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs index 1b92a8aa54b..9b7b73f6c81 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs @@ -4569,6 +4569,7 @@ packageHashConfigInputs packageHashConfigInputs shared@ElaboratedSharedConfig{..} pkg = PackageHashConfigInputs { pkgHashCompilerId = compilerId pkgConfigCompiler + , pkgHashCompilerAbiTag = compilerAbiTag pkgConfigCompiler , pkgHashPlatform = pkgConfigPlatform , pkgHashFlagAssignment = elabFlagAssignment , pkgHashConfigureScriptArgs = elabConfigureScriptArgs diff --git a/changelog.d/pr-9325 b/changelog.d/pr-9325 new file mode 100644 index 00000000000..0dd5e8f8fdc --- /dev/null +++ b/changelog.d/pr-9325 @@ -0,0 +1,3 @@ +synopsis: Include the compiler ABI tag in nix-style package hashes +packages: Cabal cabal-install +prs: #9325