[commit: packages/Cabal] ghc-head: Fix building of executables that use TH with dyn-by-default GHC. (c92409a)
git at git.haskell.org
git at git.haskell.org
Mon Aug 26 23:28:16 CEST 2013
Repository : ssh://git@git.haskell.org/Cabal
On branch : ghc-head
Link : http://git.haskell.org/?p=packages/Cabal.git;a=commit;h=c92409a4ced44577b11fd66242988392eac95b08
>---------------------------------------------------------------
commit c92409a4ced44577b11fd66242988392eac95b08
Author: Mikhail Glushenkov <mikhail.glushenkov at gmail.com>
Date: Wed Jul 10 23:21:01 2013 +0200
Fix building of executables that use TH with dyn-by-default GHC.
Fixes #1252. Makes the test suite pass with GHC HEAD.
(If 'TemplateHaskell/profiling' still fails, you're probably affected by this
GHC bug: http://ghc.haskell.org/trac/ghc/ticket/7978 . Try compiling a more
recent GHC HEAD.)
>---------------------------------------------------------------
c92409a4ced44577b11fd66242988392eac95b08
Cabal/Distribution/Simple/GHC.hs | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/Cabal/Distribution/Simple/GHC.hs b/Cabal/Distribution/Simple/GHC.hs
index 7b7589c..e162f21 100644
--- a/Cabal/Distribution/Simple/GHC.hs
+++ b/Cabal/Distribution/Simple/GHC.hs
@@ -710,6 +710,8 @@ buildLib verbosity pkg_descr lbi lib clbi = do
"-dynosuf", "dyn_o"]
}
+ -- TODO: the logic in this fragment is quite convoluted. Should be possible to
+ -- simplify/refactor.
unless (null (libModules lib)) $
do let vanilla = whenVanillaLib forceVanillaLib (runGhcProg vanillaOpts)
shared = whenSharedLib forceSharedLib (runGhcProg sharedOpts)
@@ -882,6 +884,7 @@ buildExe verbosity _pkg_descr lbi
-- build executables
srcMainFile <- findFile (exeDir : hsSourceDirs exeBi) modPath
+ isGhcDynamic <- ghcDynamic verbosity ghcProg
let isHaskellMain = elem (takeExtension srcMainFile) [".hs", ".lhs"]
cSrcs = cSources exeBi ++ [srcMainFile | not isHaskellMain]
@@ -913,6 +916,21 @@ buildExe verbosity _pkg_descr lbi
compileOpts | withProfExe lbi = profOpts
| withDynExe lbi = dynOpts
| otherwise = staticOpts
+ withStaticExe = (not $ withProfExe lbi) && (not $ withDynExe lbi)
+
+ -- For building exe's that use TH with -prof or -dynamic we actually have
+ -- to build twice, once without -prof/-dynamic and then again with
+ -- -prof/-dynamic. This is because the code that TH needs to run at
+ -- compile time needs to be the vanilla ABI so it can be loaded up and run
+ -- by the compiler.
+ -- With dynamic-by-default GHC the TH object files loaded at compile-time
+ -- need to be .dyn_o instead of .o.
+ doingTH = EnableExtension TemplateHaskell `elem` allExtensions exeBi
+ compileTHOpts | isGhcDynamic = dynOpts
+ | otherwise = staticOpts
+ compileForTH
+ | isGhcDynamic = doingTH && (withProfExe lbi || withStaticExe)
+ | otherwise = doingTH && (withProfExe lbi || withDynExe lbi)
linkOpts = compileOpts `mappend` mempty {
ghcOptLinkOptions = PD.ldOptions exeBi,
@@ -923,15 +941,10 @@ buildExe verbosity _pkg_descr lbi
ghcOptExtra = ["-no-hs-main" | not isHaskellMain ]
}
- -- For building exe's for profiling that use TH we actually
- -- have to build twice, once without profiling and then again
- -- with profiling. This is because the code that TH needs to
- -- run at compile time needs to be the vanilla ABI so it can
- -- be loaded up and run by the compiler.
- when ((withProfExe lbi || withDynExe lbi) &&
- EnableExtension TemplateHaskell `elem` allExtensions exeBi) $
- runGhcProg staticOpts { ghcOptNoLink = toFlag True }
- --TODO: do we also need to play the static vs dynamic games here?
+ -- Build static/dynamic object files for TH, if needed.
+ -- TODO: use -dynamic-too when possible
+ when compileForTH $
+ runGhcProg compileTHOpts { ghcOptNoLink = toFlag True }
runGhcProg compileOpts { ghcOptNoLink = toFlag True }
More information about the ghc-commits
mailing list