Commit c92409a4 authored by Mikhail Glushenkov's avatar Mikhail Glushenkov
Browse files

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.)
parent 4606f9b2
......@@ -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 }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment