Skip to content

Cabal doesn't pass *-options to GHC when compiling ordinary Haskell sources #10969

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 3 additions & 4 deletions Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ module Distribution.Simple.GHC
, hcPkgInfo
, registerPackage
, Internal.componentGhcOptions
, Internal.componentCcGhcOptions
, getGhcAppDir
, getLibDir
, compilerBuildWay
Expand Down Expand Up @@ -744,7 +743,7 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
, ghcOptFPic = toFlag True
, ghcOptHiSuffix = toFlag "dyn_hi"
, ghcOptObjSuffix = toFlag "dyn_o"
, ghcOptExtra = hcOptions GHC libBi ++ hcSharedOptions GHC libBi
, ghcOptExtra = hcSharedOptions GHC libBi
}
profArgs =
vanillaArgs
Expand All @@ -756,7 +755,7 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
(withProfLibDetail lbi)
, ghcOptHiSuffix = toFlag "p_hi"
, ghcOptObjSuffix = toFlag "p_o"
, ghcOptExtra = hcOptions GHC libBi ++ hcProfOptions GHC libBi
, ghcOptExtra = hcProfOptions GHC libBi
}
profDynArgs =
vanillaArgs
Expand All @@ -770,7 +769,7 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
, ghcOptFPic = toFlag True
, ghcOptHiSuffix = toFlag "p_dyn_hi"
, ghcOptObjSuffix = toFlag "p_dyn_o"
, ghcOptExtra = hcOptions GHC libBi ++ hcProfSharedOptions GHC libBi
, ghcOptExtra = hcProfSharedOptions GHC libBi
}
ghcArgs =
let (libWays, _, _) = buildWays lbi
Expand Down
37 changes: 25 additions & 12 deletions Cabal/src/Distribution/Simple/GHC/Build/ExtraSources.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import Distribution.Utils.NubList
import Distribution.Types.BuildInfo
import Distribution.Types.Component
import Distribution.Types.TargetInfo
import Distribution.Types.Version

