Skip to content

Commit f8508f7

Browse files
committed
Pass *-options and -pgmc to GHC
Refactor componentGhcOptions for pass *-options to all invoking GHC. During the refactoring process we needed to add componentGhcOptions to all Haskell sources. It was also worth add linkGhcOptions to linkLibrary same as componentGhcOptions to linkExecutable, linkFLib. Add test for PackageTests/FFI/ForeignOptsCapi to pass cc-options flags to *.h. Add -pgmc gcc to componentGhcOptions for versions newer then 9.4. Add more tests like PackageTests/ShowBuildInfo/Complex for -pgmc gcc and -optc-O2,-optcxx-O2,-opta-O2. Move PackageTests/Cmm* to PackageTests/Cmm/*. Fixes #9801 #4435
1 parent 25e87fd commit f8508f7

Some content is hidden

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

56 files changed

+980
-310
lines changed

Cabal/src/Distribution/Simple/GHC.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ module Distribution.Simple.GHC
6060
, hcPkgInfo
6161
, registerPackage
6262
, Internal.componentGhcOptions
63-
, Internal.componentCcGhcOptions
6463
, getGhcAppDir
6564
, getLibDir
6665
, compilerBuildWay
@@ -801,7 +800,7 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
801800
, ghcOptFPic = toFlag True
802801
, ghcOptHiSuffix = toFlag "dyn_hi"
803802
, ghcOptObjSuffix = toFlag "dyn_o"
804-
, ghcOptExtra = hcOptions GHC libBi ++ hcSharedOptions GHC libBi
803+
, ghcOptExtra = hcSharedOptions GHC libBi
805804
}
806805
profArgs =
807806
vanillaArgs
@@ -813,7 +812,7 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
813812
(withProfLibDetail lbi)
814813
, ghcOptHiSuffix = toFlag "p_hi"
815814
, ghcOptObjSuffix = toFlag "p_o"
816-
, ghcOptExtra = hcOptions GHC libBi ++ hcProfOptions GHC libBi
815+
, ghcOptExtra = hcProfOptions GHC libBi
817816
}
818817
profDynArgs =
819818
vanillaArgs
@@ -827,7 +826,7 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
827826
, ghcOptFPic = toFlag True
828827
, ghcOptHiSuffix = toFlag "p_dyn_hi"
829828
, ghcOptObjSuffix = toFlag "p_dyn_o"
830-
, ghcOptExtra = hcOptions GHC libBi ++ hcProfSharedOptions GHC libBi
829+
, ghcOptExtra = hcProfSharedOptions GHC libBi
831830
}
832831
ghcArgs =
833832
let (libWays, _, _) = buildWays lbi

Cabal/src/Distribution/Simple/GHC/Build/ExtraSources.hs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import Distribution.Utils.NubList
1717
import Distribution.Types.BuildInfo
1818
import Distribution.Types.Component
1919
import Distribution.Types.TargetInfo
20+
import Distribution.Types.Version
2021

2122
import Distribution.Simple.Build.Inputs
22-
import Distribution.Simple.GHC.Build.Modules
23+
import Distribution.Simple.BuildWay
2324
import Distribution.Simple.GHC.Build.Utils
2425
import Distribution.Simple.LocalBuildInfo
2526
import Distribution.Simple.Program.Types
@@ -73,7 +74,23 @@ buildCSources
7374
buildCSources mbMainFile =
7475
buildExtraSources
7576
"C Sources"
76-
Internal.componentCcGhcOptions
77+
( \verbosity lbi bi clbi odir filename ->
78+
(Internal.sourcesGhcOptions verbosity lbi bi clbi odir filename)
79+
{ -- C++ compiler options: GHC >= 8.10 requires -optcxx, older requires -optc
80+
-- we want to be able to support cxx-options and cc-options separately
81+
-- https://gitlab.haskell.org/ghc/ghc/-/issues/16477
82+
-- see example in cabal-testsuite/PackageTests/FFI/ForeignOptsC
83+
ghcOptCxxOptions =
84+
Internal.separateGhcOptions
85+
(mkVersion [8, 10])
86+
(compiler lbi)
87+
(Internal.defaultGhcOptCxxOptions lbi bi)
88+
, -- there are problems with linking with versions below 9.4,
89+
-- that's why we need this replacement for linkGhcOptions
90+
-- see example in cabal-testsuite/PackageTests/ShowBuildInfo/Complex
91+
ghcOptCcProgram = Internal.defaultGhcOptCcProgram lbi
92+
}
93+
)
7794
( \c -> do
7895
let cFiles = cSources (componentBuildInfo c)
7996
case c of
@@ -86,7 +103,23 @@ buildCSources mbMainFile =
86103
buildCxxSources mbMainFile =
87104
buildExtraSources
88105
"C++ Sources"
89-
Internal.componentCxxGhcOptions
106+
( \verbosity lbi bi clbi odir filename ->
107+
(Internal.sourcesGhcOptions verbosity lbi bi clbi odir filename)
108+
{ -- C++ compiler options: GHC >= 8.10 requires -optcxx, older requires -optc
109+
-- we want to be able to support cxx-options and cc-options separately
110+
-- https://gitlab.haskell.org/ghc/ghc/-/issues/16477
111+
-- see example in cabal-testsuite/PackageTests/FFI/ForeignOptsCxx
112+
ghcOptCcOptions =
113+
Internal.separateGhcOptions
114+
(mkVersion [8, 10])
115+
(compiler lbi)
116+
(Internal.defaultGhcOptCcOptions lbi bi)
117+
, -- there are problems with linking with versions below 9.4,
118+
-- that's why we need this replacement for linkGhcOptions
119+
-- see example in cabal-testsuite/PackageTests/ShowBuildInfo/Complex
120+
ghcOptCcProgram = Internal.defaultGhcOptCcProgram lbi
121+
}
122+
)
90123
( \c -> do
91124
let cxxFiles = cxxSources (componentBuildInfo c)
92125
case c of
@@ -101,7 +134,7 @@ buildJsSources _mbMainFile ghcProg buildTargetDir neededWays = do
101134
let hasJsSupport = hostArch == JavaScript
102135
buildExtraSources
103136
"JS Sources"
104-
Internal.componentJsGhcOptions
137+
Internal.sourcesGhcOptions
105138
( \c ->
106139
if hasJsSupport
107140
then -- JS files are C-like with GHC's JS backend: they are
@@ -117,12 +150,12 @@ buildJsSources _mbMainFile ghcProg buildTargetDir neededWays = do
117150
buildAsmSources _mbMainFile =
118151
buildExtraSources
119152
"Assembler Sources"
120-
Internal.componentAsmGhcOptions
153+
Internal.sourcesGhcOptions
121154
(asmSources . componentBuildInfo)
122155
buildCmmSources _mbMainFile =
123156
buildExtraSources
124157
"C-- Sources"
125-
Internal.componentCmmGhcOptions
158+
Internal.sourcesGhcOptions
126159
(cmmSources . componentBuildInfo)
127160

128161
-- | Create 'PreBuildComponentRules' for a given type of extra build sources
@@ -140,9 +173,7 @@ buildExtraSources
140173
-> GhcOptions
141174
)
142175
-- ^ Function to determine the @'GhcOptions'@ for the
143-
-- invocation of GHC when compiling these extra sources (e.g.
144-
-- @'Internal.componentCxxGhcOptions'@,
145-
-- @'Internal.componentCmmGhcOptions'@)
176+
-- invocation of GHC when compiling these extra sources
146177
-> (Component -> [SymbolicPath Pkg File])
147178
-- ^ View the extra sources of a component, typically from
148179
-- the build info (e.g. @'asmSources'@, @'cSources'@).

Cabal/src/Distribution/Simple/GHC/Build/Link.hs

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,9 @@ linkOrLoadComponent
121121
linkerOpts rpaths =
122122
mempty
123123
{ ghcOptLinkOptions =
124-
PD.ldOptions bi
125-
++ [ "-static"
126-
| withFullyStaticExe lbi
127-
]
124+
[ "-static"
125+
| withFullyStaticExe lbi
126+
]
128127
-- Pass extra `ld-options` given
129128
-- through to GHC's linker.
130129
++ maybe
@@ -344,36 +343,11 @@ linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg li
344343
--
345344
-- Right now, instead, we pass the path to each object file.
346345
ghcBaseLinkArgs =
347-
mempty
348-
{ -- TODO: This basically duplicates componentGhcOptions.
349-
-- I think we want to do the same as we do for executables: re-use the
350-
-- base options, and link by module names, not object paths.
351-
ghcOptExtra = hcStaticOptions GHC libBi
352-
, ghcOptHideAllPackages = toFlag True
353-
, ghcOptNoAutoLinkPackages = toFlag True
354-
, ghcOptPackageDBs = withPackageDB lbi
355-
, ghcOptThisUnitId = case clbi of
356-
LibComponentLocalBuildInfo{componentCompatPackageKey = pk} ->
357-
toFlag pk
358-
_ -> mempty
359-
, ghcOptThisComponentId = case clbi of
360-
LibComponentLocalBuildInfo
361-
{ componentInstantiatedWith = insts
362-
} ->
363-
if null insts
364-
then mempty
365-
else toFlag (componentComponentId clbi)
366-
_ -> mempty
367-
, ghcOptInstantiatedWith = case clbi of
368-
LibComponentLocalBuildInfo
369-
{ componentInstantiatedWith = insts
370-
} ->
371-
insts
372-
_ -> []
373-
, ghcOptPackages =
374-
toNubListR $
375-
Internal.mkGhcOptPackages mempty clbi
376-
}
346+
Internal.linkGhcOptions verbosity lbi libBi clbi
347+
<> mempty
348+
{ ghcOptExtra = hcStaticOptions GHC libBi
349+
, ghcOptNoAutoLinkPackages = toFlag True
350+
}
377351

378352
-- After the relocation lib is created we invoke ghc -shared
379353
-- with the dependencies spelled out as -package arguments

0 commit comments

Comments
 (0)