summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-01-08 11:25:48 +0000
committerMatthew Pickering <matthewtpickering@gmail.com>2021-01-20 14:07:46 +0000
commit325c71425e8825cce7d293710b468520306e339d (patch)
treefde7ff6a6715090834f3618a2a49c1f472943377
parentb1cafb82872784c224d297c748f9c78f47a39fd2 (diff)
downloadhaskell-wip/hadrian-cxx.tar.gz
Hadrian: Add support for packages with C++ fileswip/hadrian-cxx
-rw-r--r--hadrian/src/Builder.hs1
-rw-r--r--hadrian/src/Hadrian/Haskell/Cabal/Parse.hs2
-rw-r--r--hadrian/src/Hadrian/Haskell/Cabal/Type.hs2
-rw-r--r--hadrian/src/Rules/Compile.hs8
-rw-r--r--hadrian/src/Rules/Library.hs9
-rw-r--r--hadrian/src/Rules/Program.hs4
-rwxr-xr-xhadrian/src/Settings.hs1
-rw-r--r--hadrian/src/Settings/Builders/Ghc.hs19
-rw-r--r--hadrian/src/Settings/Packages.hs1
9 files changed, 43 insertions, 4 deletions
diff --git a/hadrian/src/Builder.hs b/hadrian/src/Builder.hs
index 3419dee422..e8c72b794e 100644
--- a/hadrian/src/Builder.hs
+++ b/hadrian/src/Builder.hs
@@ -52,6 +52,7 @@ instance NFData CcMode
-- * Link object files & static libraries into an executable.
data GhcMode = CompileHs
| CompileCWithGhc
+ | CompileCppWithGhc
| FindHsDependencies
| LinkHs
| ToolArgs
diff --git a/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs b/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
index ace24dc87d..7b31961154 100644
--- a/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
+++ b/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
@@ -291,6 +291,7 @@ resolveContextData context@Context {..} = do
, extraLibDirs = C.extraLibDirs buildInfo
, asmSrcs = C.asmSources buildInfo
, cSrcs = C.cSources buildInfo
+ , cxxSrcs = C.cxxSources buildInfo
, cmmSrcs = C.cmmSources buildInfo
, hcOpts = C.programDefaultArgs ghcProg
++ C.hcOptions C.GHC buildInfo
@@ -299,6 +300,7 @@ resolveContextData context@Context {..} = do
++ C.programOverrideArgs ghcProg
, asmOpts = C.asmOptions buildInfo
, ccOpts = C.ccOptions buildInfo
+ , cxxOpts = C.cxxOptions buildInfo
, cmmOpts = C.cmmOptions buildInfo
, cppOpts = C.cppOptions buildInfo
, ldOpts = C.ldOptions buildInfo
diff --git a/hadrian/src/Hadrian/Haskell/Cabal/Type.hs b/hadrian/src/Hadrian/Haskell/Cabal/Type.hs
index 2b5d51a719..e55360a1cf 100644
--- a/hadrian/src/Hadrian/Haskell/Cabal/Type.hs
+++ b/hadrian/src/Hadrian/Haskell/Cabal/Type.hs
@@ -53,10 +53,12 @@ data ContextData = ContextData
, extraLibDirs :: [String]
, asmSrcs :: [String]
, cSrcs :: [String]
+ , cxxSrcs :: [String]
, cmmSrcs :: [String]
, hcOpts :: [String]
, asmOpts :: [String]
, ccOpts :: [String]
+ , cxxOpts :: [String]
, cmmOpts :: [String]
, cppOpts :: [String]
, ldOpts :: [String]
diff --git a/hadrian/src/Rules/Compile.hs b/hadrian/src/Rules/Compile.hs
index 12a8707f31..0efcea9474 100644
--- a/hadrian/src/Rules/Compile.hs
+++ b/hadrian/src/Rules/Compile.hs
@@ -39,6 +39,9 @@ compilePackage rs = do
[ root -/- "**/build/cmm/**/*." ++ wayPat ++ "o"
| wayPat <- wayPats] |%> compileNonHsObject rs Cmm
+ [ root -/- "**/build/cpp/**/*." ++ wayPat ++ "o"
+ | wayPat <- wayPats] |%> compileNonHsObject rs Cxx
+
[ root -/- "**/build/s/**/*." ++ wayPat ++ "o"
| wayPat <- wayPats] |%> compileNonHsObject rs Asm
@@ -112,12 +115,13 @@ compilePackage rs = do
-}
-- | Non Haskell source languages that we compile to get object files.
-data SourceLang = Asm | C | Cmm deriving (Eq, Show)
+data SourceLang = Asm | C | Cmm | Cxx deriving (Eq, Show)
parseSourceLang :: Parsec.Parsec String () SourceLang
parseSourceLang = Parsec.choice
[ Parsec.char 'c' *> Parsec.choice
[ Parsec.string "mm" *> pure Cmm
+ , Parsec.string "pp" *> pure Cxx
, pure C
]
, Parsec.char 's' *> pure Asm
@@ -227,11 +231,13 @@ compileNonHsObject rs lang path = do
ctx = objectContext b
builder = case lang of
C -> Ghc CompileCWithGhc
+ Cxx-> Ghc CompileCppWithGhc
_ -> Ghc CompileHs
src <- case lang of
Asm -> obj2src "S" (const False) ctx path
C -> obj2src "c" (const False) ctx path
Cmm -> obj2src "cmm" isGeneratedCmmFile ctx path
+ Cxx -> obj2src "cpp" (const False) ctx path
need [src]
needDependencies ctx src (path <.> "d")
buildWithResources rs $ target ctx (builder stage) [src] [path]
diff --git a/hadrian/src/Rules/Library.hs b/hadrian/src/Rules/Library.hs
index 4b9d7d6235..c67346f5d6 100644
--- a/hadrian/src/Rules/Library.hs
+++ b/hadrian/src/Rules/Library.hs
@@ -117,10 +117,17 @@ nonHsObjects context = do
asmSrcs <- interpretInContext context (getContextData asmSrcs)
asmObjs <- mapM (objectPath context) asmSrcs
cObjs <- cObjects context
+ cxxObjs <- cxxObjects context
cmmSrcs <- interpretInContext context (getContextData cmmSrcs)
cmmObjs <- mapM (objectPath context) cmmSrcs
eObjs <- extraObjects context
- return $ asmObjs ++ cObjs ++ cmmObjs ++ eObjs
+ return $ asmObjs ++ cObjs ++ cxxObjs ++ cmmObjs ++ eObjs
+
+-- | Return all the Cxx object files needed to build the given library context.
+cxxObjects :: Context -> Action [FilePath]
+cxxObjects context = do
+ srcs <- interpretInContext context (getContextData cxxSrcs)
+ mapM (objectPath context) srcs
-- | Return all the C object files needed to build the given library context.
cObjects :: Context -> Action [FilePath]
diff --git a/hadrian/src/Rules/Program.hs b/hadrian/src/Rules/Program.hs
index df542c0f1e..04a3bf3aaa 100644
--- a/hadrian/src/Rules/Program.hs
+++ b/hadrian/src/Rules/Program.hs
@@ -117,9 +117,11 @@ buildBinary rs bin context@Context {..} = do
asmSrcs <- interpretInContext context (getContextData asmSrcs)
asmObjs <- mapM (objectPath context) asmSrcs
cSrcs <- interpretInContext context (getContextData cSrcs)
+ cxxSrcs <- interpretInContext context (getContextData cxxSrcs)
cObjs <- mapM (objectPath context) cSrcs
+ cxxObjs <- mapM (objectPath context) cxxSrcs
hsObjs <- hsObjects context
- let binDeps = asmObjs ++ cObjs ++ hsObjs
+ let binDeps = asmObjs ++ cObjs ++ cxxObjs ++ hsObjs
need binDeps
buildWithResources rs $ target context (Ghc LinkHs stage) binDeps [bin]
synopsis <- pkgSynopsis package
diff --git a/hadrian/src/Settings.hs b/hadrian/src/Settings.hs
index 23f2708b9f..7e712155e2 100755
--- a/hadrian/src/Settings.hs
+++ b/hadrian/src/Settings.hs
@@ -280,6 +280,7 @@ builderSetting = (,,)
where ghcBuilder =
[ ("c", CompileCWithGhc)
+ , ("cpp", CompileCppWithGhc)
, ("deps", FindHsDependencies)
, ("hs", CompileHs)
, ("link", LinkHs)
diff --git a/hadrian/src/Settings/Builders/Ghc.hs b/hadrian/src/Settings/Builders/Ghc.hs
index 240ae4b9df..3880a99562 100644
--- a/hadrian/src/Settings/Builders/Ghc.hs
+++ b/hadrian/src/Settings/Builders/Ghc.hs
@@ -14,7 +14,7 @@ import Rules.Libffi (libffiName)
import System.Directory
ghcBuilderArgs :: Args
-ghcBuilderArgs = mconcat [ compileAndLinkHs, compileC, findHsDependencies
+ghcBuilderArgs = mconcat [ compileAndLinkHs, compileC, compileCxx, findHsDependencies
, toolArgs]
toolArgs :: Args
@@ -66,6 +66,23 @@ compileC = builder (Ghc CompileCWithGhc) ? do
, arg "-o"
, arg =<< getOutput ]
+compileCxx :: Args
+compileCxx = builder (Ghc CompileCppWithGhc) ? do
+ way <- getWay
+ let ccArgs = [ getContextData cxxOpts
+ , getStagedSettingList ConfCcArgs
+ , cIncludeArgs
+ , Dynamic `wayUnit` way ? pure [ "-fPIC", "-DDYNAMIC" ] ]
+ mconcat [ arg "-Wall"
+ , ghcLinkArgs
+ , commonGhcArgs
+ , mconcat (map (map ("-optcxx" ++) <$>) ccArgs)
+ , defaultGhcWarningsArgs
+ , arg "-c"
+ , getInputs
+ , arg "-o"
+ , arg =<< getOutput ]
+
ghcLinkArgs :: Args
ghcLinkArgs = builder (Ghc LinkHs) ? do
pkg <- getPackage
diff --git a/hadrian/src/Settings/Packages.hs b/hadrian/src/Settings/Packages.hs
index 3ac31b539f..a08cc3ee98 100644
--- a/hadrian/src/Settings/Packages.hs
+++ b/hadrian/src/Settings/Packages.hs
@@ -376,6 +376,7 @@ rtsPackageArgs = package rts ? do
]
, builder (Cc FindCDependencies) ? cArgs
, builder (Ghc CompileCWithGhc) ? map ("-optc" ++) <$> cArgs
+ , builder (Ghc CompileCppWithGhc) ? map ("-optcxx" ++) <$> cArgs
, builder Ghc ? ghcArgs
, builder HsCpp ? pure