[Git][ghc/ghc][master] Don't let configure perform trivial substitutions (#21846)

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Wed Nov 23 17:46:58 UTC 2022



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
b5c71454 by Sylvain Henry at 2022-11-23T12:46:35-05:00
Don't let configure perform trivial substitutions (#21846)

Hadrian now performs substitutions, especially to generate .cabal files
from .cabal.in files. Two benefits:

1. We won't have to re-configure when we modify thing.cabal.in. Hadrian
   will take care of this for us.

2. It paves the way to allow the same package to be configured
   differently by Hadrian in the same session. This will be useful to
   fix #19174: we want to build a stage2 cross-compiler for the host
   platform and a stage1 compiler for the cross target platform in the
   same Hadrian session.

- - - - -


10 changed files:

- configure.ac
- hadrian/cfg/system.config.in
- hadrian/src/Oracles/Flag.hs
- hadrian/src/Oracles/Setting.hs
- hadrian/src/Rules.hs
- hadrian/src/Rules/Generate.hs
- hadrian/src/Settings/Packages.hs
- m4/fp_bfd_support.m4
- m4/fp_cc_supports__atomics.m4
- m4/fp_check_pthreads.m4


Changes:

=====================================
configure.ac
=====================================
@@ -943,9 +943,9 @@ AC_CHECK_LIB(m, atan, HaveLibM=YES, HaveLibM=NO)
 if test $HaveLibM = YES
 then
   AC_DEFINE([HAVE_LIBM], [1], [Define to 1 if you need to link with libm])
-  AC_SUBST([CabalHaveLibm],[True])
+  AC_SUBST([UseLibm],[YES])
 else
-  AC_SUBST([CabalHaveLibm],[False])
+  AC_SUBST([UseLibm],[NO])
 fi
 TargetHasLibm=$HaveLibM
 AC_SUBST(TargetHasLibm)
@@ -958,15 +958,11 @@ dnl ################################################################
 
 FP_FIND_LIBFFI
 AC_SUBST(UseSystemLibFFI)
-AS_IF([test "x$with_system_libffi" = "xyes"],
-  [CabalUseSystemLibFFI="True"],
-  [CabalUseSystemLibFFI="False"]
-)
-AC_SUBST(CabalUseSystemLibFFI)
 
 dnl ** check whether we need -ldl to get dlopen()
 AC_CHECK_LIB([dl], [dlopen])
-AC_CHECK_LIB([dl], [dlopen], [AC_SUBST([CabalHaveLibdl], [True])], [AC_SUBST([CabalHaveLibdl], [False])])
+AC_CHECK_LIB([dl], [dlopen], HaveLibdl=YES, HaveLibdl=NO)
+AC_SUBST([UseLibdl],[$HaveLibdl])
 dnl ** check whether we have dlinfo
 AC_CHECK_FUNCS([dlinfo])
 
@@ -1003,7 +999,13 @@ FP_MUSTTAIL
 
 dnl ** check for librt
 AC_CHECK_LIB([rt], [clock_gettime])
-AC_CHECK_LIB([rt], [clock_gettime], [AC_SUBST([CabalHaveLibrt], [True])], [AC_SUBST([CabalHaveLibrt], [False])])
+AC_CHECK_LIB([rt], [clock_gettime], HaveLibrt=YES, HaveLibrt=NO)
+if test $HaveLibrt = YES
+then
+  AC_SUBST([UseLibrt],[YES])
+else
+  AC_SUBST([UseLibrt],[NO])
+fi
 AC_CHECK_FUNCS(clock_gettime timer_settime)
 FP_CHECK_TIMER_CREATE
 
