Skip to content

Commit a66258f

Browse files
committed
Add support for profiled dynamic way
New options for cabal.project and ./Setup interface: * `profiling-shared`: Enable building profiling dynamic way * Passing `--enable-profiling` and `--enable-executable-dynamic` builds profiled dynamic executables. Support for using `profiling-shared` is guarded behind a constraint which ensures you are using `Cabal >= 3.13`. In the cabal file: * `ghc-prof-shared-options`, for passing options when building in profiling dynamic way Other miscellenious fixes and improvements * Some refactoring around ways so that which ways we should build for a library, foreign library and executable is computed by the `buildWays` function (rather than ad-hoc in three different places). * Improved logic for detecting whether a compiler supports compiling a specific way. See functions `profilingVanillaSupported`, `dynamicSupported`, `profilingDynamicSupported` etc These functions report accurate infomation after ghc-9.10.1. * Fixed logic for determining whether to build shared libraries. (see #10050) Now, if you explicitly enable `--*-shared`, then that will always take effect. If it's not specified then `--enable-executable-dynamic` will turn on shared libraries IF `--enable-profiling` is not enabled. * Remove assumption that dynamically linked compilers can build dynamic libraries (they might be cross compilers. * Query the build compiler to determine which library way is necessary to be built for TH support to work. (rather than assume all compilers are dynamically linked) * An extensive test which checks how options for `./Setup` and `cabal-install` are translated into build ways. Fixes #4816, #10049, #10050
1 parent e1f73a4 commit a66258f

File tree

88 files changed

+1491
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1491
-483
lines changed

Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ buildInfoFieldGrammar =
673673
<*> optionsFieldGrammar
674674
<*> profOptionsFieldGrammar
675675
<*> sharedOptionsFieldGrammar
676+
<*> profSharedOptionsFieldGrammar
676677
<*> pure mempty -- static-options ???
677678
<*> prefixedFields "x-" L.customFieldsBI
678679
<*> monoidalFieldAla "build-depends" formatDependencyList L.targetBuildDepends
@@ -738,6 +739,17 @@ sharedOptionsFieldGrammar =
738739
extract :: CompilerFlavor -> ALens' BuildInfo [String]
739740
extract flavor = L.sharedOptions . lookupLens flavor
740741

742+
profSharedOptionsFieldGrammar
743+
:: (FieldGrammar c g, Applicative (g BuildInfo), c (List NoCommaFSep Token' String))
744+
=> g BuildInfo (PerCompilerFlavor [String])
745+
profSharedOptionsFieldGrammar =
746+
PerCompilerFlavor
747+
<$> monoidalFieldAla "ghc-prof-shared-options" (alaList' NoCommaFSep Token') (extract GHC)
748+
<*> monoidalFieldAla "ghcjs-prof-shared-options" (alaList' NoCommaFSep Token') (extract GHCJS)
749+
where
750+
extract :: CompilerFlavor -> ALens' BuildInfo [String]
751+
extract flavor = L.profSharedOptions . lookupLens flavor
752+
741753
lookupLens :: (Functor f, Monoid v) => CompilerFlavor -> LensLike' f (PerCompilerFlavor v) v
742754
lookupLens k f p@(PerCompilerFlavor ghc ghcjs)
743755
| k == GHC = (\n -> PerCompilerFlavor n ghcjs) <$> f ghc

Cabal-syntax/src/Distribution/Types/BuildInfo.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Distribution.Types.BuildInfo
1212
, hcOptions
1313
, hcProfOptions
1414
, hcSharedOptions
15+
, hcProfSharedOptions
1516
, hcStaticOptions
1617
) where
1718

@@ -133,6 +134,7 @@ data BuildInfo = BuildInfo
133134
, options :: PerCompilerFlavor [String]
134135
, profOptions :: PerCompilerFlavor [String]
135136
, sharedOptions :: PerCompilerFlavor [String]
137+
, profSharedOptions :: PerCompilerFlavor [String]
136138
, staticOptions :: PerCompilerFlavor [String]
137139
, customFieldsBI :: [(String, String)]
138140
-- ^ Custom fields starting
@@ -193,6 +195,7 @@ instance Monoid BuildInfo where
193195
, options = mempty
194196
, profOptions = mempty
195197
, sharedOptions = mempty
198+
, profSharedOptions = mempty
196199
, staticOptions = mempty
197200
, customFieldsBI = []
198201
, targetBuildDepends = []
@@ -245,6 +248,7 @@ instance Semigroup BuildInfo where
245248
, options = combine options
246249
, profOptions = combine profOptions
247250
, sharedOptions = combine sharedOptions
251+
, profSharedOptions = combine profSharedOptions
248252
, staticOptions = combine staticOptions
249253
, customFieldsBI = combine customFieldsBI
250254
, targetBuildDepends = combineNub targetBuildDepends
@@ -295,6 +299,9 @@ hcProfOptions = lookupHcOptions profOptions
295299
hcSharedOptions :: CompilerFlavor -> BuildInfo -> [String]
296300
hcSharedOptions = lookupHcOptions sharedOptions
297301

302+
hcProfSharedOptions :: CompilerFlavor -> BuildInfo -> [String]
303+
hcProfSharedOptions = lookupHcOptions profSharedOptions
304+
298305
hcStaticOptions :: CompilerFlavor -> BuildInfo -> [String]
299306
hcStaticOptions = lookupHcOptions staticOptions
300307

Cabal-syntax/src/Distribution/Types/BuildInfo/Lens.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ class HasBuildInfo a where
195195
sharedOptions = buildInfo . sharedOptions
196196
{-# INLINE sharedOptions #-}
197197

198+
profSharedOptions :: Lens' a (PerCompilerFlavor [String])
199+
profSharedOptions = buildInfo . profSharedOptions
200+
{-# INLINE profSharedOptions #-}
201+
198202
staticOptions :: Lens' a (PerCompilerFlavor [String])
199203
staticOptions = buildInfo . staticOptions
200204
{-# INLINE staticOptions #-}
@@ -341,6 +345,9 @@ instance HasBuildInfo BuildInfo where
341345
sharedOptions f s = fmap (\x -> s{T.sharedOptions = x}) (f (T.sharedOptions s))
342346
{-# INLINE sharedOptions #-}
343347

348+
profSharedOptions f s = fmap (\x -> s{T.profSharedOptions = x}) (f (T.profSharedOptions s))
349+
{-# INLINE profSharedOptions #-}
350+
344351
staticOptions f s = fmap (\x -> s{T.staticOptions = x}) (f (T.staticOptions s))
345352
{-# INLINE staticOptions #-}
346353

Cabal-tests/tests/ParserTests/regressions/Octree-0.5.expr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ GenericPackageDescription {
132132
[],
133133
sharedOptions =
134134
PerCompilerFlavor [] [],
135+
profSharedOptions =
136+
PerCompilerFlavor [] [],
135137
staticOptions =
136138
PerCompilerFlavor [] [],
137139
customFieldsBI = [],
@@ -238,6 +240,8 @@ GenericPackageDescription {
238240
[],
239241
sharedOptions =
240242
PerCompilerFlavor [] [],
243+
profSharedOptions =
244+
PerCompilerFlavor [] [],
241245
staticOptions =
242246
PerCompilerFlavor [] [],
243247
customFieldsBI = [],
@@ -339,6 +343,8 @@ GenericPackageDescription {
339343
[],
340344
sharedOptions =
341345
PerCompilerFlavor [] [],
346+
profSharedOptions =
347+
PerCompilerFlavor [] [],
342348
staticOptions =
343349
PerCompilerFlavor [] [],
344350
customFieldsBI = [],

Cabal-tests/tests/ParserTests/regressions/anynone.expr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ GenericPackageDescription {
9595
[],
9696
sharedOptions =
9797
PerCompilerFlavor [] [],
98+
profSharedOptions =
99+
PerCompilerFlavor [] [],
98100
staticOptions =
99101
PerCompilerFlavor [] [],
100102
customFieldsBI = [],

Cabal-tests/tests/ParserTests/regressions/big-version.expr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ GenericPackageDescription {
9696
[],
9797
sharedOptions =
9898
PerCompilerFlavor [] [],
99+
profSharedOptions =
100+
PerCompilerFlavor [] [],
99101
staticOptions =
100102
PerCompilerFlavor [] [],
101103
customFieldsBI = [],

Cabal-tests/tests/ParserTests/regressions/common-conditional.expr

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ GenericPackageDescription {
112112
[],
113113
sharedOptions =
114114
PerCompilerFlavor [] [],
115+
profSharedOptions =
116+
PerCompilerFlavor [] [],
115117
staticOptions =
116118
PerCompilerFlavor [] [],
117119
customFieldsBI = [],
@@ -187,6 +189,8 @@ GenericPackageDescription {
187189
[],
188190
sharedOptions =
189191
PerCompilerFlavor [] [],
192+
profSharedOptions =
193+
PerCompilerFlavor [] [],
190194
staticOptions =
191195
PerCompilerFlavor [] [],
192196
customFieldsBI = [],
@@ -278,6 +282,8 @@ GenericPackageDescription {
278282
[],
279283
sharedOptions =
280284
PerCompilerFlavor [] [],
285+
profSharedOptions =
286+
PerCompilerFlavor [] [],
281287
staticOptions =
282288
PerCompilerFlavor [] [],
283289
customFieldsBI = [],
@@ -356,6 +362,8 @@ GenericPackageDescription {
356362
[],
357363
sharedOptions =
358364
PerCompilerFlavor [] [],
365+
profSharedOptions =
366+
PerCompilerFlavor [] [],
359367
staticOptions =
360368
PerCompilerFlavor [] [],
361369
customFieldsBI = [],
@@ -432,6 +440,8 @@ GenericPackageDescription {
432440
[],
433441
sharedOptions =
434442
PerCompilerFlavor [] [],
443+
profSharedOptions =
444+
PerCompilerFlavor [] [],
435445
staticOptions =
436446
PerCompilerFlavor [] [],
437447
customFieldsBI = [],
@@ -501,6 +511,8 @@ GenericPackageDescription {
501511
[],
502512
sharedOptions =
503513
PerCompilerFlavor [] [],
514+
profSharedOptions =
515+
PerCompilerFlavor [] [],
504516
staticOptions =
505517
PerCompilerFlavor [] [],
506518
customFieldsBI = [],
@@ -593,6 +605,8 @@ GenericPackageDescription {
593605
[],
594606
sharedOptions =
595607
PerCompilerFlavor [] [],
608+
profSharedOptions =
609+
PerCompilerFlavor [] [],
596610
staticOptions =
597611
PerCompilerFlavor [] [],
598612
customFieldsBI = [],
@@ -670,6 +684,8 @@ GenericPackageDescription {
670684
[],
671685
sharedOptions =
672686
PerCompilerFlavor [] [],
687+
profSharedOptions =
688+
PerCompilerFlavor [] [],
673689
staticOptions =
674690
PerCompilerFlavor [] [],
675691
customFieldsBI = [],

Cabal-tests/tests/ParserTests/regressions/common.expr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ GenericPackageDescription {
110110
[],
111111
sharedOptions =
112112
PerCompilerFlavor [] [],
113+
profSharedOptions =
114+
PerCompilerFlavor [] [],
113115
staticOptions =
114116
PerCompilerFlavor [] [],
115117
customFieldsBI = [],
@@ -186,6 +188,8 @@ GenericPackageDescription {
186188
[],
187189
sharedOptions =
188190
PerCompilerFlavor [] [],
191+
profSharedOptions =
192+
PerCompilerFlavor [] [],
189193
staticOptions =
190194
PerCompilerFlavor [] [],
191195
customFieldsBI = [],

Cabal-tests/tests/ParserTests/regressions/common2.expr

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ GenericPackageDescription {
106106
[],
107107
sharedOptions =
108108
PerCompilerFlavor [] [],
109+
profSharedOptions =
110+
PerCompilerFlavor [] [],
109111
staticOptions =
110112
PerCompilerFlavor [] [],
111113
customFieldsBI = [],
@@ -205,6 +207,8 @@ GenericPackageDescription {
205207
[],
206208
sharedOptions =
207209
PerCompilerFlavor [] [],
210+
profSharedOptions =
211+
PerCompilerFlavor [] [],
208212
staticOptions =
209213
PerCompilerFlavor [] [],
210214
customFieldsBI = [],
@@ -285,6 +289,8 @@ GenericPackageDescription {
285289
[],
286290
sharedOptions =
287291
PerCompilerFlavor [] [],
292+
profSharedOptions =
293+
PerCompilerFlavor [] [],
288294
staticOptions =
289295
PerCompilerFlavor [] [],
290296
customFieldsBI = [],
@@ -386,6 +392,8 @@ GenericPackageDescription {
386392
[],
387393
sharedOptions =
388394
PerCompilerFlavor [] [],
395+
profSharedOptions =
396+
PerCompilerFlavor [] [],
389397
staticOptions =
390398
PerCompilerFlavor [] [],
391399
customFieldsBI = [],
@@ -462,6 +470,8 @@ GenericPackageDescription {
462470
[],
463471
sharedOptions =
464472
PerCompilerFlavor [] [],
473+
profSharedOptions =
474+
PerCompilerFlavor [] [],
465475
staticOptions =
466476
PerCompilerFlavor [] [],
467477
customFieldsBI = [],
@@ -562,6 +572,8 @@ GenericPackageDescription {
562572
[],
563573
sharedOptions =
564574
PerCompilerFlavor [] [],
575+
profSharedOptions =
576+
PerCompilerFlavor [] [],
565577
staticOptions =
566578
PerCompilerFlavor [] [],
567579
customFieldsBI = [],
@@ -639,6 +651,8 @@ GenericPackageDescription {
639651
[],
640652
sharedOptions =
641653
PerCompilerFlavor [] [],
654+
profSharedOptions =
655+
PerCompilerFlavor [] [],
642656
staticOptions =
643657
PerCompilerFlavor [] [],
644658
customFieldsBI = [],
@@ -716,6 +730,8 @@ GenericPackageDescription {
716730
[],
717731
sharedOptions =
718732
PerCompilerFlavor [] [],
733+
profSharedOptions =
734+
PerCompilerFlavor [] [],
719735
staticOptions =
720736
PerCompilerFlavor [] [],
721737
customFieldsBI = [],

Cabal-tests/tests/ParserTests/regressions/common3.expr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ GenericPackageDescription {
110110
[],
111111
sharedOptions =
112112
PerCompilerFlavor [] [],
113+
profSharedOptions =
114+
PerCompilerFlavor [] [],
113115
staticOptions =
114116
PerCompilerFlavor [] [],
115117
customFieldsBI = [],
@@ -186,6 +188,8 @@ GenericPackageDescription {
186188
[],
187189
sharedOptions =
188190
PerCompilerFlavor [] [],
191+
profSharedOptions =
192+
PerCompilerFlavor [] [],
189193
staticOptions =
190194
PerCompilerFlavor [] [],
191195
customFieldsBI = [],

0 commit comments

Comments
 (0)