[Git][ghc/ghc][wip/ghc-toolchain-fixes] 3 commits: Using more user options

Matthew Pickering (@mpickering) gitlab at gitlab.haskell.org
Mon Aug 7 13:11:45 UTC 2023



Matthew Pickering pushed to branch wip/ghc-toolchain-fixes at Glasgow Haskell Compiler / GHC


Commits:
a9eed1d6 by Rodrigo Mesquita at 2023-07-28T11:22:10+01:00
Using more user options

- - - - -
e258d98a by Matthew Pickering at 2023-08-07T12:21:14+01:00
ghc-toolchain: Add format mode to normalise differences before diffing.

The "format" mode takes an "--input" and "--ouput" target file and
formats it.

This is intended to be useful on windows where the
configure/ghc-toolchain target files can't be diffed very easily because
the path separators are different.

- - - - -
1cc515b2 by Matthew Pickering at 2023-08-07T14:09:34+01:00
ghc-toolchain: Bump ci-images commit to get new ghc-wasm-meta

We needed to remove -Wno-unused-command-line-argument from the arguments
passed in order for the configure check to report correctly.

See https://gitlab.haskell.org/ghc/ghc/-/merge_requests/10976#note_516335

- - - - -


5 changed files:

- .gitlab-ci.yml
- configure.ac
- distrib/configure.ac.in
- m4/ghc_toolchain.m4
- utils/ghc-toolchain/exe/Main.hs


Changes:

=====================================
.gitlab-ci.yml
=====================================
@@ -2,7 +2,7 @@ variables:
   GIT_SSL_NO_VERIFY: "1"
 
   # Commit of ghc/ci-images repository from which to pull Docker images
-  DOCKER_REV: a9c0f5efbe503c17f63070583b2d815e498acc68
+  DOCKER_REV: 17f816b010d4e585d3a935530ea3d1fc743eac0d
 
   # Sequential version number of all cached things.
   # Bump to invalidate GitLab CI cache.


=====================================
configure.ac
=====================================
@@ -49,7 +49,11 @@ USER_CFLAGS="$CFLAGS"
 USER_LDFLAGS="$LDFLAGS"
 USER_LIBS="$LIBS"
 USER_CXXFLAGS="$CXXFLAGS"
-
+dnl The lower-level/not user-facing environment variables that may still be set
+dnl by developers such as in ghc-wasm-meta
+USER_CONF_CC_OPTS_STAGE2="$CONF_CC_OPTS_STAGE2"
+USER_CONF_CXX_OPTS_STAGE2="$CONF_CXX_OPTS_STAGE2"
+USER_CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2"
 
 dnl ----------------------------------------------------------
 dnl ** Find unixy sort and find commands,
@@ -1193,8 +1197,9 @@ checkMake380 make
 checkMake380 gmake
 
 # Toolchain target files
+FIND_GHC_TOOLCHAIN_BIN([NO])
 PREP_TARGET_FILE
