Skip to content

Commit

Permalink
Add support for profiled dynamic way
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mpickering committed Jun 18, 2024
1 parent e1f73a4 commit 353881c
Show file tree
Hide file tree
Showing 88 changed files with 1,494 additions and 483 deletions.
12 changes: 12 additions & 0 deletions Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ buildInfoFieldGrammar =
<*> optionsFieldGrammar
<*> profOptionsFieldGrammar
<*> sharedOptionsFieldGrammar
<*> profSharedOptionsFieldGrammar
<*> pure mempty -- static-options ???
<*> prefixedFields "x-" L.customFieldsBI
<*> monoidalFieldAla "build-depends" formatDependencyList L.targetBuildDepends
Expand Down Expand Up @@ -738,6 +739,17 @@ sharedOptionsFieldGrammar =
extract :: CompilerFlavor -> ALens' BuildInfo [String]
extract flavor = L.sharedOptions . lookupLens flavor

profSharedOptionsFieldGrammar
:: (FieldGrammar c g, Applicative (g BuildInfo), c (List NoCommaFSep Token' String))
=> g BuildInfo (PerCompilerFlavor [String])
profSharedOptionsFieldGrammar =
PerCompilerFlavor
<$> monoidalFieldAla "ghc-prof-shared-options" (alaList' NoCommaFSep Token') (extract GHC)
<*> monoidalFieldAla "ghcjs-prof-shared-options" (alaList' NoCommaFSep Token') (extract GHCJS)
where
extract :: CompilerFlavor -> ALens' BuildInfo [String]
extract flavor = L.profSharedOptions . lookupLens flavor

lookupLens :: (Functor f, Monoid v) => CompilerFlavor -> LensLike' f (PerCompilerFlavor v) v
lookupLens k f p@(PerCompilerFlavor ghc ghcjs)
| k == GHC = (\n -> PerCompilerFlavor n ghcjs) <$> f ghc
Expand Down
7 changes: 7 additions & 0 deletions Cabal-syntax/src/Distribution/Types/BuildInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Distribution.Types.BuildInfo
, hcOptions
, hcProfOptions
, hcSharedOptions
, hcProfSharedOptions
, hcStaticOptions
) where

Expand Down Expand Up @@ -133,6 +134,7 @@ data BuildInfo = BuildInfo
, options :: PerCompilerFlavor [String]
, profOptions :: PerCompilerFlavor [String]
, sharedOptions :: PerCompilerFlavor [String]
, profSharedOptions :: PerCompilerFlavor [String]
, staticOptions :: PerCompilerFlavor [String]
, customFieldsBI :: [(String, String)]
-- ^ Custom fields starting
Expand Down Expand Up @@ -193,6 +195,7 @@ instance Monoid BuildInfo where
, options = mempty
, profOptions = mempty
, sharedOptions = mempty
, profSharedOptions = mempty
, staticOptions = mempty
, customFieldsBI = []
, targetBuildDepends = []
Expand Down Expand Up @@ -245,6 +248,7 @@ instance Semigroup BuildInfo where
, options = combine options
, profOptions = combine profOptions
, sharedOptions = combine sharedOptions
, profSharedOptions = combine profSharedOptions
, staticOptions = combine staticOptions
, customFieldsBI = combine customFieldsBI
, targetBuildDepends = combineNub targetBuildDepends
Expand Down Expand Up @@ -295,6 +299,9 @@ hcProfOptions = lookupHcOptions profOptions
hcSharedOptions :: CompilerFlavor -> BuildInfo -> [String]
hcSharedOptions = lookupHcOptions sharedOptions

hcProfSharedOptions :: CompilerFlavor -> BuildInfo -> [String]
hcProfSharedOptions = lookupHcOptions profSharedOptions

hcStaticOptions :: CompilerFlavor -> BuildInfo -> [String]
hcStaticOptions = lookupHcOptions staticOptions

Expand Down
7 changes: 7 additions & 0 deletions Cabal-syntax/src/Distribution/Types/BuildInfo/Lens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ class HasBuildInfo a where
sharedOptions = buildInfo . sharedOptions
{-# INLINE sharedOptions #-}

profSharedOptions :: Lens' a (PerCompilerFlavor [String])
profSharedOptions = buildInfo . profSharedOptions
{-# INLINE profSharedOptions #-}

staticOptions :: Lens' a (PerCompilerFlavor [String])
staticOptions = buildInfo . staticOptions
{-# INLINE staticOptions #-}
Expand Down Expand Up @@ -341,6 +345,9 @@ instance HasBuildInfo BuildInfo where
sharedOptions f s = fmap (\x -> s{T.sharedOptions = x}) (f (T.sharedOptions s))
{-# INLINE sharedOptions #-}

profSharedOptions f s = fmap (\x -> s{T.profSharedOptions = x}) (f (T.profSharedOptions s))
{-# INLINE profSharedOptions #-}

staticOptions f s = fmap (\x -> s{T.staticOptions = x}) (f (T.staticOptions s))
{-# INLINE staticOptions #-}

Expand Down
6 changes: 6 additions & 0 deletions Cabal-tests/tests/ParserTests/regressions/Octree-0.5.expr
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -238,6 +240,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -339,6 +343,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down
2 changes: 2 additions & 0 deletions Cabal-tests/tests/ParserTests/regressions/anynone.expr
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down
2 changes: 2 additions & 0 deletions Cabal-tests/tests/ParserTests/regressions/big-version.expr
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down
16 changes: 16 additions & 0 deletions Cabal-tests/tests/ParserTests/regressions/common-conditional.expr
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -187,6 +189,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -278,6 +282,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -356,6 +362,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -432,6 +440,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -501,6 +511,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -593,6 +605,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -670,6 +684,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down
4 changes: 4 additions & 0 deletions Cabal-tests/tests/ParserTests/regressions/common.expr
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -186,6 +188,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down
16 changes: 16 additions & 0 deletions Cabal-tests/tests/ParserTests/regressions/common2.expr
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -205,6 +207,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -285,6 +289,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -386,6 +392,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -462,6 +470,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -562,6 +572,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -639,6 +651,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -716,6 +730,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down
4 changes: 4 additions & 0 deletions Cabal-tests/tests/ParserTests/regressions/common3.expr
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -186,6 +188,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down
4 changes: 4 additions & 0 deletions Cabal-tests/tests/ParserTests/regressions/elif.expr
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -172,6 +174,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down
10 changes: 10 additions & 0 deletions Cabal-tests/tests/ParserTests/regressions/elif2.expr
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -172,6 +174,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -245,6 +249,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -312,6 +318,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down Expand Up @@ -385,6 +393,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down
2 changes: 2 additions & 0 deletions Cabal-tests/tests/ParserTests/regressions/encoding-0.8.expr
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ GenericPackageDescription {
[],
sharedOptions =
PerCompilerFlavor [] [],
profSharedOptions =
PerCompilerFlavor [] [],
staticOptions =
PerCompilerFlavor [] [],
customFieldsBI = [],
Expand Down
Loading

0 comments on commit 353881c

Please sign in to comment.