[Git][ghc/ghc][wip/toolchain-selection] Ship ghc-toolchain in the bindist

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Wed Jul 19 15:47:12 UTC 2023



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


Commits:
ee2810e2 by Rodrigo Mesquita at 2023-07-19T16:46:55+01:00
Ship ghc-toolchain in the bindist

Add the ghc-toolchain binary to the binary distribution we ship to
users, and teach the bindist configure to use the existing ghc-toolchain.

- - - - -


9 changed files:

- configure.ac
- distrib/configure.ac.in
- hadrian/src/Packages.hs
- hadrian/src/Settings/Default.hs
- m4/ghc_toolchain.m4
- utils/ghc-toolchain/src/GHC/Toolchain/CheckArm.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Ar.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/MergeObjs.hs


Changes:

=====================================
configure.ac
=====================================
@@ -1177,7 +1177,7 @@ checkMake380 gmake
 
 # Toolchain target files
 PREP_TARGET_FILE
-FIND_GHC_TOOLCHAIN([hadrian/cfg])
+FIND_GHC_TOOLCHAIN([hadrian/cfg],[NO])
 
 AC_CONFIG_FILES(
 [ mk/project.mk


=====================================
distrib/configure.ac.in
=====================================
@@ -312,7 +312,7 @@ checkMake380 gmake
 
 # Toolchain target files
 PREP_TARGET_FILE
-FIND_GHC_TOOLCHAIN([.])
+FIND_GHC_TOOLCHAIN([.],[YES])
 
 VALIDATE_GHC_TOOLCHAIN([default.target],[default.target.ghc-toolchain])
 


=====================================
hadrian/src/Packages.hs
=====================================
@@ -5,7 +5,8 @@ module Packages (
     checkExact, countDeps,
     compareSizes, compiler, containers, deepseq, deriveConstants, directory, dumpDecls,
     exceptions, filepath, genapply, genprimopcode, ghc, ghcBignum, ghcBoot, ghcBootTh, ghcPlatform,
-    ghcCompact, ghcConfig, ghcHeap, ghci, ghciWrapper, ghcPkg, ghcPrim, haddock, haskeline,
+    ghcCompact, ghcConfig, ghcHeap, ghci, ghciWrapper, ghcPkg, ghcPrim, ghcToolchain, ghcToolchainBin,
+    haddock, haskeline,
     hsc2hs, hp2ps, hpc, hpcBin, integerGmp, integerSimple, iserv, iservProxy,
     libffi, mtl, parsec, pretty, primitive, process, remoteIserv, rts,
     runGhc, semaphoreCompat, stm, templateHaskell, terminfo, text, time, timeout, touchy,
@@ -37,7 +38,8 @@ ghcPackages =
     [ array, base, binary, bytestring, cabalSyntax, cabal, checkPpr, checkExact, countDeps
     , compareSizes, compiler, containers, deepseq, deriveConstants, directory, dumpDecls
     , exceptions, filepath, genapply, genprimopcode, ghc, ghcBignum, ghcBoot, ghcBootTh, ghcPlatform
-    , ghcCompact, ghcConfig, ghcHeap, ghci, ghciWrapper, ghcPkg, ghcPrim, haddock, haskeline, hsc2hs
+    , ghcCompact, ghcConfig, ghcHeap, ghci, ghciWrapper, ghcPkg, ghcPrim, ghcToolchain, ghcToolchainBin
+    , haddock, haskeline, hsc2hs
     , hp2ps, hpc, hpcBin, integerGmp, integerSimple, iserv, libffi, mtl
     , parsec, pretty, process, rts, runGhc, stm, semaphoreCompat, templateHaskell
     , terminfo, text, time, touchy, transformers, unlit, unix, win32, xhtml
@@ -53,7 +55,8 @@ isGhcPackage = (`elem` ghcPackages)
 array, base, binary, bytestring, cabalSyntax, cabal, checkPpr, checkExact, countDeps,
   compareSizes, compiler, containers, deepseq, deriveConstants, directory, dumpDecls,
   exceptions, filepath, genapply, genprimopcode, ghc, ghcBignum, ghcBoot, ghcBootTh, ghcPlatform,
-  ghcCompact, ghcConfig, ghcHeap, ghci, ghciWrapper, ghcPkg, ghcPrim, haddock, haskeline, hsc2hs,
+  ghcCompact, ghcConfig, ghcHeap, ghci, ghciWrapper, ghcPkg, ghcPrim, ghcToolchain,
+  haddock, haskeline, hsc2hs,
   hp2ps, hpc, hpcBin, integerGmp, integerSimple, iserv, iservProxy, remoteIserv, libffi, mtl,
   parsec, pretty, primitive, process, rts, runGhc, semaphoreCompat, stm, templateHaskell,
   terminfo, text, time, touchy, transformers, unlit, unix, win32, xhtml,
@@ -93,6 +96,8 @@ ghciWrapper         = prg  "ghci-wrapper"    `setPath` "driver/ghci"
                       -- See Note [Hadrian's ghci-wrapper package]
 ghcPkg              = util "ghc-pkg"
 ghcPrim             = lib  "ghc-prim"
+ghcToolchain        = lib  "ghc-toolchain"     `setPath` "utils/ghc-toolchain"
+ghcToolchainBin     = prg  "ghc-toolchain-bin" `setPath` "utils/ghc-toolchain/exe" -- workaround for #23690
 haddock             = util "haddock"
 haskeline           = lib  "haskeline"
 hsc2hs              = util "hsc2hs"


=====================================
hadrian/src/Settings/Default.hs
=====================================
@@ -87,6 +87,7 @@ stage0Packages = do
              , ghcBootTh
              , ghcPlatform
              , ghcHeap
+             , ghcToolchain
              , ghci
              , ghcPkg
              , haddock
@@ -154,6 +155,7 @@ stage1Packages = do
         , hpcBin
         , iserv
         , runGhc
+        , ghcToolchainBin
         ]
       , when (winTarget && not cross)
         [ touchy


=====================================
m4/ghc_toolchain.m4
=====================================
@@ -33,21 +33,38 @@ AC_DEFUN([INVOKE_GHC_TOOLCHAIN],
         while read -r arg; do
             set -- "[$]@" "$arg"
         done
-        # For now, we don't exit even if ghc-toolchain fails. We don't want to
+        # For now, we don't 'exit' even if ghc-toolchain fails. We don't want to
         # fail configure due to it, since the target file is still being generated by configure.
-        ./acghc-toolchain -v2 "[$]@" # || exit 1
-        python3 -c 'import sys; print(sys.argv)' "[$]@"
-    ) <acargs || exit 1
+        "$GHC_TOOLCHAIN_BIN" -v2 "[$]@"
+    ) <acargs
 ])
 
 dnl $1 is the path to the directory where to put the configured default.host.target.ghc-toolchain and default.target.ghc-toolchain
+dnl $2 is YES or NO,
+dnl     * YES means we're calling GHC_TOOLCHAIN from the bindist configure script,
+dnl         and that ghc-toolchain is already an available binary
+dnl     * NO means we're calling GHC_TOOLCHAIN from the source tree configure script,
+dnl         and that we must compile ghc-toolchain before invoking it
 AC_DEFUN([FIND_GHC_TOOLCHAIN],
 [
-    "$GHC" -v0 \
-        -ilibraries/ghc-platform/src -iutils/ghc-toolchain/src \
-        -XNoImplicitPrelude \
-        -odir actmp-ghc-toolchain -hidir actmp-ghc-toolchain \
-        utils/ghc-toolchain/exe/Main.hs -o acghc-toolchain
+    case "$2" in
+        YES)
+            # We're configuring the bindist, and the binary is already available
+            GHC_TOOLCHAIN_BIN="bin/ghc-toolchain-bin"
+            ;;
+        NO)
+            # We're in the source tree, so compile ghc-toolchain
+            "$GHC" -v0 \
+                -ilibraries/ghc-platform/src -iutils/ghc-toolchain/src \
+                -XNoImplicitPrelude \
+                -odir actmp-ghc-toolchain -hidir actmp-ghc-toolchain \
+                utils/ghc-toolchain/exe/Main.hs -o acghc-toolchain
+            GHC_TOOLCHAIN_BIN="./acghc-toolchain"
+            ;;
+        *)
+            AC_MSG_ERROR([In m4/ghc_toolchain.m4, expecting $2 to be either YES or NO.])
+            ;;
+    esac
 
     # (1) Configure a toolchain for the build and host platform (we require that BUILD=HOST, so one toolchain suffices)
     rm -f acargs


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/CheckArm.hs
=====================================
@@ -1,6 +1,6 @@
 module GHC.Toolchain.CheckArm ( findArmIsa ) where
 
-import Data.List
+import Data.List (isInfixOf)
 import Data.Maybe (catMaybes)
 import Control.Monad.IO.Class
 import System.Process


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Ar.hs
=====================================
@@ -5,7 +5,7 @@ module GHC.Toolchain.Tools.Ar (Ar(..), findAr) where
 
 import Control.Monad
 import System.FilePath
-import Data.List
+import Data.List (isInfixOf)
 
 import GHC.Toolchain.Prelude
 import GHC.Toolchain.Utils


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs
=====================================
@@ -6,7 +6,7 @@
 module GHC.Toolchain.Tools.Link ( CcLink(..), findCcLink ) where
 
 import Control.Monad (when)
-import Data.List
+import Data.List (isInfixOf)
 import System.FilePath
 
 import GHC.Platform.ArchOS


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/MergeObjs.hs
=====================================
@@ -4,7 +4,7 @@
 module GHC.Toolchain.Tools.MergeObjs ( MergeObjs(..), findMergeObjs ) where
 
 import Control.Monad
-import Data.List
+import Data.List (isInfixOf)
 import System.FilePath
 
 import GHC.Toolchain.Prelude



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ee2810e264c396429706bf0883863e9286d15d23
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/20230719/be59ea25/attachment-0001.html>


More information about the ghc-commits mailing list