-FIND_GHC_TOOLCHAIN([hadrian/cfg],[NO])
+FIND_GHC_TOOLCHAIN([hadrian/cfg])
 
 AC_CONFIG_FILES(
 [ mk/project.mk
@@ -1332,3 +1337,5 @@ For more information on how to configure your GHC build, see
 
 VALIDATE_GHC_TOOLCHAIN([hadrian/cfg/default.target],[hadrian/cfg/default.target.ghc-toolchain])
 
+rm -Rf acargs acghc-toolchain actmp-ghc-toolchain
+


=====================================
distrib/configure.ac.in
=====================================
@@ -311,11 +311,14 @@ checkMake380 make
 checkMake380 gmake
 
 # Toolchain target files
+FIND_GHC_TOOLCHAIN_BIN([YES])
 PREP_TARGET_FILE
-FIND_GHC_TOOLCHAIN([.],[YES])
+FIND_GHC_TOOLCHAIN([.])
 
 VALIDATE_GHC_TOOLCHAIN([default.target],[default.target.ghc-toolchain])
 
+rm -Rf acargs acghc-toolchain actmp-ghc-toolchain
+
 echo "****************************************************"
 echo "Configuration done, ready to 'make install'"
 echo "(see README and INSTALL files for more info.)"


=====================================
m4/ghc_toolchain.m4
=====================================
@@ -8,6 +8,18 @@ AC_DEFUN([ADD_GHC_TOOLCHAIN_ARG],
     done
 ])
 
+dnl $1 argument name
+dnl $2 first variable to try
+dnl $3 variable to add if the first variable is empty
+AC_DEFUN([ADD_GHC_TOOLCHAIN_ARG_CHOOSE],
+[
+    if test -z "$2"; then
+        ADD_GHC_TOOLCHAIN_ARG([$1],[$3])
+    else
+        ADD_GHC_TOOLCHAIN_ARG([$1],[$2])
+    fi
+])
+
 AC_DEFUN([ENABLE_GHC_TOOLCHAIN_ARG],
 [
     if test "$2" = "YES"; then
@@ -48,31 +60,8 @@ AC_DEFUN([INVOKE_GHC_TOOLCHAIN],
 ])
 
 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],
 [
-    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
@@ -124,27 +113,52 @@ AC_DEFUN([FIND_GHC_TOOLCHAIN],
     ENABLE_GHC_TOOLCHAIN_ARG([libffi-adjustors], [$UseLibffiForAdjustors])
 
     dnl We store USER_* variants of all user-specified flags to pass them over to ghc-toolchain.
-    ADD_GHC_TOOLCHAIN_ARG([cc-opt], [$USER_CFLAGS])
-    ADD_GHC_TOOLCHAIN_ARG([cc-link-opt], [$USER_LDFLAGS])
+    ADD_GHC_TOOLCHAIN_ARG_CHOOSE([cc-opt], [$USER_CONF_CC_OPTS_STAGE2], [$USER_CFLAGS])
+    ADD_GHC_TOOLCHAIN_ARG_CHOOSE([cc-link-opt], [$USER_CONF_GCC_LINKER_OPTS_STAGE2], [$USER_LDFLAGS])
     ADD_GHC_TOOLCHAIN_ARG([cc-link-opt], [$USER_LIBS])
-    ADD_GHC_TOOLCHAIN_ARG([cxx-opt], [$USER_CXXFLAGS])
+    ADD_GHC_TOOLCHAIN_ARG_CHOOSE([cxx-opt], [$USER_CONF_CXX_OPTS_STAGE2], [$USER_CXXFLAGS])
     ADD_GHC_TOOLCHAIN_ARG([cpp-opt], [$USER_CPP_ARGS])
     ADD_GHC_TOOLCHAIN_ARG([hs-cpp-opt], [$USER_HS_CPP_ARGS])
 
     INVOKE_GHC_TOOLCHAIN()
 
-    rm -Rf acargs acghc-toolchain actmp-ghc-toolchain
-
     dnl Note: if we weren't passing the paths to the programs explicitly, to make
     dnl ghc-toolchain use the bundled windows toolchain, simply add it to the search PATH
 ])
 
 
+dnl $1 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_BIN],[
+    case "$1" 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
+])
+
+
 dnl Note [ghc-toolchain consistency checking]
 dnl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 dnl ghc-toolchain is the brand new way (2023) to configure toolchains for GHC,
 dnl but this novelty musn't break user's installations, so we still
-dnl conservatively use the toolchains configured by configure (see also m4/prep_target_file.m4).
+dnl conservatively use the toolchains configured by configure (see also m4/tprep_target_file.m4).
 dnl
 dnl However, we already ship and run ghc-toolchain at configure time to /validate/ ghc-toolchain:
 dnl * PREP_TARGET_FILE substitutes the toolchain into default.target.in and default.host.target.in