@@ -1119,11 +1121,6 @@ AC_DEFINE_UNQUOTED([RTS_LINKER_USE_MMAP], [$RtsLinkerUseMmap],
 
 GHC_ADJUSTORS_METHOD([Target])
 AC_SUBST([UseLibffiForAdjustors])
-AS_IF([test x"${UseLibffiForAdjustors}" = x"YES"],
-  [CabalLibffiAdjustors=True],
-  [CabalLibffiAdjustors=False]
-)
-AC_SUBST([CabalLibffiAdjustors])
 
 dnl ** Other RTS features
 dnl --------------------------------------------------------------
@@ -1173,12 +1170,6 @@ if grep '	' compiler/ghc.cabal.in 2>&1 >/dev/null; then
    AC_MSG_ERROR([compiler/ghc.cabal.in contains tab characters; please remove them])
 fi
 
-# Create the configuration for the Hadrian build system if it is present
-if test -e hadrian/cfg/system.config.in; then
-    AC_CONFIG_FILES([hadrian/cfg/system.config])
-    AC_CONFIG_FILES([hadrian/ghci-cabal hadrian/ghci-stack hadrian/ghci-multi-cabal])
-fi
-
 # We got caught by
 #     http://savannah.gnu.org/bugs/index.php?1516
 #     $(eval ...) inside conditionals causes errors
@@ -1202,27 +1193,12 @@ checkMake380() {
 checkMake380 make
 checkMake380 gmake
 
-AC_CONFIG_FILES([ mk/project.mk ])
-
-dnl When adding things to this list be sure to update hadrian's
-dnl Rules.Configure.configureResults list.
 AC_CONFIG_FILES(
-[ rts/rts.cabal
-  compiler/ghc.cabal
-  ghc/ghc-bin.cabal
-  utils/runghc/runghc.cabal
-  driver/ghci/ghci-wrapper.cabal
-  utils/iserv/iserv.cabal
-  utils/ghc-pkg/ghc-pkg.cabal
-  utils/remote-iserv/remote-iserv.cabal
-  libraries/ghc-boot/ghc-boot.cabal
-  libraries/ghc-boot-th/ghc-boot-th.cabal
-  libraries/ghci/ghci.cabal
-  libraries/ghc-heap/ghc-heap.cabal
-  libraries/libiserv/libiserv.cabal
-  libraries/template-haskell/template-haskell.cabal
+[ mk/project.mk
+  hadrian/cfg/system.config
+  hadrian/ghci-cabal
+  hadrian/ghci-stack
   docs/users_guide/ghc_config.py
-  libraries/prologue.txt
   distrib/configure.ac
 ])
 


=====================================
hadrian/cfg/system.config.in
=====================================
@@ -90,13 +90,14 @@ ghc-patch-level       = @GhcPatchLevel@
 
 bootstrap-threaded-rts      = @GhcThreadedRts@
 
-project-name          = @ProjectName@
-project-version       = @ProjectVersion@
-project-version-int   = @ProjectVersionInt@
-project-patch-level   = @ProjectPatchLevel@
-project-patch-level1  = @ProjectPatchLevel1@
-project-patch-level2  = @ProjectPatchLevel2@
-project-git-commit-id = @ProjectGitCommitId@
+project-name           = @ProjectName@
+project-version        = @ProjectVersion@
+project-version-munged = @ProjectVersionMunged@
+project-version-int    = @ProjectVersionInt@
+project-patch-level    = @ProjectPatchLevel@
+project-patch-level1   = @ProjectPatchLevel1@
+project-patch-level2   = @ProjectPatchLevel2@
+project-git-commit-id  = @ProjectGitCommitId@
 
 # Compilation and linking flags:
 #===============================
@@ -201,6 +202,12 @@ libnuma-lib-dir       = @LibNumaLibDir@
 # Optional Dependencies:
 #=======================
 
-with-libdw = @UseLibdw@
-with-libnuma = @UseLibNuma@
-have-lib-mingw-ex = @HaveLibMingwEx@
+use-lib-dw        = @UseLibdw@
+use-lib-numa      = @UseLibNuma@
+use-lib-mingw-ex  = @HaveLibMingwEx@
+use-lib-m         = @UseLibm@
+use-lib-rt        = @UseLibrt@
+use-lib-dl        = @UseLibdl@
+use-lib-bfd       = @UseLibbfd@
+use-lib-pthread   = @UseLibpthread@
+need-libatomic    = @NeedLibatomic@


=====================================
hadrian/src/Oracles/Flag.hs
=====================================
@@ -27,13 +27,19 @@ data Flag = ArSupportsAtFile
           | GmpFrameworkPref
           | LeadingUnderscore
           | SolarisBrokenShld
-          | WithLibdw
-          | WithLibnuma
-          | HaveLibMingwEx
           | UseSystemFfi
           | BootstrapThreadedRts
           | BootstrapEventLoggingRts
           | UseLibffiForAdjustors
+          | UseLibdw
+          | UseLibnuma
+          | UseLibmingwex
+          | UseLibm
+          | UseLibrt
+          | UseLibdl
+          | UseLibbfd
+          | UseLibpthread
+          | NeedLibatomic
 
 -- Note, if a flag is set to empty string we treat it as set to NO. This seems
 -- fragile, but some flags do behave like this.
@@ -51,13 +57,19 @@ flag f = do
             GmpFrameworkPref     -> "gmp-framework-preferred"
             LeadingUnderscore    -> "leading-underscore"
             SolarisBrokenShld    -> "solaris-broken-shld"
-            WithLibdw            -> "with-libdw"
-            WithLibnuma          -> "with-libnuma"
-            HaveLibMingwEx       -> "have-lib-mingw-ex"
             UseSystemFfi         -> "use-system-ffi"
             BootstrapThreadedRts -> "bootstrap-threaded-rts"
             BootstrapEventLoggingRts -> "bootstrap-event-logging-rts"
             UseLibffiForAdjustors -> "use-libffi-for-adjustors"
+            UseLibdw             -> "use-lib-dw"
+            UseLibnuma           -> "use-lib-numa"
+            UseLibmingwex        -> "use-lib-mingw-ex"
+            UseLibm              -> "use-lib-m"
+            UseLibrt             -> "use-lib-rt"
+            UseLibdl             -> "use-lib-dl"
+            UseLibbfd            -> "use-lib-bfd"
+            UseLibpthread        -> "use-lib-pthread"
+            NeedLibatomic        -> "need-libatomic"
     value <- lookupSystemConfig key
     when (value `notElem` ["YES", "NO", ""]) . error $ "Configuration flag "
         ++ quote (key ++ " = " ++ value) ++ " cannot be parsed."


=====================================
hadrian/src/Oracles/Setting.hs
=====================================
@@ -65,6 +65,7 @@ data Setting = BuildArch
              | ProjectName
              | ProjectVersion
              | ProjectVersionInt
+             | ProjectVersionMunged
              | ProjectPatchLevel
              | ProjectPatchLevel1
              | ProjectPatchLevel2
@@ -165,6 +166,7 @@ setting key = lookupSystemConfig $ case key of
     ProjectGitCommitId -> "project-git-commit-id"
     ProjectName        -> "project-name"
     ProjectVersion     -> "project-version"
+    ProjectVersionMunged -> "project-version-munged"
     ProjectVersionInt  -> "project-version-int"
     ProjectPatchLevel  -> "project-patch-level"
     ProjectPatchLevel1 -> "project-patch-level1"


=====================================
hadrian/src/Rules.hs
=====================================
@@ -130,6 +130,7 @@ buildRules = do
     Rules.BinaryDist.bindistRules
     Rules.Generate.copyRules
     Rules.Generate.generateRules
+    Rules.Generate.templateRules
     Rules.Gmp.gmpRules
     Rules.Libffi.libffiRules
     Rules.Library.libraryRules


=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -1,7 +1,8 @@
 module Rules.Generate (
     isGeneratedCmmFile, compilerDependencies, generatePackageCode,
     generateRules, copyRules, generatedDependencies,
-    ghcPrimDependencies
+    ghcPrimDependencies,
+    templateRules
     ) where
 
 import qualified Data.Set as Set
@@ -225,6 +226,72 @@ emptyTarget :: Context
 emptyTarget = vanillaContext (error "Rules.Generate.emptyTarget: unknown stage")
                              (error "Rules.Generate.emptyTarget: unknown package")
 
+-- | Files generated by query-replace from a template
+templateResults :: [FilePath]
+templateResults =
+    [ "compiler/ghc.cabal"
+    , "rts/rts.cabal"
+    , "driver/ghci/ghci-wrapper.cabal"
+    , "ghc/ghc-bin.cabal"
+    , "utils/iserv/iserv.cabal"
+    , "utils/iserv-proxy/iserv-proxy.cabal"
+    , "utils/remote-iserv/remote-iserv.cabal"
+    , "utils/runghc/runghc.cabal"
+    , "libraries/ghc-boot/ghc-boot.cabal"
+    , "libraries/ghc-boot-th/ghc-boot-th.cabal"
+    , "libraries/ghci/ghci.cabal"
+    , "libraries/ghc-heap/ghc-heap.cabal"
+    , "utils/ghc-pkg/ghc-pkg.cabal"
+    , "libraries/libiserv/libiserv.cabal"
+    , "libraries/template-haskell/template-haskell.cabal"
+    , "libraries/prologue.txt"
+    ]
+
+templateRules :: Rules ()
+templateRules = do
+  templateResults |%> \out -> do
+    let settingWord :: Setting -> Action Word
+        settingWord s = read <$> setting s
+
+    project_version        <- setting ProjectVersion
+    project_version_munged <- setting ProjectVersionMunged
+    target_word_size       <- settingWord TargetWordSize
+    lib_dw                 <- flag UseLibdw
+    lib_numa               <- flag UseLibnuma
+    lib_mingwex            <- flag UseLibmingwex
+    lib_m                  <- flag UseLibm
+    lib_rt                 <- flag UseLibrt
+    lib_dl                 <- flag UseLibdl
+    lib_ffi                <- flag UseSystemFfi
+    lib_ffi_adjustors      <- flag UseLibffiForAdjustors
+    lib_bfd                <- flag UseLibbfd
+    lib_pthread            <- flag UseLibpthread
+    leading_underscore     <- flag LeadingUnderscore
+    need_libatomic         <- flag NeedLibatomic
+
+    let cabal_bool True  = "True"
+        cabal_bool False = "False"
+
+        subst = replace "@ProjectVersion@" project_version
+                . replace "@ProjectVersionMunged@" project_version_munged
+                . replace "@Cabal64bit@" (cabal_bool (target_word_size == 8))
+                . replace "@CabalMingwex@" (cabal_bool lib_mingwex)
+                . replace "@CabalHaveLibdw@" (cabal_bool lib_dw)
+                . replace "@CabalHaveLibm@" (cabal_bool lib_m)
+                . replace "@CabalHaveLibrt@" (cabal_bool lib_rt)
+                . replace "@CabalHaveLibdl@" (cabal_bool lib_dl)
+                . replace "@CabalUseSystemLibFFI@" (cabal_bool lib_ffi)
+                . replace "@CabalLibffiAdjustors@" (cabal_bool lib_ffi_adjustors)
+                . replace "@CabalNeedLibpthread@" (cabal_bool lib_pthread)
+                . replace "@CabalHaveLibbfd@" (cabal_bool lib_bfd)
+                . replace "@CabalHaveLibNuma@" (cabal_bool lib_numa)
+                . replace "@CabalLeadingUnderscore@" (cabal_bool leading_underscore)
+                . replace "@CabalNeedLibatomic@" (cabal_bool need_libatomic)
+
+    s <- readFile' (out <.> "in")
+    writeFile' out (subst s)
+    putSuccess ("| Successfully generated " ++ out ++ " from its template")
+
 -- Generators
 
 -- | GHC wrapper scripts used for passing the path to the right package database
@@ -353,7 +420,7 @@ generateSettings = do
         , ("Tables next to code", expr $ yesNo <$> flag TablesNextToCode)
         , ("Leading underscore", expr $ yesNo <$> flag LeadingUnderscore)
         , ("Use LibFFI", expr $ yesNo <$> useLibffiForAdjustors)
-        , ("RTS expects libdw", yesNo <$> getFlag WithLibdw)
+        , ("RTS expects libdw", yesNo <$> getFlag UseLibdw)
         ]
     let showTuple (k, v) = "(" ++ show k ++ ", " ++ show v ++ ")"
     pure $ case settings of


=====================================
hadrian/src/Settings/Packages.hs
=====================================
@@ -403,8 +403,8 @@ rtsPackageArgs = package rts ? do
         , builder HsCpp ? pure
           [ "-DTOP="             ++ show top ]
 
-        , builder HsCpp ? flag WithLibdw ? arg "-DUSE_LIBDW"
-        , builder HsCpp ? flag HaveLibMingwEx ? arg "-DHAVE_LIBMINGWEX" ]
+        , builder HsCpp ? flag UseLibdw ? arg "-DUSE_LIBDW"
+        , builder HsCpp ? flag UseLibmingwex ? arg "-DHAVE_LIBMINGWEX" ]
 
 -- Compile various performance-critical pieces *without* -fPIC -dynamic
 -- even when building a shared library.  If we don't do this, then the


