diff options
author | Ethan Kiang <chocopuff298@gmail.com> | 2021-06-22 21:34:34 +0800 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-07-06 13:37:24 -0400 |
commit | 4002bd1dcee0d05927abc669d6848c43b124c253 (patch) | |
tree | dbbce87ba00b31fbcf21873918d9c2fe1266b93c | |
parent | a4e742c5157f268781761553496e8e37e3f00ab5 (diff) | |
download | haskell-4002bd1dcee0d05927abc669d6848c43b124c253.tar.gz |
Pass '-x c++' and '-std=c++11' to `cc` for cpp files, in Hadrian
'-x c++' was found to be required on Darwin Clang 11 and 12.
'-std=c++' was found to be needed on Clang 12 but not 11.
-rw-r--r-- | hadrian/src/Builder.hs | 13 | ||||
-rw-r--r-- | hadrian/src/Flavour.hs | 3 | ||||
-rw-r--r-- | hadrian/src/Rules/Compile.hs | 12 | ||||
-rw-r--r-- | hadrian/src/Settings/Builders/Cc.hs | 12 | ||||
-rw-r--r-- | hadrian/src/Settings/Packages.hs | 3 |
5 files changed, 30 insertions, 13 deletions
diff --git a/hadrian/src/Builder.hs b/hadrian/src/Builder.hs index 04202e03f3..2661ba7df6 100644 --- a/hadrian/src/Builder.hs +++ b/hadrian/src/Builder.hs @@ -1,9 +1,9 @@ {-# LANGUAGE InstanceSigs, TypeOperators #-} module Builder ( -- * Data types - ArMode (..), CcMode (..), ConfigurationInfo (..), GhcMode (..), - GhcPkgMode (..), HaddockMode (..), SphinxMode (..), TarMode (..), - Builder (..), + ArMode (..), CcMode (..), ConfigurationInfo (..), DependencyType (..), + GhcMode (..), GhcPkgMode (..), HaddockMode (..), SphinxMode (..), + TarMode (..), Builder (..), -- * Builder properties builderProvenance, systemBuilderPath, builderPath, isSpecified, needBuilder, @@ -41,12 +41,17 @@ import Packages -- | C compiler can be used in two different modes: -- * Compile or preprocess a source file. -- * Extract source dependencies by passing @-MM@ command line argument. -data CcMode = CompileC | FindCDependencies deriving (Eq, Generic, Show) +data CcMode = CompileC | FindCDependencies DependencyType deriving (Eq, Generic, Show) +data DependencyType = CDep | CxxDep deriving (Eq, Generic, Show) instance Binary CcMode instance Hashable CcMode instance NFData CcMode +instance Binary DependencyType +instance Hashable DependencyType +instance NFData DependencyType + -- | GHC can be used in four different modes: -- * Compile a Haskell source file. -- * Compile a C source file. diff --git a/hadrian/src/Flavour.hs b/hadrian/src/Flavour.hs index d8f34347f4..aa31de83fa 100644 --- a/hadrian/src/Flavour.hs +++ b/hadrian/src/Flavour.hs @@ -391,7 +391,8 @@ builderSetting = ccBuilder = [ ("c", CompileC) - , ("deps", FindCDependencies) + -- Not sure how to handle the FindCDependencies CxxDep case + , ("deps", FindCDependencies CDep) ] stages = map (\stg -> (stageString stg, stg)) [minBound..maxBound] diff --git a/hadrian/src/Rules/Compile.hs b/hadrian/src/Rules/Compile.hs index b21bcaf74b..f093d15b96 100644 --- a/hadrian/src/Rules/Compile.hs +++ b/hadrian/src/Rules/Compile.hs @@ -239,7 +239,7 @@ compileNonHsObject rs lang path = do Cmm -> obj2src "cmm" isGeneratedCmmFile ctx path Cxx -> obj2src "cpp" (const False) ctx path need [src] - needDependencies ctx src (path <.> "d") + needDependencies lang ctx src (path <.> "d") buildWithResources rs $ target ctx (builder stage) [src] [path] -- * Helpers @@ -247,11 +247,11 @@ compileNonHsObject rs lang path = do -- | Discover dependencies of a given source file by iteratively calling @gcc@ -- in the @-MM -MG@ mode and building generated dependencies if they are missing -- until reaching a fixed point. -needDependencies :: Context -> FilePath -> FilePath -> Action () -needDependencies context@Context {..} src depFile = discover +needDependencies :: SourceLang -> Context -> FilePath -> FilePath -> Action () +needDependencies lang context@Context {..} src depFile = discover where discover = do - build $ target context (Cc FindCDependencies stage) [src] [depFile] + build $ target context (Cc (FindCDependencies depType) stage) [src] [depFile] deps <- parseFile depFile -- Generated dependencies, if not yet built, will not be found and hence -- will be referred to simply by their file names. @@ -266,6 +266,10 @@ needDependencies context@Context {..} src depFile = discover need todo -- Build newly discovered generated dependencies discover -- Continue the discovery process + -- We need to pass different flags to cc depending on whether the + -- file to compile is a .c or a .cpp file + depType = if lang == Cxx then CxxDep else CDep + parseFile :: FilePath -> Action [String] parseFile file = do input <- liftIO $ readFile file diff --git a/hadrian/src/Settings/Builders/Cc.hs b/hadrian/src/Settings/Builders/Cc.hs index e0055f3e8b..f7bf215f26 100644 --- a/hadrian/src/Settings/Builders/Cc.hs +++ b/hadrian/src/Settings/Builders/Cc.hs @@ -17,12 +17,18 @@ ccBuilderArgs = do , arg "-c", arg =<< getInput , arg "-o", arg =<< getOutput ] - , builder (Cc FindCDependencies) ? do + , builder (Cc (FindCDependencies CDep)) ? findCDepExpr CDep + , builder (Cc (FindCDependencies CxxDep)) ? findCDepExpr CxxDep + ] + where + findCDepExpr depType = do output <- getOutput mconcat [ arg "-E" , arg "-MM", arg "-MG" , arg "-MF", arg output , arg "-MT", arg $ dropExtension output -<.> "o" + , case depType of CDep -> mempty; CxxDep -> arg "-std=c++11" , cIncludeArgs - , arg "-x", arg "c" - , arg =<< getInput ] ] + , arg "-x", arg (case depType of CDep -> "c"; CxxDep -> "c++") + , arg =<< getInput + ] diff --git a/hadrian/src/Settings/Packages.hs b/hadrian/src/Settings/Packages.hs index 7b0a28fd4c..8161598431 100644 --- a/hadrian/src/Settings/Packages.hs +++ b/hadrian/src/Settings/Packages.hs @@ -367,7 +367,8 @@ rtsPackageArgs = package rts ? do , if not (null libnumaLibraryDir) then arg ("--extra-lib-dirs="++libnumaLibraryDir) else mempty , if not (null libnumaIncludeDir) then arg ("--extra-include-dirs="++libnumaIncludeDir) else mempty ] - , builder (Cc FindCDependencies) ? cArgs + , builder (Cc (FindCDependencies CDep)) ? cArgs + , builder (Cc (FindCDependencies CxxDep)) ? cArgs , builder (Ghc CompileCWithGhc) ? map ("-optc" ++) <$> cArgs , builder (Ghc CompileCppWithGhc) ? map ("-optcxx" ++) <$> cArgs , builder Ghc ? ghcArgs |