Skip to content

Commit

Permalink
Conditionally omit TemplateHaskell from set of supported extensions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hvr committed Nov 17, 2015
1 parent 4e11fb9 commit 9f68eb4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Cabal/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE PatternGuards #-}

-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Simple.GHC
Expand Down Expand Up @@ -105,7 +107,7 @@ import Language.Haskell.Extension (Extension(..), KnownExtension(..))
import Control.Monad ( unless, when )
import Data.Char ( isDigit, isSpace )
import Data.List
import qualified Data.Map as M ( fromList )
import qualified Data.Map as M ( fromList, lookup )
import Data.Maybe ( catMaybes )
import Data.Monoid as Mon ( Monoid(..) )
import Data.Version ( showVersion )
Expand Down Expand Up @@ -155,11 +157,20 @@ configure verbosity hcPath hcPkgPath conf0 = do
addKnownProgram hsc2hsProgram' conf2

languages <- Internal.getLanguages verbosity implInfo ghcProg
extensions <- Internal.getExtensions verbosity implInfo ghcProg
extensions0 <- Internal.getExtensions verbosity implInfo ghcProg

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

-- starting with GHC 8.0, `TemplateHaskell` will be omitted from
-- `--supported-extensions` when it's not available.
-- for older GHCs we can use the "Have interpreter" property to
-- filter out `TemplateHaskell`
extensions | ghcVersion < Version [8] []
, Just "NO" <- M.lookup "Have interpreter" ghcInfoMap
= filter ((/= EnableExtension TemplateHaskell) . fst) extensions0
| otherwise = extensions0

let comp = Compiler {
compilerId = CompilerId GHC ghcVersion,
compilerAbiTag = NoAbiTag,
Expand Down

0 comments on commit 9f68eb4

Please sign in to comment.