Merge pull request #10625 from cabalism/fix/project-config-path-haddock
[cabal.git] / Cabal / src / Distribution / Simple / GHC / ImplInfo.hs
blobf575697819b73d5b76e680c56a61a4f76283e50a
1 -----------------------------------------------------------------------------
3 -- |
4 -- Module : Distribution.Simple.GHC.ImplInfo
5 --
6 -- Maintainer : cabal-devel@haskell.org
7 -- Portability : portable
8 --
9 -- This module contains the data structure describing invocation
10 -- details for a GHC or GHC-derived compiler, such as supported flags
11 -- and workarounds for bugs.
12 module Distribution.Simple.GHC.ImplInfo
13 ( GhcImplInfo (..)
14 , getImplInfo
15 , ghcVersionImplInfo
16 , ghcjsVersionImplInfo
17 ) where
19 import Distribution.Compat.Prelude
20 import Prelude ()
22 import Distribution.Simple.Compiler
23 import Distribution.Version
25 -- |
26 -- Information about features and quirks of a GHC-based implementation.
28 -- Compiler flavors based on GHC behave similarly enough that some of
29 -- the support code for them is shared. Every implementation has its
30 -- own peculiarities, that may or may not be a direct result of the
31 -- underlying GHC version. This record keeps track of these differences.
33 -- All shared code (i.e. everything not in the Distribution.Simple.FLAVOR
34 -- module) should use implementation info rather than version numbers
35 -- to test for supported features.
36 data GhcImplInfo = GhcImplInfo
37 { supportsHaskell2010 :: Bool
38 -- ^ -XHaskell2010 and -XHaskell98 flags
39 , supportsGHC2021 :: Bool
40 -- ^ -XGHC2021 flag
41 , supportsGHC2024 :: Bool
42 -- ^ -XGHC2024 flag
43 , reportsNoExt :: Bool
44 -- ^ --supported-languages gives Ext and NoExt
45 , alwaysNondecIndent :: Bool
46 -- ^ NondecreasingIndentation is always on
47 , flagGhciScript :: Bool
48 -- ^ -ghci-script flag supported
49 , flagProfAuto :: Bool
50 -- ^ new style -fprof-auto* flags
51 , flagProfLate :: Bool
52 -- ^ fprof-late flag
53 , flagPackageConf :: Bool
54 -- ^ use package-conf instead of package-db
55 , flagDebugInfo :: Bool
56 -- ^ -g flag supported
57 , flagHie :: Bool
58 -- ^ -hiedir flag supported
59 , supportsDebugLevels :: Bool
60 -- ^ supports numeric @-g@ levels
61 , supportsPkgEnvFiles :: Bool
62 -- ^ picks up @.ghc.environment@ files
63 , flagWarnMissingHomeModules :: Bool
64 -- ^ -Wmissing-home-modules is supported
65 , unitIdForExes :: Bool
66 -- ^ Pass -this-unit-id flag when building executables
69 getImplInfo :: Compiler -> GhcImplInfo
70 getImplInfo comp =
71 case compilerFlavor comp of
72 GHC -> ghcVersionImplInfo (compilerVersion comp)
73 GHCJS -> case compilerCompatVersion GHC comp of
74 Just ghcVer -> ghcjsVersionImplInfo (compilerVersion comp) ghcVer
75 _ ->
76 error
77 ( "Distribution.Simple.GHC.Props.getImplProps: "
78 ++ "could not find GHC version for GHCJS compiler"
80 x ->
81 error
82 ( "Distribution.Simple.GHC.Props.getImplProps only works"
83 ++ "for GHC-like compilers (GHC, GHCJS)"
84 ++ ", but found "
85 ++ show x
88 ghcVersionImplInfo :: Version -> GhcImplInfo
89 ghcVersionImplInfo ver =
90 GhcImplInfo
91 { supportsHaskell2010 = v >= [7]
92 , supportsGHC2021 = v >= [9, 1]
93 , supportsGHC2024 = v >= [9, 9]
94 , reportsNoExt = v >= [7]
95 , alwaysNondecIndent = v < [7, 1]
96 , flagGhciScript = v >= [7, 2]
97 , flagProfAuto = v >= [7, 4]
98 , flagProfLate = v >= [9, 4]
99 , flagPackageConf = v < [7, 5]
100 , flagDebugInfo = v >= [7, 10]
101 , flagHie = v >= [8, 8]
102 , supportsDebugLevels = v >= [8, 0]
103 , supportsPkgEnvFiles = v >= [8, 0, 1, 20160901] -- broken in 8.0.1, fixed in 8.0.2
104 , flagWarnMissingHomeModules = v >= [8, 2]
105 , unitIdForExes = v >= [9, 2]
107 where
108 v = versionNumbers ver
110 ghcjsVersionImplInfo
111 :: Version
112 -- ^ The GHCJS version
113 -> Version
114 -- ^ The GHC version
115 -> GhcImplInfo
116 ghcjsVersionImplInfo _ghcjsver ghcver =
117 GhcImplInfo
118 { supportsHaskell2010 = True
119 , supportsGHC2021 = True
120 , supportsGHC2024 = ghcv >= [9, 9]
121 , reportsNoExt = True
122 , alwaysNondecIndent = False
123 , flagGhciScript = True
124 , flagProfAuto = True
125 , flagProfLate = True
126 , flagPackageConf = False
127 , flagDebugInfo = False
128 , flagHie = ghcv >= [8, 8]
129 , supportsDebugLevels = ghcv >= [8, 0]
130 , supportsPkgEnvFiles = ghcv >= [8, 0, 2] -- TODO: check this works in ghcjs
131 , flagWarnMissingHomeModules = ghcv >= [8, 2]
132 , unitIdForExes = ghcv >= [9, 2]
134 where
135 ghcv = versionNumbers ghcver