Make “sublibrary” standard terminology in docs
[cabal.git] / Cabal / src / Distribution / Simple / GHC / ImplInfo.hs
blobdf1a811bfb6260de0fcc263dc88d8cea7bee10a9
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 , reportsNoExt :: Bool
42 -- ^ --supported-languages gives Ext and NoExt
43 , alwaysNondecIndent :: Bool
44 -- ^ NondecreasingIndentation is always on
45 , flagGhciScript :: Bool
46 -- ^ -ghci-script flag supported
47 , flagProfAuto :: Bool
48 -- ^ new style -fprof-auto* flags
49 , flagProfLate :: Bool
50 -- ^ fprof-late flag
51 , flagPackageConf :: Bool
52 -- ^ use package-conf instead of package-db
53 , flagDebugInfo :: Bool
54 -- ^ -g flag supported
55 , flagHie :: Bool
56 -- ^ -hiedir flag supported
57 , supportsDebugLevels :: Bool
58 -- ^ supports numeric @-g@ levels
59 , supportsPkgEnvFiles :: Bool
60 -- ^ picks up @.ghc.environment@ files
61 , flagWarnMissingHomeModules :: Bool
62 -- ^ -Wmissing-home-modules is supported
63 , unitIdForExes :: Bool
64 -- ^ Pass -this-unit-id flag when building executables
67 getImplInfo :: Compiler -> GhcImplInfo
68 getImplInfo comp =
69 case compilerFlavor comp of
70 GHC -> ghcVersionImplInfo (compilerVersion comp)
71 GHCJS -> case compilerCompatVersion GHC comp of
72 Just ghcVer -> ghcjsVersionImplInfo (compilerVersion comp) ghcVer
73 _ ->
74 error
75 ( "Distribution.Simple.GHC.Props.getImplProps: "
76 ++ "could not find GHC version for GHCJS compiler"
78 x ->
79 error
80 ( "Distribution.Simple.GHC.Props.getImplProps only works"
81 ++ "for GHC-like compilers (GHC, GHCJS)"
82 ++ ", but found "
83 ++ show x
86 ghcVersionImplInfo :: Version -> GhcImplInfo
87 ghcVersionImplInfo ver =
88 GhcImplInfo
89 { supportsHaskell2010 = v >= [7]
90 , supportsGHC2021 = v >= [9, 1]
91 , reportsNoExt = v >= [7]
92 , alwaysNondecIndent = v < [7, 1]
93 , flagGhciScript = v >= [7, 2]
94 , flagProfAuto = v >= [7, 4]
95 , flagProfLate = v >= [9, 4]
96 , flagPackageConf = v < [7, 5]
97 , flagDebugInfo = v >= [7, 10]
98 , flagHie = v >= [8, 8]
99 , supportsDebugLevels = v >= [8, 0]
100 , supportsPkgEnvFiles = v >= [8, 0, 1, 20160901] -- broken in 8.0.1, fixed in 8.0.2
101 , flagWarnMissingHomeModules = v >= [8, 2]
102 , unitIdForExes = v >= [9, 2]
104 where
105 v = versionNumbers ver
107 ghcjsVersionImplInfo
108 :: Version
109 -- ^ The GHCJS version
110 -> Version
111 -- ^ The GHC version
112 -> GhcImplInfo
113 ghcjsVersionImplInfo _ghcjsver ghcver =
114 GhcImplInfo
115 { supportsHaskell2010 = True
116 , supportsGHC2021 = True
117 , reportsNoExt = True
118 , alwaysNondecIndent = False
119 , flagGhciScript = True
120 , flagProfAuto = True
121 , flagProfLate = True
122 , flagPackageConf = False
123 , flagDebugInfo = False
124 , flagHie = ghcv >= [8, 8]
125 , supportsDebugLevels = ghcv >= [8, 0]
126 , supportsPkgEnvFiles = ghcv >= [8, 0, 2] -- TODO: check this works in ghcjs
127 , flagWarnMissingHomeModules = ghcv >= [8, 2]
128 , unitIdForExes = ghcv >= [9, 2]
130 where
131 ghcv = versionNumbers ghcver