Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
Packages
Cabal
Commits
d54b4374
Commit
d54b4374
authored
Jul 12, 2013
by
Mikhail Glushenkov
Browse files
Merge pull request #1386 from 23Skidoo/ghc-head-fixes
Fix building of executables that use TH with dyn-by-default GHC.
parents
e70bbe03
c854a53b
Changes
10
Hide whitespace changes
Inline
Side-by-side
Cabal/Cabal.cabal
View file @
d54b4374
...
...
@@ -91,6 +91,10 @@ extra-source-files:
tests/PackageTests/PreProcess/Foo.hsc
tests/PackageTests/PreProcess/Main.hs
tests/PackageTests/PreProcess/my.cabal
tests/PackageTests/TemplateHaskell/vanilla/Exe.hs
tests/PackageTests/TemplateHaskell/vanilla/Lib.hs
tests/PackageTests/TemplateHaskell/vanilla/TH.hs
tests/PackageTests/TemplateHaskell/vanilla/my.cabal
tests/PackageTests/TemplateHaskell/dynamic/Exe.hs
tests/PackageTests/TemplateHaskell/dynamic/Lib.hs
tests/PackageTests/TemplateHaskell/dynamic/TH.hs
...
...
Cabal/Distribution/Simple/GHC.hs
View file @
d54b4374
...
...
@@ -713,10 +713,11 @@ buildLib verbosity pkg_descr lbi lib clbi = do
unless
(
null
(
libModules
lib
))
$
do
let
vanilla
=
whenVanillaLib
forceVanillaLib
(
runGhcProg
vanillaOpts
)
shared
=
whenSharedLib
forceSharedLib
(
runGhcProg
sharedOpts
)
if
dynamicTooSupported
&&
(
forceVanillaLib
||
withVanillaLib
lbi
)
&&
(
forceSharedLib
||
withSharedLib
lbi
)
&&
null
(
ghcSharedOptions
libBi
)
useDynToo
=
dynamicTooSupported
&&
(
forceVanillaLib
||
withVanillaLib
lbi
)
&&
(
forceSharedLib
||
withSharedLib
lbi
)
&&
null
(
ghcSharedOptions
libBi
)
if
useDynToo
then
runGhcProg
vanillaSharedOpts
else
if
isGhcDynamic
then
do
shared
;
vanilla
else
do
vanilla
;
shared
...
...
@@ -881,7 +882,9 @@ buildExe verbosity _pkg_descr lbi
-- build executables
srcMainFile
<-
findFile
(
exeDir
:
hsSourceDirs
exeBi
)
modPath
srcMainFile
<-
findFile
(
exeDir
:
hsSourceDirs
exeBi
)
modPath
isGhcDynamic
<-
ghcDynamic
verbosity
ghcProg
dynamicTooSupported
<-
ghcSupportsDynamicToo
verbosity
ghcProg
let
isHaskellMain
=
elem
(
takeExtension
srcMainFile
)
[
".hs"
,
".lhs"
]
cSrcs
=
cSources
exeBi
++
[
srcMainFile
|
not
isHaskellMain
]
...
...
@@ -909,12 +912,37 @@ buildExe verbosity _pkg_descr lbi
ghcOptObjSuffix
=
toFlag
"dyn_o"
,
ghcOptExtra
=
ghcSharedOptions
exeBi
}
compileOpts
|
withProfExe
lbi
=
profOpts
dynTooOpts
=
staticOpts
`
mappend
`
mempty
{
ghcOptExtra
=
[
"-dynamic-too"
,
"-dynhisuf"
,
"dyn_hi"
,
"-dynosuf"
,
"dyn_o"
]
}
commonOpts
|
withProfExe
lbi
=
profOpts
|
withDynExe
lbi
=
dynOpts
|
otherwise
=
staticOpts
linkOpts
=
compileOpts
`
mappend
`
mempty
{
compileOpts
|
useDynToo
=
dynTooOpts
|
otherwise
=
commonOpts
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
-- Should we use -dynamic-too instead of compilng twice?
useDynToo
=
dynamicTooSupported
&&
isGhcDynamic
&&
doingTH
&&
withStaticExe
&&
null
(
ghcSharedOptions
exeBi
)
compileTHOpts
|
isGhcDynamic
=
dynOpts
|
otherwise
=
staticOpts
compileForTH
|
useDynToo
=
False
|
isGhcDynamic
=
doingTH
&&
(
withProfExe
lbi
||
withStaticExe
)
|
otherwise
=
doingTH
&&
(
withProfExe
lbi
||
withDynExe
lbi
)
linkOpts
=
commonOpts
`
mappend
`
mempty
{
ghcOptLinkOptions
=
PD
.
ldOptions
exeBi
,
ghcOptLinkLibs
=
extraLibs
exeBi
,
ghcOptLinkLibPath
=
extraLibDirs
exeBi
,
...
...
@@ -923,15 +951,9 @@ 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.
when
compileForTH
$
runGhcProg
compileTHOpts
{
ghcOptNoLink
=
toFlag
True
}
runGhcProg
compileOpts
{
ghcOptNoLink
=
toFlag
True
}
...
...
Cabal/tests/PackageTests.hs
View file @
d54b4374
...
...
@@ -71,6 +71,8 @@ tests version inplaceSpec =
,
hunit
"BenchmarkExeV10/Test"
PackageTests
.
BenchmarkExeV10
.
Check
.
checkBenchmark
,
hunit
"BenchmarkOptions"
PackageTests
.
BenchmarkOptions
.
Check
.
suite
,
hunit
"TemplateHaskell/vanilla"
PackageTests
.
TemplateHaskell
.
Check
.
vanilla
,
hunit
"TemplateHaskell/profiling"
PackageTests
.
TemplateHaskell
.
Check
.
profiling
,
hunit
"TemplateHaskell/dynamic"
...
...
Cabal/tests/PackageTests/TemplateHaskell/Check.hs
View file @
d54b4374
...
...
@@ -4,6 +4,13 @@ import PackageTests.PackageTester
import
System.FilePath
import
Test.HUnit
vanilla
::
Test
vanilla
=
TestCase
$
do
let
spec
=
PackageSpec
(
"PackageTests"
</>
"TemplateHaskell"
</>
"vanilla"
)
[]
result
<-
cabal_build
spec
assertBuildSucceeded
result
profiling
::
Test
profiling
=
TestCase
$
do
let
flags
=
[
"--enable-library-profiling"
...
...
Cabal/tests/PackageTests/TemplateHaskell/dynamic/Exe.hs
View file @
d54b4374
...
...
@@ -3,4 +3,4 @@ module Main where
import
TH
main
=
print
$
(
splice
)
\ No newline at end of file
main
=
print
$
(
splice
)
Cabal/tests/PackageTests/TemplateHaskell/profiling/Exe.hs
View file @
d54b4374
...
...
@@ -3,4 +3,4 @@ module Main where
import
TH
main
=
print
$
(
splice
)
\ No newline at end of file
main
=
print
$
(
splice
)
Cabal/tests/PackageTests/TemplateHaskell/vanilla/Exe.hs
0 → 100644
View file @
d54b4374
{-# LANGUAGE TemplateHaskell #-}
module
Main
where
import
TH
main
=
print
$
(
splice
)
Cabal/tests/PackageTests/TemplateHaskell/vanilla/Lib.hs
0 → 100644
View file @
d54b4374
{-# LANGUAGE TemplateHaskell #-}
module
Lib
where
import
TH
val
=
$
(
splice
)
Cabal/tests/PackageTests/TemplateHaskell/vanilla/TH.hs
0 → 100644
View file @
d54b4374
{-# LANGUAGE TemplateHaskell #-}
module
TH
where
splice
=
[
|
()
|
]
Cabal/tests/PackageTests/TemplateHaskell/vanilla/my.cabal
0 → 100644
View file @
d54b4374
Name: templateHaskell
Version: 0.1
Build-Type: Simple
Cabal-Version: >= 1.2
Library
Exposed-Modules: Lib
Other-Modules: TH
Build-Depends: base, template-haskell
Extensions: TemplateHaskell
Executable main
Main-is: Exe.hs
Build-Depends: base, template-haskell
Extensions: TemplateHaskell
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment