Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for building profiled dynamic way #9900

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 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,19 @@ 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)
mpickering marked this conversation as resolved.
Show resolved Hide resolved
^^^ availableSince CabalSpecV3_14 []
<*> monoidalFieldAla "ghcjs-prof-shared-options" (alaList' NoCommaFSep Token') (extract GHCJS)
mpickering marked this conversation as resolved.
Show resolved Hide resolved
^^^ availableSince CabalSpecV3_14 []
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
Loading