Skip to content

Commit 9f68eb4

Browse files
committed
Conditionally omit TemplateHaskell from set of supported extensions
This emulates what GHC>=8 will do on its own for older GHC versions. This is particularly useful in combination with #2644 allowing the solver to toggle flags depending on the availability of `-XTemplateHaskell`. For instance, cross-compilers and/or unregisterised GHC builds often don't have TemplateHaskell support. Having support for toggling flags based on availability of `-XTemplateHaskell` allows `cabal` to support such environments with less manual intervention.
1 parent 4e11fb9 commit 9f68eb4

File tree

1 file changed

+13
-2
lines changed
  • Cabal/Distribution/Simple

1 file changed

+13
-2
lines changed

Cabal/Distribution/Simple/GHC.hs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE PatternGuards #-}
2+
13
-----------------------------------------------------------------------------
24
-- |
35
-- Module : Distribution.Simple.GHC
@@ -105,7 +107,7 @@ import Language.Haskell.Extension (Extension(..), KnownExtension(..))
105107
import Control.Monad ( unless, when )
106108
import Data.Char ( isDigit, isSpace )
107109
import Data.List
108-
import qualified Data.Map as M ( fromList )
110+
import qualified Data.Map as M ( fromList, lookup )
109111
import Data.Maybe ( catMaybes )
110112
import Data.Monoid as Mon ( Monoid(..) )
111113
import Data.Version ( showVersion )
@@ -155,11 +157,20 @@ configure verbosity hcPath hcPkgPath conf0 = do
155157
addKnownProgram hsc2hsProgram' conf2
156158

157159
languages <- Internal.getLanguages verbosity implInfo ghcProg
158-
extensions <- Internal.getExtensions verbosity implInfo ghcProg
160+
extensions0 <- Internal.getExtensions verbosity implInfo ghcProg
159161

160162
ghcInfo <- Internal.getGhcInfo verbosity implInfo ghcProg
161163
let ghcInfoMap = M.fromList ghcInfo
162164

165+
-- starting with GHC 8.0, `TemplateHaskell` will be omitted from
166+
-- `--supported-extensions` when it's not available.
167+
-- for older GHCs we can use the "Have interpreter" property to
168+
-- filter out `TemplateHaskell`
169+
extensions | ghcVersion < Version [8] []
170+
, Just "NO" <- M.lookup "Have interpreter" ghcInfoMap
171+
= filter ((/= EnableExtension TemplateHaskell) . fst) extensions0
172+
| otherwise = extensions0
173+
163174
let comp = Compiler {
164175
compilerId = CompilerId GHC ghcVersion,
165176
compilerAbiTag = NoAbiTag,

0 commit comments

Comments
 (0)