=====================================
m4/fp_bfd_support.m4
=====================================
@@ -2,7 +2,7 @@
 # ----------------------
 # whether to use libbfd for debugging RTS
 AC_DEFUN([FP_BFD_SUPPORT], [
-    AC_SUBST([CabalHaveLibbfd], [False])
+    HaveLibbfd=NO
     AC_ARG_ENABLE(bfd-debug,
         [AS_HELP_STRING([--enable-bfd-debug],
               [Enable symbol resolution for -debug rts ('+RTS -Di') via binutils' libbfd [default=no]])],
@@ -40,9 +40,10 @@ AC_DEFUN([FP_BFD_SUPPORT], [
                                     bfd_get_symbol_info(abfd,symbol_table[0],&info);
                                 }
                         ]])],
-                        [AC_SUBST([CabalHaveLibbfd], [True])],dnl bfd seems to work
+                        HaveLibbfd=YES,dnl bfd seems to work
                         [AC_MSG_ERROR([can't use 'bfd' library])])
             LIBS="$save_LIBS"
         ]
     )
+    AC_SUBST([UseLibbfd],[$HaveLibbfd])
 ])


=====================================
m4/fp_cc_supports__atomics.m4
=====================================
@@ -63,9 +63,9 @@ AC_DEFUN([FP_CC_SUPPORTS__ATOMICS],
     ])
     AC_DEFINE([HAVE_C11_ATOMICS], [1], [Does C compiler support __atomic primitives?])
     if test "$need_latomic" = 1; then
-        AC_SUBST([CabalNeedLibatomic],[True])
+        AC_SUBST([NeedLibatomic],[YES])
     else
-        AC_SUBST([CabalNeedLibatomic],[False])
+        AC_SUBST([NeedLibatomic],[NO])
     fi
     AC_DEFINE_UNQUOTED([NEED_ATOMIC_LIB], [$need_latomic],
         [Define to 1 if we need -latomic.])


=====================================
m4/fp_check_pthreads.m4
=====================================
@@ -12,18 +12,18 @@ AC_DEFUN([FP_CHECK_PTHREADS],
   AC_CHECK_FUNC(pthread_create,
       [
           AC_MSG_RESULT(no)
-          AC_SUBST([CabalNeedLibpthread],[False])
+          AC_SUBST([UseLibpthread],[NO])
           need_lpthread=0
       ],
       [
           AC_CHECK_LIB(pthread, pthread_create,
               [
                   AC_MSG_RESULT(yes)
-                  AC_SUBST([CabalNeedLibpthread],[True])
+                  AC_SUBST([UseLibpthread],[YES])
                   need_lpthread=1
               ],
               [
-                  AC_SUBST([CabalNeedLibpthread],[False])
+                  AC_SUBST([UseLibpthread],[NO])
                   AC_MSG_RESULT([no pthreads support found.])
                   need_lpthread=0
               ])



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b5c714545abc5f75a1ffdcc39b4bfdc7cd5e64b4
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/20221123/9fa6e31a/attachment-0001.html>


More information about the ghc-commits mailing list