import Distribution.Simple.Build.Inputs
import Distribution.Simple.GHC.Build.Modules
import Distribution.Simple.BuildWay
import Distribution.Simple.GHC.Build.Utils
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program.Types
Expand Down Expand Up @@ -73,7 +74,15 @@ buildCSources
buildCSources mbMainFile =
buildExtraSources
"C Sources"
Internal.componentCcGhcOptions
( \verbosity lbi bi clbi odir filename ->
(Internal.sourcesGhcOptions verbosity lbi bi clbi odir filename)
{ -- C++ compiler options: GHC >= 8.10 requires -optcxx, older requires -optc
-- we want to be able to support cxx-options and cc-options separately
ghcOptCxxOptions = Internal.separateGhcOptions (mkVersion [8, 10]) (compiler lbi) (Internal.defaultGhcOptCxxOptions lbi bi)
, -- there are problems with linking with versions lower than 9.4, that's why we need this duplication
ghcOptCcProgram = Internal.defaultGhcOptCcProgram lbi
}
)
( \c -> do
let cFiles = cSources (componentBuildInfo c)
case c of
Expand All @@ -86,7 +95,15 @@ buildCSources mbMainFile =
buildCxxSources mbMainFile =
buildExtraSources
"C++ Sources"
Internal.componentCxxGhcOptions
( \verbosity lbi bi clbi odir filename ->
(Internal.sourcesGhcOptions verbosity lbi bi clbi odir filename)
{ -- C++ compiler options: GHC >= 8.10 requires -optcxx, older requires -optc
-- we want to be able to support cxx-options and cc-options separately
ghcOptCcOptions = Internal.separateGhcOptions (mkVersion [8, 10]) (compiler lbi) (Internal.defaultGhcOptCcOptions lbi bi)
, -- there are problems with linking with versions lower than 9.4, that's why we need this duplication
ghcOptCcProgram = Internal.defaultGhcOptCcProgram lbi
}
)
( \c -> do
let cxxFiles = cxxSources (componentBuildInfo c)
case c of
Expand All @@ -101,7 +118,7 @@ buildJsSources _mbMainFile ghcProg buildTargetDir neededWays = do
let hasJsSupport = hostArch == JavaScript
buildExtraSources
"JS Sources"
Internal.componentJsGhcOptions
Internal.sourcesGhcOptions
( \c ->
if hasJsSupport
then -- JS files are C-like with GHC's JS backend: they are
Expand All @@ -117,12 +134,12 @@ buildJsSources _mbMainFile ghcProg buildTargetDir neededWays = do
buildAsmSources _mbMainFile =
buildExtraSources
"Assembler Sources"
Internal.componentAsmGhcOptions
Internal.sourcesGhcOptions
(asmSources . componentBuildInfo)
buildCmmSources _mbMainFile =
buildExtraSources
"C-- Sources"
Internal.componentCmmGhcOptions
Internal.sourcesGhcOptions
(cmmSources . componentBuildInfo)

-- | Create 'PreBuildComponentRules' for a given type of extra build sources
Expand All @@ -140,9 +157,7 @@ buildExtraSources
-> GhcOptions
)
-- ^ Function to determine the @'GhcOptions'@ for the
-- invocation of GHC when compiling these extra sources (e.g.
-- @'Internal.componentCxxGhcOptions'@,
-- @'Internal.componentCmmGhcOptions'@)
-- invocation of GHC when compiling these extra sources
-> (Component -> [SymbolicPath Pkg File])
-- ^ View the extra sources of a component, typically from
-- the build info (e.g. @'asmSources'@, @'cSources'@).
Expand Down Expand Up @@ -211,14 +226,12 @@ buildExtraSources
sharedSrcOpts =
vanillaSrcOpts
`mappend` mempty
{ ghcOptFPic = toFlag True
, ghcOptDynLinkMode = toFlag GhcDynamicOnly
{ ghcOptDynLinkMode = toFlag GhcDynamicOnly
}
profSharedSrcOpts =
vanillaSrcOpts
`mappend` mempty
{ ghcOptProfilingMode = toFlag True
, ghcOptFPic = toFlag True
, ghcOptDynLinkMode = toFlag GhcDynamicOnly
}
-- TODO: Placing all Haskell, C, & C++ objects in a single directory
Expand Down
42 changes: 8 additions & 34 deletions Cabal/src/Distribution/Simple/GHC/Build/Link.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ linkOrLoadComponent
linkerOpts rpaths =
mempty
{ ghcOptLinkOptions =
PD.ldOptions bi
++ [ "-static"
| withFullyStaticExe lbi
]
[ "-static"
| withFullyStaticExe lbi
]
-- Pass extra `ld-options` given
-- through to GHC's linker.
++ maybe
Expand Down Expand Up @@ -341,36 +340,11 @@ linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg li
--
-- Right now, instead, we pass the path to each object file.
ghcBaseLinkArgs =
mempty
{ -- TODO: This basically duplicates componentGhcOptions.
-- I think we want to do the same as we do for executables: re-use the
-- base options, and link by module names, not object paths.
ghcOptExtra = hcStaticOptions GHC libBi
, ghcOptHideAllPackages = toFlag True
, ghcOptNoAutoLinkPackages = toFlag True
, ghcOptPackageDBs = withPackageDB lbi
, ghcOptThisUnitId = case clbi of
LibComponentLocalBuildInfo{componentCompatPackageKey = pk} ->
toFlag pk
_ -> mempty
, ghcOptThisComponentId = case clbi of
LibComponentLocalBuildInfo
{ componentInstantiatedWith = insts
} ->
if null insts
then mempty
else toFlag (componentComponentId clbi)
_ -> mempty
, ghcOptInstantiatedWith = case clbi of
LibComponentLocalBuildInfo
{ componentInstantiatedWith = insts
} ->
insts
_ -> []
, ghcOptPackages =
toNubListR $
Internal.mkGhcOptPackages mempty clbi
}
Internal.linkGhcOptions verbosity lbi libBi clbi
<> mempty
{ ghcOptExtra = hcStaticOptions GHC libBi
, ghcOptNoAutoLinkPackages = toFlag True
}

-- After the relocation lib is created we invoke ghc -shared
-- with the dependencies spelled out as -package arguments
Expand Down
Loading
Loading