diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2021-05-12 10:59:15 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-11-23 12:46:35 -0500 |
commit | b5c714545abc5f75a1ffdcc39b4bfdc7cd5e64b4 (patch) | |
tree | 46721c2ca167a8295fb70600b102ccc26aac7b02 | |
parent | e153851650bbba631f3a6926ba42422f9f1fa0cd (diff) | |
download | haskell-b5c714545abc5f75a1ffdcc39b4bfdc7cd5e64b4.tar.gz |
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.
-rw-r--r-- | configure.ac | 54 | ||||
-rw-r--r-- | hadrian/cfg/system.config.in | 27 | ||||
-rw-r--r-- | hadrian/src/Oracles/Flag.hs | 24 | ||||
-rw-r--r-- | hadrian/src/Oracles/Setting.hs | 2 | ||||
-rw-r--r-- | hadrian/src/Rules.hs | 1 | ||||
-rw-r--r-- | hadrian/src/Rules/Generate.hs | 71 | ||||
-rw-r--r-- | hadrian/src/Settings/Packages.hs | 4 | ||||
-rw-r--r-- | m4/fp_bfd_support.m4 | 5 | ||||
-rw-r--r-- | m4/fp_cc_supports__atomics.m4 | 4 | ||||
-rw-r--r-- | m4/fp_check_pthreads.m4 | 6 |
10 files changed, 132 insertions, 66 deletions
diff --git a/configure.ac b/configure.ac index bf4f597572..b5855f4ef0 100644 --- a/configure.ac +++ b/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 ]) diff --git a/hadrian/cfg/system.config.in b/hadrian/cfg/system.config.in index 0541d90138..78f66df02f 100644 --- a/hadrian/cfg/system.config.in +++ b/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@ diff --git a/hadrian/src/Oracles/Flag.hs b/hadrian/src/Oracles/Flag.hs index 37f675b5e8..a929b77e68 100644 --- a/hadrian/src/Oracles/Flag.hs +++ b/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." diff --git a/hadrian/src/Oracles/Setting.hs b/hadrian/src/Oracles/Setting.hs index dca0861869..28926c7763 100644 --- a/hadrian/src/Oracles/Setting.hs +++ b/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" diff --git a/hadrian/src/Rules.hs b/hadrian/src/Rules.hs index 8c65f471a7..7cfeb65e5a 100644 --- a/hadrian/src/Rules.hs +++ b/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 diff --git a/hadrian/src/Rules/Generate.hs b/hadrian/src/Rules/Generate.hs index c41b6eed8f..a44ca510d2 100644 --- a/hadrian/src/Rules/Generate.hs +++ b/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 diff --git a/hadrian/src/Settings/Packages.hs b/hadrian/src/Settings/Packages.hs index b6ba1e94ff..e99e639eb8 100644 --- a/hadrian/src/Settings/Packages.hs +++ b/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 diff --git a/m4/fp_bfd_support.m4 b/m4/fp_bfd_support.m4 index 89c051253f..2f357820f7 100644 --- a/m4/fp_bfd_support.m4 +++ b/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]) ]) diff --git a/m4/fp_cc_supports__atomics.m4 b/m4/fp_cc_supports__atomics.m4 index f4a2eaff7c..bd3750e972 100644 --- a/m4/fp_cc_supports__atomics.m4 +++ b/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.]) diff --git a/m4/fp_check_pthreads.m4 b/m4/fp_check_pthreads.m4 index ee5b364e93..5713e7c743 100644 --- a/m4/fp_check_pthreads.m4 +++ b/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 ]) |