[Git][ghc/ghc][wip/toolchain-selection] Configure Cpp and HsCpp separately

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Mon May 22 14:32:02 UTC 2023



Rodrigo Mesquita pushed to branch wip/toolchain-selection at Glasgow Haskell Compiler / GHC


Commits:
d6e52272 by Rodrigo Mesquita at 2023-05-22T15:31:55+01:00
Configure Cpp and HsCpp separately

- - - - -


4 changed files:

- m4/ghc_toolchain.m4
- utils/ghc-toolchain/Main.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Target.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs


Changes:

=====================================
m4/ghc_toolchain.m4
=====================================
@@ -21,12 +21,14 @@ AC_DEFUN([FIND_GHC_TOOLCHAIN],
     echo "--cc=$CC" >> acargs
     ADD_GHC_TOOLCHAIN_ARG([cc-opt], [$CONF_CC_OPTS_STAGE1])
 
-    # We can't use $CPP, since HS_CPP_CMD is expected to be a single
-    # command (no flags), and AC_PROG_CPP defines CPP as "/usr/bin/gcc -E".
-    echo "--cpp=$HaskellCPPCmd" >> acargs
-    # ROMES:TODO: CONF_CPP_OPTS_STAGE1 vs HaskellCPPArgs
+    # CPP flags
+    echo "--cpp=$CPPCmd" >> acargs
     ADD_GHC_TOOLCHAIN_ARG([cpp-opt], [$CONF_CPP_OPTS_STAGE1])
 
+    # HS CPP flags
+    echo "--hs-cpp=$HaskellCPPCmd" >> acargs
+    ADD_GHC_TOOLCHAIN_ARG([hs-cpp-opt], [$HaskellCPPArgs])
+
     echo "--cc-link=$CC" >> acargs
     ADD_GHC_TOOLCHAIN_ARG([cc-link-opt], [$CONF_GCC_LINK_OPTS_STAGE1])
     echo "--cxx=$CXX" >> acargs


=====================================
utils/ghc-toolchain/Main.hs
=====================================
@@ -35,6 +35,7 @@ data Opts = Opts
     , optCc        :: ProgOpt
     , optCxx       :: ProgOpt
     , optCpp       :: ProgOpt
+    , optHsCpp     :: ProgOpt
     , optCcLink    :: ProgOpt
     , optAr        :: ProgOpt
     , optRanlib    :: ProgOpt
@@ -58,6 +59,7 @@ emptyOpts = Opts
     , optCc        = po0
     , optCxx       = po0
     , optCpp       = po0
+    , optHsCpp     = po0
     , optCcLink    = po0
     , optAr        = po0
     , optRanlib    = po0
@@ -76,12 +78,13 @@ emptyOpts = Opts
   where
     po0 = emptyProgOpt
 
-_optCc, _optCxx, _optCpp, _optCcLink, _optAr, _optRanlib, _optNm,
+_optCc, _optCxx, _optCpp, _optHsCpp, _optCcLink, _optAr, _optRanlib, _optNm,
     _optReadelf, _optMergeObjs, _optDllwrap, _optWindres
     :: Lens Opts ProgOpt
 _optCc      = Lens optCc      (\x o -> o {optCc=x})
 _optCxx     = Lens optCxx     (\x o -> o {optCxx=x})
 _optCpp     = Lens optCpp     (\x o -> o {optCpp=x})
+_optHsCpp   = Lens optHsCpp   (\x o -> o {optHsCpp=x})
 _optCcLink  = Lens optCcLink  (\x o -> o {optCcLink=x})
 _optAr      = Lens optAr      (\x o -> o {optAr=x})
 _optRanlib  = Lens optRanlib  (\x o -> o {optRanlib=x})
@@ -131,6 +134,7 @@ options =
     concat
     [ progOpts "cc" "C compiler" _optCc
     , progOpts "cpp" "C preprocessor" _optCpp
+    , progOpts "hs-cpp" "Haskell C preprocessor" _optHsCpp
     , progOpts "cxx" "C++ compiler" _optCxx
     , progOpts "cc-link" "C compiler for linking" _optCcLink
     , progOpts "ar" "ar archiver" _optAr
@@ -289,6 +293,7 @@ mkTarget opts = do
     cc0 <- findCc (optCc opts)
     cxx <- findCxx (optCxx opts)
     cpp <- findCpp (optCpp opts) cc0
+    hsCpp <- findHsCpp (optHsCpp opts) cc0
     archOs <- parseTriple cc0 (optTriple opts)
     cc <- addPlatformDepCcFlags archOs cc0
     readelf <- optional $ findReadelf (optReadelf opts)
@@ -338,6 +343,7 @@ mkTarget opts = do
                    , tgtCCompiler = cc
                    , tgtCxxCompiler = cxx
                    , tgtCPreprocessor = cpp
+                   , tgtHsCPreprocessor = hsCpp
                    , tgtAr = ar
                    , tgtCCompilerLink = ccLink
                    , tgtRanlib = ranlib


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Target.hs
=====================================
@@ -48,7 +48,8 @@ data Target = Target
       -- C toolchain
     , tgtCCompiler :: Cc
     , tgtCxxCompiler :: Cxx
-    , tgtCPreprocessor :: Cpp -- if hadrian depends on Cpp (not HsCpp flags) then this isn't sufficient
+    , tgtCPreprocessor :: Cpp
+    , tgtHsCPreprocessor :: HsCpp
     , tgtCCompilerLink :: CcLink
     -- , tgtLd :: Program -- needed? probably not, we link always through the c compiler
     -- , tgtLdIsGnuLd :: Bool -- After rebase on LdHasGcSections (and renamed)


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs
=====================================
@@ -1,6 +1,6 @@
 {-# LANGUAGE NamedFieldPuns #-}
 
-module GHC.Toolchain.Tools.Cpp (Cpp(..), findCpp) where
+module GHC.Toolchain.Tools.Cpp (HsCpp(..), findHsCpp, Cpp(..), findCpp) where
 
 import Control.Monad
 import System.FilePath
@@ -12,22 +12,28 @@ import GHC.Toolchain.Utils (withTempDir)
 import GHC.Toolchain.Tools.Cc
 
 newtype Cpp = Cpp { cppProgram :: Program
-                  }
+                    }
     deriving (Show, Read, Eq, Ord)
 
-findCpp :: ProgOpt -> Cc -> M Cpp
-findCpp progOpt cc = checking "for C preprocessor" $ do
-  -- Use the specified CPP or try to find one (candidate is the c compiler)
-  foundCppProg <- findProgram "C preprocessor" progOpt [prgPath $ ccProgram cc]
+newtype HsCpp = HsCpp { hsCppProgram :: Program
+                      }
+    deriving (Show, Read, Eq, Ord)
+
+----- Haskell Preprocessor -----
+
+findHsCpp :: ProgOpt -> Cc -> M HsCpp
+findHsCpp progOpt cc = checking "for Haskell C preprocessor" $ do
+  -- Use the specified HS CPP or try to find one (candidate is the c compiler)
+  foundHsCppProg <- findProgram "Haskell C preprocessor" progOpt [prgPath $ ccProgram cc]
   case poFlags progOpt of
-    -- If the user specified CPP flags don't second-guess them
-    Just _ -> return Cpp{cppProgram=foundCppProg}
-    -- Otherwise, configure the CPP flags for this CPP program
+    -- If the user specified HS CPP flags don't second-guess them
+    Just _ -> return HsCpp{hsCppProgram=foundHsCppProg}
+    -- Otherwise, configure the HS CPP flags for this CPP program
     Nothing -> do
-      let rawCppProgram = over _prgFlags (["-E"]++) foundCppProg
-      hppArgs <- findHsCppArgs rawCppProgram
-      let cppProgram = over _prgFlags (++hppArgs) rawCppProgram
-      return Cpp{cppProgram}
+      let rawHsCppProgram = over _prgFlags (["-E"]++) foundHsCppProg
+      hppArgs <- findHsCppArgs rawHsCppProgram
+      let hsCppProgram = over _prgFlags (++hppArgs) rawHsCppProgram
+      return HsCpp{hsCppProgram}
 
 -- | Given a C preprocessor, figure out how it should be invoked to preprocess
 -- Haskell source.
@@ -51,3 +57,16 @@ findHsCppArgs cpp = withTempDir $ \dir -> do
       , tryFlag "-Wno-trigraphs"
       ]
 
+----- C preprocessor -----
+
+findCpp :: ProgOpt -> Cc -> M Cpp
+findCpp progOpt cc = checking "for C preprocessor" $ do
+  -- Use the specified HS CPP or try to find one (candidate is the c compiler)
+  foundCppProg <- findProgram "C preprocessor" progOpt [prgPath $ ccProgram cc]
+  case poFlags progOpt of
+    -- If the user specified CPP flags don't second-guess them
+    Just _ -> return Cpp{cppProgram=foundCppProg}
+    -- Otherwise, configure the CPP flags for this CPP program
+    Nothing -> do
+      let cppProgram = over _prgFlags (["-E"]++) foundCppProg
+      return Cpp{cppProgram}



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d6e52272a44055d4f3487c91514cfd27bf20fd3b

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d6e52272a44055d4f3487c91514cfd27bf20fd3b
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230522/1efafd3e/attachment-0001.html>


More information about the ghc-commits mailing list