Support GHC 9.12
[cabal.git] / Cabal / src / Distribution / Types / LocalBuildConfig.hs
blob4423a77410d12054ce5b50e25a257fc7e39c5a81
1 {-# LANGUAGE DeriveGeneric #-}
2 {-# LANGUAGE DuplicateRecordFields #-}
3 {-# LANGUAGE FlexibleContexts #-}
4 {-# LANGUAGE NamedFieldPuns #-}
5 {-# LANGUAGE PatternSynonyms #-}
6 {-# LANGUAGE RankNTypes #-}
7 {-# LANGUAGE RecordWildCards #-}
9 module Distribution.Types.LocalBuildConfig
10 ( -- * The types
11 PackageBuildDescr (..)
12 , ComponentBuildDescr (..)
13 , LocalBuildDescr (..)
14 , LocalBuildConfig (..)
15 , BuildOptions (..)
17 -- * Conversion functions
18 , buildOptionsConfigFlags
19 ) where
21 import Distribution.Compat.Prelude
22 import Prelude ()
24 import Distribution.Types.ComponentId
25 import Distribution.Types.ComponentLocalBuildInfo
26 import Distribution.Types.ComponentRequestedSpec
27 import Distribution.Types.PackageDescription
28 import Distribution.Types.UnitId
30 import Distribution.PackageDescription
31 import Distribution.Simple.Compiler
32 import Distribution.Simple.Flag
33 import Distribution.Simple.InstallDirs hiding
34 ( absoluteInstallDirs
35 , prefixRelativeInstallDirs
36 , substPathTemplate
38 import Distribution.Simple.PackageIndex
39 import Distribution.Simple.Program
40 import Distribution.Simple.Setup.Config
41 import Distribution.System
43 import Distribution.Compat.Graph (Graph)
45 -- | 'PackageBuildDescr' contains the information Cabal determines after
46 -- performing package-wide configuration of a package, before doing any
47 -- per-component configuration.
48 data PackageBuildDescr = PackageBuildDescr
49 { configFlags :: ConfigFlags
50 -- ^ Options passed to the configuration step.
51 -- Needed to re-run configuration when .cabal is out of date
52 , flagAssignment :: FlagAssignment
53 -- ^ The final set of flags which were picked for this package
54 , componentEnabledSpec :: ComponentRequestedSpec
55 -- ^ What components were enabled during configuration, and why.
56 , compiler :: Compiler
57 -- ^ The compiler we're building with
58 , hostPlatform :: Platform
59 -- ^ The platform we're building for
60 , pkgDescrFile :: Maybe FilePath
61 -- ^ the filename containing the .cabal file, if available
62 , localPkgDescr :: PackageDescription
63 -- ^ WARNING WARNING WARNING Be VERY careful about using
64 -- this function; we haven't deprecated it but using it
65 -- could introduce subtle bugs related to
66 -- 'HookedBuildInfo'.
68 -- In principle, this is supposed to contain the
69 -- resolved package description, that does not contain
70 -- any conditionals. However, it MAY NOT contain
71 -- the description with a 'HookedBuildInfo' applied
72 -- to it; see 'HookedBuildInfo' for the whole sordid saga.
73 -- As much as possible, Cabal library should avoid using
74 -- this parameter.
75 , installDirTemplates :: InstallDirTemplates
76 -- ^ The installation directories for the various different
77 -- kinds of files
78 -- TODO: inplaceDirTemplates :: InstallDirs FilePath
79 , withPackageDB :: PackageDBStack
80 -- ^ What package database to use, global\/user
81 , extraCoverageFor :: [UnitId]
82 -- ^ For per-package builds-only: an extra list of libraries to be included in
83 -- the hpc coverage report for testsuites run with @--enable-coverage@.
84 -- Notably, this list must exclude indefinite libraries and instantiations
85 -- because HPC does not support backpack (Nov. 2023).
87 deriving (Generic, Read, Show)
89 -- | Information about individual components in a package,
90 -- determined after the configure step.
91 data ComponentBuildDescr = ComponentBuildDescr
92 { componentGraph :: Graph ComponentLocalBuildInfo
93 -- ^ All the components to build, ordered by topological
94 -- sort, and with their INTERNAL dependencies over the
95 -- intrapackage dependency graph.
96 -- TODO: this is assumed to be short; otherwise we want
97 -- some sort of ordered map.
98 , componentNameMap :: Map ComponentName [ComponentLocalBuildInfo]
99 -- ^ A map from component name to all matching
100 -- components. These coincide with 'componentGraph'
101 -- There may be more than one matching component because of backpack instantiations
102 , promisedPkgs :: Map (PackageName, ComponentName) ComponentId
103 -- ^ The packages we were promised, but aren't already installed.
104 -- MP: Perhaps this just needs to be a Set UnitId at this stage.
105 , installedPkgs :: InstalledPackageIndex
106 -- ^ All the info about the installed packages that the
107 -- current package depends on (directly or indirectly).
108 -- The copy saved on disk does NOT include internal
109 -- dependencies (because we just don't have enough
110 -- information at this point to have an
111 -- 'InstalledPackageInfo' for an internal dep), but we
112 -- will often update it with the internal dependencies;
113 -- see for example 'Distribution.Simple.Build.build'.
114 -- (This admonition doesn't apply for per-component builds.)
116 deriving (Generic, Read, Show)
118 -- | 'LocalBuildDescr ' contains the information Cabal determines after
119 -- performing package-wide and per-component configuration of a package.
121 -- This information can no longer be changed after that point.
122 data LocalBuildDescr = LocalBuildDescr
123 { packageBuildDescr :: PackageBuildDescr
124 -- ^ Information that is available after configuring the package itself,
125 -- before looking at individual components.
126 , componentBuildDescr :: ComponentBuildDescr
127 -- ^ Information about individual components in the package
128 -- determined after the configure step.
130 deriving (Generic, Read, Show)
132 -- | 'LocalBuildConfig' contains options that can be controlled
133 -- by the user and serve as inputs to the configuration of a package.
134 data LocalBuildConfig = LocalBuildConfig
135 { extraConfigArgs :: [String]
136 -- ^ Extra args on the command line for the configuration step.
137 -- Needed to re-run configuration when .cabal is out of date
138 , withPrograms :: ProgramDb
139 -- ^ Location and args for all programs
140 , withBuildOptions :: BuildOptions
141 -- ^ Options to control the build, e.g. whether to
142 -- enable profiling or to enable program coverage.
144 deriving (Generic, Read, Show)
146 -- | 'BuildOptions' contains configuration options that can be controlled
147 -- by the user.
148 data BuildOptions = BuildOptions
149 { withVanillaLib :: Bool
150 -- ^ Whether to build normal libs.
151 , withProfLib :: Bool
152 -- ^ Whether to build profiling versions of libs.
153 , withSharedLib :: Bool
154 -- ^ Whether to build shared versions of libs.
155 , withStaticLib :: Bool
156 -- ^ Whether to build static versions of libs (with all other libs rolled in)
157 , withDynExe :: Bool
158 -- ^ Whether to link executables dynamically
159 , withFullyStaticExe :: Bool
160 -- ^ Whether to link executables fully statically
161 , withProfExe :: Bool
162 -- ^ Whether to build executables for profiling.
163 , withProfLibDetail :: ProfDetailLevel
164 -- ^ Level of automatic profile detail.
165 , withProfExeDetail :: ProfDetailLevel
166 -- ^ Level of automatic profile detail.
167 , withOptimization :: OptimisationLevel
168 -- ^ Whether to build with optimization (if available).
169 , withDebugInfo :: DebugInfoLevel
170 -- ^ Whether to emit debug info (if available).
171 , withGHCiLib :: Bool
172 -- ^ Whether to build libs suitable for use with GHCi.
173 , splitSections :: Bool
174 -- ^ Use -split-sections with GHC, if available
175 , splitObjs :: Bool
176 -- ^ Use -split-objs with GHC, if available
177 , stripExes :: Bool
178 -- ^ Whether to strip executables during install
179 , stripLibs :: Bool
180 -- ^ Whether to strip libraries during install
181 , exeCoverage :: Bool
182 -- ^ Whether to enable executable program coverage
183 , libCoverage :: Bool
184 -- ^ Whether to enable library program coverage
185 , relocatable :: Bool
186 -- ^ Whether to build a relocatable package
188 deriving (Eq, Generic, Read, Show)
190 instance Binary PackageBuildDescr
191 instance Structured PackageBuildDescr
192 instance Binary ComponentBuildDescr
193 instance Structured ComponentBuildDescr
194 instance Binary LocalBuildDescr
195 instance Structured LocalBuildDescr
196 instance Binary LocalBuildConfig
197 instance Structured LocalBuildConfig
198 instance Binary BuildOptions
199 instance Structured BuildOptions
201 buildOptionsConfigFlags :: BuildOptions -> ConfigFlags
202 buildOptionsConfigFlags (BuildOptions{..}) =
203 mempty
204 { configVanillaLib = toFlag $ withVanillaLib
205 , configSharedLib = toFlag $ withSharedLib
206 , configStaticLib = toFlag $ withStaticLib
207 , configDynExe = toFlag $ withDynExe
208 , configFullyStaticExe = toFlag $ withFullyStaticExe
209 , configGHCiLib = toFlag $ withGHCiLib
210 , configProfExe = toFlag $ withProfExe
211 , configProfLib = toFlag $ withProfLib
212 , configProf = mempty
213 , -- configProfDetail is for exe+lib, but overridden by configProfLibDetail
214 -- so we specify both so we can specify independently
215 configProfDetail = toFlag $ withProfExeDetail
216 , configProfLibDetail = toFlag $ withProfLibDetail
217 , configCoverage = toFlag $ exeCoverage
218 , configLibCoverage = mempty
219 , configRelocatable = toFlag $ relocatable
220 , configOptimization = toFlag $ withOptimization
221 , configSplitSections = toFlag $ splitSections
222 , configSplitObjs = toFlag $ splitObjs
223 , configStripExes = toFlag $ stripExes
224 , configStripLibs = toFlag $ stripLibs
225 , configDebugInfo = toFlag $ withDebugInfo