@@ -159,7 +173,11 @@ dnl files generated by ghc-toolchain instead).
 dnl $1 like "default.target"
 dnl $2 like "default.target.ghc-toolchain"
 AC_DEFUN([VALIDATE_GHC_TOOLCHAIN],[
-    diff_output=`diff "$1" "$2" 2>&1`
+    o1=$(mktemp)
+    o2=$(mktemp)
+    "$GHC_TOOLCHAIN_BIN" format --input="$1" --output="$o1"
+    "$GHC_TOOLCHAIN_BIN" format --input="$2" --output="$o2"
+    diff_output=`diff "$o1" "$o2" 2>&1`
     if test -z "$diff_output"; then
       true
     else


=====================================
utils/ghc-toolchain/exe/Main.hs
=====================================
@@ -1,5 +1,6 @@
 {-# LANGUAGE NamedFieldPuns #-}
 {-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE TypeApplications #-}
 
 module Main where
 
@@ -10,6 +11,7 @@ import System.Exit
 import System.Console.GetOpt
 import System.Environment
 import System.FilePath ((</>))
+import qualified System.IO (readFile, writeFile)
 
 import GHC.Platform.ArchOS
 
@@ -55,6 +57,22 @@ data Opts = Opts
     , optKeepTemp  :: Bool
     }
 
+data FormatOpts = FormatOpts
+    { formatOptInput :: FilePath
+    , formatOptOutput :: FilePath
+    }
+
+_formatOptOutput :: Lens FormatOpts String
+_formatOptOutput = Lens formatOptOutput (\x o -> o {formatOptOutput=x})
+
+_formatOptInput :: Lens FormatOpts String
+_formatOptInput = Lens formatOptInput (\x o -> o {formatOptInput=x})
+
+emptyFormatOpts :: FormatOpts
+emptyFormatOpts = FormatOpts { formatOptInput = error "formatOpts: input"
+                             , formatOptOutput = error "formatOpts: output"
+                             }
+
 emptyOpts :: Opts
 emptyOpts = Opts
     { optTriple    = ""
@@ -202,10 +220,41 @@ options =
     outputOpt = Option ['o'] ["output"] (ReqArg (set _optOutput) "OUTPUT")
         "The output path for the generated target toolchain configuration"
 
+formatOpts :: [OptDescr (FormatOpts -> FormatOpts)]
+formatOpts = [
+    (Option ['o'] ["output"] (ReqArg (set _formatOptOutput) "OUTPUT")
+        "The output path for the formatted target toolchain configuration")
+    , (Option ['i'] ["input"] (ReqArg (set _formatOptInput) "INPUT")
+        "The target file to format")
+    ]
+
 main :: IO ()
 main = do
     argv <- getArgs
-    let (opts0, _nonopts, errs) = getOpt RequireOrder options argv
+    case argv of
+      ("format": args) -> doFormat args
+      _ -> doConfigure argv
+
+-- The format mode is very useful for normalising paths and newlines on windows.
+doFormat :: [String] -> IO ()
+doFormat args = do
+  let (opts0, _nonopts, errs) = getOpt RequireOrder formatOpts args
+  case errs of
+    [] -> do
+      let opts = foldr (.) id opts0 emptyFormatOpts
+      tgt <- read @Target <$> System.IO.readFile (view _formatOptInput opts)
+      let file = formatOptOutput opts
+      System.IO.writeFile file (show tgt)
+    _ -> do
+      mapM_ putStrLn errs
+      putStrLn $ usageInfo "ghc-toolchain" formatOpts
+      exitWith (ExitFailure 1)
+
+
+
+doConfigure :: [String] -> IO ()
+doConfigure args = do
+    let (opts0, _nonopts, errs) = getOpt RequireOrder options args
     let opts = foldr (.) id opts0 emptyOpts
     case errs of
       [] -> do



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f06e2993d54c67de0d1f011d54700703a32351ae...1cc515b21acb68006f43a03002dd5949f71a1972

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f06e2993d54c67de0d1f011d54700703a32351ae...1cc515b21acb68006f43a03002dd5949f71a1972
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/20230807/dfca7403/attachment-0001.html>


More information about the ghc-commits mailing list