Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -61,7 +61,6 @@ module Distribution.Simple.GHC
, hcPkgInfo
, registerPackage
, Internal.componentGhcOptions
, Internal.componentCcGhcOptions
, getGhcAppDir
, getLibDir
, compilerBuildWay
Expand Down Expand Up @@ -794,7 +793,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
Comment thread
zlonast marked this conversation as resolved.
}
profArgs =
vanillaArgs
Expand All @@ -806,7 +805,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 @@ -820,7 +819,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
57 changes: 47 additions & 10 deletions Cabal/src/Distribution/Simple/GHC/Build/ExtraSources.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ import Control.Monad
import Data.Foldable
import Distribution.Simple.Flag
import qualified Distribution.Simple.GHC.Internal as Internal
import Distribution.Simple.Program
import Distribution.Simple.Program.GHC
import Distribution.Simple.Utils
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
import Distribution.Simple.Setup.Common (commonSetupTempFileOptions)
import Distribution.System (Arch (JavaScript), Platform (..))
import Distribution.Types.ComponentLocalBuildInfo
Expand Down Expand Up @@ -77,7 +78,26 @@ 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
-- https://gitlab.haskell.org/ghc/ghc/-/issues/16477
-- see example in cabal-testsuite/PackageTests/FFI/ForeignOptsC
ghcOptCxxOptions =
Comment thread
zlonast marked this conversation as resolved.
Outdated
Internal.ghcOptionsSince
(mkVersion [8, 10])
(compiler lbi)
(Internal.optimizationCFlags lbi ++ cxxOptions bi)
, -- Use -pgmc to ensure that Cabal always passes cc-options, ld-options to GHC (#4435, #9801)
-- We can only do this on GHC >= 9.4, as we need https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6949
-- Without that GHC MR, this change would cause GHC to never pass -no-pie when linking,
-- which can cause breakage depending on the C toolchain use. Otherwise,
-- we pass the flag only to source files #11712
-- see example in cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc
ghcOptCcProgram = maybeToFlag $ programPath <$> lookupProgram gccProgram (withPrograms lbi)
}
)
( \c -> do
let cFiles = cSources (componentBuildInfo c)
case c of
Expand All @@ -90,7 +110,26 @@ 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
-- https://gitlab.haskell.org/ghc/ghc/-/issues/16477
-- see example in cabal-testsuite/PackageTests/FFI/ForeignOptsCxx
ghcOptCcOptions =
Internal.ghcOptionsSince
(mkVersion [8, 10])
(compiler lbi)
(Internal.optimizationCFlags lbi ++ ccOptions bi)
, -- Use -pgmc to ensure that Cabal always passes cc-options, ld-options to GHC (#4435, #9801)
-- We can only do this on GHC >= 9.4, as we need https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6949
-- Without that GHC MR, this change would cause GHC to never pass -no-pie when linking,
-- which can cause breakage depending on the C toolchain use. Otherwise,
-- we pass the flag only to source files #11712
-- see example in cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc
ghcOptCcProgram = maybeToFlag $ programPath <$> lookupProgram gccProgram (withPrograms lbi)
}
)
Comment thread
zlonast marked this conversation as resolved.
Outdated
( \c -> do
let cxxFiles = cxxSources (componentBuildInfo c)
case c of
Expand All @@ -105,7 +144,7 @@ buildJsSources _mbMainFile ghcProg buildTargetDir neededWays verbHandles = 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 @@ -122,12 +161,12 @@ buildJsSources _mbMainFile ghcProg buildTargetDir neededWays verbHandles = 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 @@ -145,9 +184,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
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 @@ -120,10 +120,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 @@ -322,36 +321,11 @@ linkLibrary buildTargetDir cleanedExtraLibDirs verbosity runGhcProg lib lbi clbi
-- Right now, instead, we pass the path to each object file.
ghcBaseLinkArgs :: GhcOptions
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 (verbosityLevel 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