[Git][ghc/ghc][wip/hadrian-cross-stage2] 5 commits: ci: Javascript don't set CROSS_EMULATOR

Matthew Pickering (@mpickering) gitlab at gitlab.haskell.org
Thu Sep 26 10:36:45 UTC 2024



Matthew Pickering pushed to branch wip/hadrian-cross-stage2 at Glasgow Haskell Compiler / GHC


Commits:
9f1f924f by Matthew Pickering at 2024-09-26T10:48:04+01:00
ci: Javascript don't set CROSS_EMULATOR

There is no CROSS_EMULATOR needed to run javascript binaries, so we
don't set the CROSS_EMULATOR to some dummy value.

- - - - -
5019b35d by Matthew Pickering at 2024-09-26T10:48:04+01:00
ci: Introduce CROSS_STAGE variable

In preparation for building and testing stage3 bindists we introduce the
CROSS_STAGE variable which is used by a CI job to determine what kind of
bindist the CI job should produce.

At the moment we are only using CROSS_STAGE=2 but in the future we will
have some jobs which set CROSS_STAGE=3 to produce native bindists for a
target, but produced by a cross compiler, which can be tested on by
another CI job on the native platform.

CROSS_STAGE=2: Build a normal cross compiler bindist
CROSS_STAGE=3: Build a stage 3 bindist, one which is a native compiler and library for the target

- - - - -
61f3fa32 by Matthew Pickering at 2024-09-26T10:48:04+01:00
Split up system.config into host/target config files

There were a number of settings which were not applied per-stage, for
example if you specified `--ffi-include-dir` then that was applied to
both host and target. Now this will just be passed when building the
crosscompiler.

The solution for now is to separate these two files into host/target and
the host file contains very bare-bones . There isn't currently a way to
specify with configure anything in the host file, so if you are building
a cross-compiler and you need to do that, you have to modify the file
yourself.

- - - - -
676a4b04 by Matthew Pickering at 2024-09-26T10:48:04+01:00
wip fixup

- - - - -
4a8b0a9a by Matthew Pickering at 2024-09-26T11:33:06+01:00
Fix location of emsdk-version

- - - - -


26 changed files:

- .gitlab/ci.sh
- .gitlab/generate-ci/gen_ci.hs
- .gitlab/jobs.yaml
- configure.ac
- hadrian/README.md
- + hadrian/cfg/system.config.host.in
- hadrian/cfg/system.config.in
- + hadrian/cfg/system.config.target.in
- hadrian/src/Base.hs
- hadrian/src/Builder.hs
- hadrian/src/Expression.hs
- hadrian/src/Hadrian/Oracles/TextFile.hs
- hadrian/src/Oracles/Flag.hs
- hadrian/src/Oracles/Setting.hs
- hadrian/src/Oracles/TestSettings.hs
- hadrian/src/Rules/Generate.hs
- hadrian/src/Rules/Gmp.hs
- hadrian/src/Rules/Libffi.hs
- hadrian/src/Rules/Rts.hs
- hadrian/src/Settings/Builders/Cabal.hs
- hadrian/src/Settings/Builders/Common.hs
- hadrian/src/Settings/Builders/Ghc.hs
- hadrian/src/Settings/Builders/Hsc2Hs.hs
- hadrian/src/Settings/Builders/RunTest.hs
- hadrian/src/Settings/Packages.hs
- hadrian/src/Settings/Warnings.hs


Changes:

=====================================
.gitlab/ci.sh
=====================================
@@ -58,6 +58,9 @@ Hadrian build system
 Environment variables affecting both build systems:
 
   CROSS_TARGET      Triple of cross-compilation target.
+  CROSS_STAGE       The stage of the cross-compiler to build either
+                      * 2: Build a normal cross-compiler bindist
+                      * 3: Build a target executable bindist (with the stage2 cross-compiler)
   VERBOSE           Set to non-empty for verbose build output
   RUNTEST_ARGS      Arguments passed to runtest.py
   MSYSTEM           (Windows-only) Which platform to build from (CLANG64).
@@ -496,6 +499,12 @@ function build_hadrian() {
     export XZ_OPT="${XZ_OPT:-} -T$cores"
   fi
 
+  case "${CROSS_STAGE:-2}" in
+    2) BINDIST_TARGET="binary-dist";;
+    3) BINDIST_TARGET="binary-dist-stage3";;
+    *) fail "Unknown CROSS_STAGE, must be 2 or 3";;
+  esac
+
   if [[ -n "${REINSTALL_GHC:-}" ]]; then
     run_hadrian build-cabal -V
   else
@@ -505,7 +514,7 @@ function build_hadrian() {
           mv _build/reloc-bindist/ghc*.tar.xz "$BIN_DIST_NAME.tar.xz"
           ;;
         *)
-          run_hadrian test:all_deps binary-dist -V
+          run_hadrian test:all_deps $BINDIST_TARGET
           mv _build/bindist/ghc*.tar.xz "$BIN_DIST_NAME.tar.xz"
           ;;
     esac


=====================================
.gitlab/generate-ci/gen_ci.hs
=====================================
@@ -147,6 +147,7 @@ data BuildConfig
                 , withNuma       :: Bool
                 , withZstd       :: Bool
                 , crossTarget    :: Maybe String
+                , crossStage     :: Maybe Int
                 , crossEmulator  :: CrossEmulator
                 , configureWrapper :: Maybe String
                 , fullyStatic    :: Bool
@@ -209,6 +210,7 @@ vanilla = BuildConfig
   , withNuma = False
   , withZstd = False
   , crossTarget = Nothing
+  , crossStage  = Nothing
   , crossEmulator = NoEmulator
   , configureWrapper = Nothing
   , fullyStatic = False
@@ -257,6 +259,7 @@ crossConfig :: String       -- ^ target triple
             -> BuildConfig
 crossConfig triple emulator configure_wrapper =
     vanilla { crossTarget = Just triple
+            , crossStage  = Just 2
             , crossEmulator = emulator
             , configureWrapper = configure_wrapper
             }
@@ -771,6 +774,7 @@ job arch opsys buildConfig = NamedJob { name = jobName, jobInfo = Job {..} }
       , "INSTALL_CONFIGURE_ARGS" =: "--enable-strict-ghc-toolchain-check"
       , maybe mempty ("CONFIGURE_WRAPPER" =:) (configureWrapper buildConfig)
       , maybe mempty ("CROSS_TARGET" =:) (crossTarget buildConfig)
+      , maybe mempty (("CROSS_STAGE" =:) . show) (crossStage buildConfig)
       , case crossEmulator buildConfig of
           NoEmulator       -> case crossTarget buildConfig of
             Nothing -> mempty
@@ -1026,7 +1030,6 @@ debian_x86 =
   ]
   where
     validate_debian = Debian12
-
     perfProfilingJob arch sys buildConfig =
         -- Rename the job to avoid conflicts
         rename (<> "-perf")
@@ -1131,7 +1134,7 @@ cross_jobs = [
       make_wasm_jobs wasm_build_config {unregisterised = True}
   ]
   where
-    javascriptConfig = (crossConfig "javascript-unknown-ghcjs" (Emulator "js-emulator") (Just "emconfigure"))
+    javascriptConfig = (crossConfig "javascript-unknown-ghcjs" NoEmulatorNeeded (Just "emconfigure"))
                          { bignumBackend = Native }
 
     make_wasm_jobs cfg =


=====================================
.gitlab/jobs.yaml
=====================================
@@ -1017,6 +1017,7 @@
       "BIN_DIST_NAME": "ghc-x86_64-linux-alpine3_18-wasm-cross_wasm32-wasi-release+fully_static+text_simdutf",
       "BUILD_FLAVOUR": "release+fully_static+text_simdutf",
       "CONFIGURE_ARGS": "--with-intree-gmp --with-system-libffi --enable-strict-ghc-toolchain-check",
+      "CROSS_STAGE": "2",
       "CROSS_TARGET": "wasm32-wasi",
       "RUNTEST_ARGS": "",
       "TEST_ENV": "x86_64-linux-alpine3_18-wasm-cross_wasm32-wasi-release+fully_static+text_simdutf",
@@ -1080,6 +1081,7 @@
       "BIN_DIST_NAME": "ghc-x86_64-linux-alpine3_18-wasm-int_native-cross_wasm32-wasi-release+fully_static+text_simdutf",
       "BUILD_FLAVOUR": "release+fully_static+text_simdutf",
       "CONFIGURE_ARGS": "--with-intree-gmp --with-system-libffi --enable-strict-ghc-toolchain-check",
+      "CROSS_STAGE": "2",
       "CROSS_TARGET": "wasm32-wasi",
       "RUNTEST_ARGS": "",
       "TEST_ENV": "x86_64-linux-alpine3_18-wasm-int_native-cross_wasm32-wasi-release+fully_static+text_simdutf",
@@ -1143,6 +1145,7 @@
       "BIN_DIST_NAME": "ghc-x86_64-linux-alpine3_18-wasm-unreg-cross_wasm32-wasi-release+fully_static+text_simdutf",
       "BUILD_FLAVOUR": "release+fully_static+text_simdutf",
       "CONFIGURE_ARGS": "--enable-unregisterised --with-intree-gmp --with-system-libffi --enable-strict-ghc-toolchain-check",
+      "CROSS_STAGE": "2",
       "CROSS_TARGET": "wasm32-wasi",
       "RUNTEST_ARGS": "",
       "TEST_ENV": "x86_64-linux-alpine3_18-wasm-unreg-cross_wasm32-wasi-release+fully_static+text_simdutf",
@@ -1462,6 +1465,7 @@
       "BUILD_FLAVOUR": "validate",
       "CONFIGURE_ARGS": "--with-intree-gmp --enable-strict-ghc-toolchain-check",
       "CROSS_EMULATOR": "qemu-aarch64 -L /usr/aarch64-linux-gnu",
+      "CROSS_STAGE": "2",
       "CROSS_TARGET": "aarch64-linux-gnu",
       "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
       "RUNTEST_ARGS": "",
@@ -1527,7 +1531,7 @@
       "BUILD_FLAVOUR": "validate",
       "CONFIGURE_ARGS": "--with-intree-gmp --enable-strict-ghc-toolchain-check",
       "CONFIGURE_WRAPPER": "emconfigure",
-      "CROSS_EMULATOR": "js-emulator",
+      "CROSS_STAGE": "2",
       "CROSS_TARGET": "javascript-unknown-ghcjs",
       "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
       "RUNTEST_ARGS": "",
@@ -4766,6 +4770,7 @@
       "BIN_DIST_NAME": "ghc-x86_64-linux-alpine3_18-wasm-cross_wasm32-wasi-release+fully_static+text_simdutf",
       "BUILD_FLAVOUR": "release+fully_static+text_simdutf",
       "CONFIGURE_ARGS": "--with-intree-gmp --with-system-libffi --enable-strict-ghc-toolchain-check",
+      "CROSS_STAGE": "2",
       "CROSS_TARGET": "wasm32-wasi",
       "RUNTEST_ARGS": "",
       "TEST_ENV": "x86_64-linux-alpine3_18-wasm-cross_wasm32-wasi-release+fully_static+text_simdutf"
@@ -4829,6 +4834,7 @@
       "BIN_DIST_NAME": "ghc-x86_64-linux-alpine3_18-wasm-int_native-cross_wasm32-wasi-release+fully_static+text_simdutf",
       "BUILD_FLAVOUR": "release+fully_static+text_simdutf",
       "CONFIGURE_ARGS": "--with-intree-gmp --with-system-libffi --enable-strict-ghc-toolchain-check",
+      "CROSS_STAGE": "2",
       "CROSS_TARGET": "wasm32-wasi",
       "RUNTEST_ARGS": "",
       "TEST_ENV": "x86_64-linux-alpine3_18-wasm-int_native-cross_wasm32-wasi-release+fully_static+text_simdutf"
@@ -4892,6 +4898,7 @@
       "BIN_DIST_NAME": "ghc-x86_64-linux-alpine3_18-wasm-unreg-cross_wasm32-wasi-release+fully_static+text_simdutf",
       "BUILD_FLAVOUR": "release+fully_static+text_simdutf",
       "CONFIGURE_ARGS": "--enable-unregisterised --with-intree-gmp --with-system-libffi --enable-strict-ghc-toolchain-check",
+      "CROSS_STAGE": "2",
       "CROSS_TARGET": "wasm32-wasi",
       "RUNTEST_ARGS": "",
       "TEST_ENV": "x86_64-linux-alpine3_18-wasm-unreg-cross_wasm32-wasi-release+fully_static+text_simdutf"
@@ -4955,6 +4962,7 @@
       "BUILD_FLAVOUR": "validate",
       "CONFIGURE_ARGS": "--with-intree-gmp --enable-strict-ghc-toolchain-check",
       "CROSS_EMULATOR": "qemu-aarch64 -L /usr/aarch64-linux-gnu",
+      "CROSS_STAGE": "2",
       "CROSS_TARGET": "aarch64-linux-gnu",
       "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
       "RUNTEST_ARGS": "",
@@ -5019,7 +5027,7 @@
       "BUILD_FLAVOUR": "validate",
       "CONFIGURE_ARGS": "--with-intree-gmp --enable-strict-ghc-toolchain-check",
       "CONFIGURE_WRAPPER": "emconfigure",
-      "CROSS_EMULATOR": "js-emulator",
+      "CROSS_STAGE": "2",
       "CROSS_TARGET": "javascript-unknown-ghcjs",
       "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
       "RUNTEST_ARGS": "",


=====================================
configure.ac
=====================================
@@ -1010,6 +1010,8 @@ FIND_GHC_TOOLCHAIN([hadrian/cfg])
 
 AC_CONFIG_FILES(
 [ hadrian/cfg/system.config
+  hadrian/cfg/system.config.host
+  hadrian/cfg/system.config.target
   hadrian/ghci-cabal
   hadrian/ghci-multi-cabal
   hadrian/ghci-stack


=====================================
hadrian/README.md
=====================================
@@ -327,6 +327,16 @@ workflow, for now.
 
 Note: On windows you need to use the `reloc-binary-dist` target.
 
+#### Cross Compiling
+
+If you are cross compiling then all the settings specified to ./configure are
+for the target system. For example, if you specify `--with-ffi-includes` then
+this is specifically for the target.
+
+If your host system needs additional configuration in order to build a stage1 compiler,
+then at the moment you need to manually edit the "cfg/system.config.host.in" file to
+specify these options in the right place.
+
 #### Relocatable Binary Distribution
 
 If you require a relocatable binary distribution (for example on Windows), then you


=====================================
hadrian/cfg/system.config.host.in
=====================================
@@ -0,0 +1,78 @@
+# This file is processed by the configure script.
+# See hadrian/src/UserSettings.hs for user-defined settings.
+#===========================================================
+
+# Paths to builders:
+#===================
+
+# Information about builders:
+#============================
+
+cc-llvm-backend           = NO
+
+
+# Information about build, host and target systems:
+#==================================================
+
+dynamic-extension     = @soext_host@
+
+bootstrap-threaded-rts = YES
+
+# Settings:
+#==========
+
+# We are in the process of moving the settings file from being entirely
+# generated by configure, to generated being by the build system. Many of these
+# might become redundant.
+# See Note [tooldir: How GHC finds mingw on Windows]
+
+settings-otool-command = otool
+settings-install_name_tool-command = install_name_tool
+settings-llc-command = llc
+settings-opt-command = opt
+settings-llvm-as-command = clang
+settings-use-distro-mingw = NO
+
+target-has-libm = YES
+
+# Include and library directories:
+#=================================
+
+curses-lib-dir     =
+curses-include-dir =
+
+iconv-include-dir =
+iconv-lib-dir     =
+
+intree-gmp              = NO
+gmp-framework-preferred = NO
+gmp-include-dir         =
+gmp-lib-dir             =
+
+use-system-ffi    = NO
+ffi-include-dir   =
+ffi-lib-dir       =
+
+libdw-include-dir   =
+libdw-lib-dir       =
+
+libnuma-include-dir   =
+libnuma-lib-dir       =
+
+libzstd-include-dir   =
+libzstd-lib-dir       =
+
+# Optional Dependencies:
+#=======================
+
+use-lib-dw        = NO
+use-lib-zstd      = NO
+static-lib-zstd   = NO
+use-lib-numa      = NO
+use-lib-m         = YES
+use-lib-rt        = YES
+use-lib-dl        = YES
+use-lib-bfd       = NO
+use-lib-pthread   = NO
+need-libatomic    = NO
+


=====================================
hadrian/cfg/system.config.in
=====================================
@@ -31,11 +31,11 @@ python         = @PythonCmd@
 # Information about builders:
 #============================
 
-cc-llvm-backend           = @CcLlvmBackend@
-
 llvm-min-version          = @LlvmMinVersion@
 llvm-max-version          = @LlvmMaxVersion@
 
+emsdk-version     = @ConfiguredEmsdkVersion@
+
 # Build options:
 #===============
 
@@ -53,8 +53,6 @@ target-platform-full  = @TargetPlatformFull@
 
 cross-compiling       = @CrossCompiling@
 
-dynamic-extension     = @soext_target@
-
 ghc-version           = @GhcVersion@
 ghc-major-version     = @GhcMajVersion@
 ghc-minor-version     = @GhcMinVersion@
@@ -72,62 +70,3 @@ project-patch-level1   = @ProjectPatchLevel1@
 project-patch-level2   = @ProjectPatchLevel2@
 project-git-commit-id  = @ProjectGitCommitId@
 
-# Settings:
-#==========
-
-# We are in the process of moving the settings file from being entirely
-# generated by configure, to generated being by the build system. Many of these
-# might become redundant.
-# See Note [tooldir: How GHC finds mingw on Windows]
-
-settings-otool-command = @SettingsOtoolCommand@
-settings-install_name_tool-command = @SettingsInstallNameToolCommand@
-settings-llc-command = @SettingsLlcCommand@
-settings-opt-command = @SettingsOptCommand@
-settings-llvm-as-command = @SettingsLlvmAsCommand@
-settings-use-distro-mingw = @SettingsUseDistroMINGW@
-
-target-has-libm = @TargetHasLibm@
-
-# Include and library directories:
-#=================================
-
-curses-lib-dir     = @CURSES_LIB_DIRS@
-curses-include-dir = @CURSES_INCLUDE_DIRS@
-
-iconv-include-dir = @ICONV_INCLUDE_DIRS@
-iconv-lib-dir     = @ICONV_LIB_DIRS@
-
-intree-gmp              = @GMP_FORCE_INTREE@
-gmp-framework-preferred = @GMP_PREFER_FRAMEWORK@
-gmp-include-dir         = @GMP_INCLUDE_DIRS@
-gmp-lib-dir             = @GMP_LIB_DIRS@
-
-use-system-ffi    = @UseSystemLibFFI@
-ffi-include-dir   = @FFIIncludeDir@
-ffi-lib-dir       = @FFILibDir@
-
-libdw-include-dir   = @LibdwIncludeDir@
-libdw-lib-dir       = @LibdwLibDir@
-
-libnuma-include-dir   = @LibNumaIncludeDir@
-libnuma-lib-dir       = @LibNumaLibDir@
-
-libzstd-include-dir   = @LibZstdIncludeDir@
-libzstd-lib-dir       = @LibZstdLibDir@
-
-# Optional Dependencies:
-#=======================
-
-use-lib-dw        = @UseLibdw@
-use-lib-zstd      = @UseLibZstd@
-static-lib-zstd   = @UseStaticLibZstd@
-use-lib-numa      = @UseLibNuma@
-use-lib-m         = @UseLibm@
-use-lib-rt        = @UseLibrt@
-use-lib-dl        = @UseLibdl@
-use-lib-bfd       = @UseLibbfd@
-use-lib-pthread   = @UseLibpthread@
-need-libatomic    = @NeedLibatomic@
-
-emsdk-version     = @ConfiguredEmsdkVersion@


=====================================
hadrian/cfg/system.config.target.in
=====================================
@@ -0,0 +1,84 @@
+# This file is processed by the configure script.
+# See hadrian/src/UserSettings.hs for user-defined settings.
+#===========================================================
+
+# Paths to builders:
+#===================
+
+# Information about builders:
+#============================
+
+cc-llvm-backend           = @CcLlvmBackend@
+
+
+# Information about build, host and target systems:
+#==================================================
+
+# Q: Is the *-platform information available in the target?
+# A: Yes, it is. We pass @BuildPlatform@ and @HostPlatform@ and @TargetPlatform@ to ghc-toolchain using --target=that
+#     And we can reconstruct the platform info using targetPlatformTriple
+# Q: What is TargetPlatformFull?
+target-platform-full  = @TargetPlatformFull@
+
+dynamic-extension     = @soext_target@
+
+bootstrap-threaded-rts = @GhcThreadedRts@
+
+# Settings:
+#==========
+
+# We are in the process of moving the settings file from being entirely
+# generated by configure, to generated being by the build system. Many of these
+# might become redundant.
+# See Note [tooldir: How GHC finds mingw on Windows]
+
+settings-otool-command = @SettingsOtoolCommand@
+settings-install_name_tool-command = @SettingsInstallNameToolCommand@
+settings-llc-command = @SettingsLlcCommand@
+settings-opt-command = @SettingsOptCommand@
+settings-llvm-as-command = @SettingsLlvmAsCommand@
+settings-use-distro-mingw = @SettingsUseDistroMINGW@
+
+target-has-libm = @TargetHasLibm@
+
+# Include and library directories:
+#=================================
+
+curses-lib-dir     = @CURSES_LIB_DIRS@
+curses-include-dir = @CURSES_INCLUDE_DIRS@
+
+iconv-include-dir = @ICONV_INCLUDE_DIRS@
+iconv-lib-dir     = @ICONV_LIB_DIRS@
+
+intree-gmp              = @GMP_FORCE_INTREE@
+gmp-framework-preferred = @GMP_PREFER_FRAMEWORK@
+gmp-include-dir         = @GMP_INCLUDE_DIRS@
+gmp-lib-dir             = @GMP_LIB_DIRS@
+
+use-system-ffi    = @UseSystemLibFFI@
+ffi-include-dir   = @FFIIncludeDir@
+ffi-lib-dir       = @FFILibDir@
+
+libdw-include-dir   = @LibdwIncludeDir@
+libdw-lib-dir       = @LibdwLibDir@
+
+libnuma-include-dir   = @LibNumaIncludeDir@
+libnuma-lib-dir       = @LibNumaLibDir@
+
+libzstd-include-dir   = @LibZstdIncludeDir@
+libzstd-lib-dir       = @LibZstdLibDir@
+
+# Optional Dependencies:
+#=======================
+
+use-lib-dw        = @UseLibdw@
+use-lib-zstd      = @UseLibZstd@
+static-lib-zstd   = @UseStaticLibZstd@
+use-lib-numa      = @UseLibNuma@
+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/Base.hs
=====================================
@@ -29,7 +29,8 @@ module Base (
     module Way,
 
     -- * Paths
-    hadrianPath, configPath, configFile, sourcePath, shakeFilesDir,
+    hadrianPath, configPath, configFile, buildConfigFileHost, buildConfigFileTarget,
+    sourcePath, shakeFilesDir,
     stageBinPath, stageLibPath, templateHscPath,
     buildTargetFile, hostTargetFile, targetTargetFile,
     ghcLibDeps, haddockDeps,
@@ -80,6 +81,13 @@ configPath = hadrianPath -/- "cfg"
 configFile :: FilePath
 configFile = configPath -/- "system.config"
 
+buildConfigFileHost :: FilePath
+buildConfigFileHost = configPath -/- "system.config.host"
+
+buildConfigFileTarget :: FilePath
+buildConfigFileTarget = configPath -/- "system.config.target"
+
+
 -- | The target configuration file generated by ghc-toolchain for the
 -- compilation build platform
 buildTargetFile :: FilePath


=====================================
hadrian/src/Builder.hs
=====================================
@@ -26,15 +26,13 @@ import Hadrian.Builder.Tar
 import Hadrian.Oracles.Path
 import Hadrian.Oracles.TextFile
 import Hadrian.Utilities
-import Oracles.Setting (bashPath, targetStage)
 import System.Exit
 import System.IO (stderr)
 
 import Base
 import Context
 import Oracles.Flag
-import Oracles.Setting (setting, Setting(..))
-import Oracles.Setting (settingsFileSetting, ToolchainSetting(..))
+import Oracles.Setting
 import Packages
 
 import GHC.IO.Encoding (getFileSystemEncoding)
@@ -240,10 +238,10 @@ instance H.Builder Builder where
         Ghc _ st -> do
             root <- buildRoot
             unlitPath  <- builderPath Unlit
-            distro_mingw <- settingsFileSetting ToolchainSetting_DistroMinGW
+            distro_mingw <- settingsFileSetting ToolchainSetting_DistroMinGW st
             -- TODO: Check this is the right stage
             libffi_adjustors <- targetUseLibffiForAdjustors st
-            use_system_ffi <- flag UseSystemFfi
+            use_system_ffi <- buildFlag UseSystemFfi st
 
             return $ [ unlitPath ]
                   ++ [ root -/- mingwStamp | windowsHost, distro_mingw == "NO" ]


=====================================
hadrian/src/Expression.hs
=====================================
@@ -146,7 +146,7 @@ buildingCompilerStage' f = f . succStage <$> getStage
 --   compiler's RTS ways. See Note [Linking ghc-bin against threaded stage0 RTS]
 --   in Settings.Packages for details.
 threadedBootstrapper :: Predicate
-threadedBootstrapper = expr (flag BootstrapThreadedRts)
+threadedBootstrapper = staged (buildFlag BootstrapThreadedRts)
 
 -- | Is a certain package /not/ built right now?
 notPackage :: Package -> Predicate


=====================================
hadrian/src/Hadrian/Oracles/TextFile.hs
=====================================
@@ -13,7 +13,7 @@
 -- to read configuration or package metadata files and cache the parsing.
 -----------------------------------------------------------------------------
 module Hadrian.Oracles.TextFile (
-    lookupValue, lookupValueOrEmpty, lookupValueOrError, lookupSystemConfig, lookupValues,
+    lookupValue, lookupValueOrEmpty, lookupValueOrError, lookupSystemConfig, lookupHostBuildConfig, lookupTargetBuildConfig, lookupValues,
     lookupValuesOrEmpty, lookupValuesOrError, lookupDependencies, textFileOracle,
     getBuildTarget, getHostTarget, getTargetTarget,
     queryBuildTarget, queryHostTarget
@@ -52,6 +52,23 @@ lookupSystemConfig = lookupValueOrError (Just configError) configFile
   where
     configError = "Perhaps you need to rerun ./configure"
 
+lookupHostBuildConfig :: String -> Action String
+lookupHostBuildConfig key = do
+  cross <- (== "YES") <$> lookupSystemConfig "cross-compiling"
+  -- If we are not cross compiling, the build the host compiler like the target.
+  let cfgFile = if cross then buildConfigFileHost else buildConfigFileTarget
+  lookupValueOrError (Just configError) cfgFile key
+  where
+    configError = "Perhaps you need to rerun ./configure"
+
+lookupTargetBuildConfig :: String -> Action String
+lookupTargetBuildConfig key =
+  lookupValueOrError (Just configError) buildConfigFileTarget key
+  where
+    configError = "Perhaps you need to rerun ./configure"
+
+
+
 -- | Lookup a list of values in a text file, tracking the result. Each line of
 -- the file is expected to have @key value1 value2 ...@ format.
 lookupValues :: FilePath -> String -> Action (Maybe [String])
@@ -104,6 +121,7 @@ getHostTarget = do
   -- MP: If we are not cross compiling then we should use the target file in order to
   -- build things for the host, in particular we want to use the configured values for the
   -- target for building the RTS (ie are we using Libffi for adjustors, and the wordsize)
+  -- TODO: Use "flag CrossCompiling"
   ht <- getTargetConfig hostTargetFile
   tt <- getTargetConfig targetTargetFile
   if (Toolchain.targetPlatformTriple ht) == (Toolchain.targetPlatformTriple tt)


=====================================
hadrian/src/Oracles/Flag.hs
=====================================
@@ -2,6 +2,7 @@
 
 module Oracles.Flag (
     Flag (..), flag, getFlag,
+    BuildFlag(..), buildFlag,
     targetSupportsSharedLibs,
     targetSupportsGhciObjects,
     targetSupportsThreadedRts,
@@ -22,7 +23,8 @@ import qualified GHC.Toolchain as Toolchain
 import GHC.Platform.ArchOS
 
 data Flag = CrossCompiling
-          | CcLlvmBackend
+          | UseGhcToolchain
+data BuildFlag = CcLlvmBackend
           | GmpInTree
           | GmpFrameworkPref
           | UseSystemFfi
@@ -38,7 +40,15 @@ data Flag = CrossCompiling
           | UseLibbfd
           | UseLibpthread
           | NeedLibatomic
-          | UseGhcToolchain
+          | TargetHasLibm
+
+parseFlagResult :: String -> String -> Bool
+parseFlagResult key value =
+  if (value `notElem` ["YES", "NO", ""])
+    then error $ "Configuration flag "
+               ++ quote (key ++ " = " ++ value) ++ " cannot be parsed."
+    else value == "YES"
+
 
 -- 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.
@@ -46,6 +56,12 @@ flag :: Flag -> Action Bool
 flag f = do
     let key = case f of
             CrossCompiling       -> "cross-compiling"
+            UseGhcToolchain      -> "use-ghc-toolchain"
+    parseFlagResult key <$> lookupSystemConfig key
+
+buildFlag :: BuildFlag -> Stage -> Action Bool
+buildFlag f st =
+    let key = case f of
             CcLlvmBackend        -> "cc-llvm-backend"
             GmpInTree            -> "intree-gmp"
             GmpFrameworkPref     -> "gmp-framework-preferred"
@@ -62,11 +78,13 @@ flag f = do
             UseLibbfd            -> "use-lib-bfd"
             UseLibpthread        -> "use-lib-pthread"
             NeedLibatomic        -> "need-libatomic"
-            UseGhcToolchain      -> "use-ghc-toolchain"
-    value <- lookupSystemConfig key
-    when (value `notElem` ["YES", "NO", ""]) . error $ "Configuration flag "
-        ++ quote (key ++ " = " ++ value) ++ " cannot be parsed."
-    return $ value == "YES"
+            TargetHasLibm        -> "target-has-libm"
+    in parseFlagResult key <$> (tgtConfig st key)
+  where
+    tgtConfig Stage0 {} = lookupHostBuildConfig
+    tgtConfig Stage1 = lookupHostBuildConfig
+    tgtConfig Stage2 = lookupTargetBuildConfig
+    tgtConfig Stage3 = lookupTargetBuildConfig
 
 -- | Get a configuration setting.
 getFlag :: Flag -> Expr c b Bool


=====================================
hadrian/src/Oracles/Setting.hs
=====================================
@@ -1,7 +1,8 @@
 module Oracles.Setting (
     configFile,
     -- * Settings
-    Setting (..), setting, getSetting,
+    ProjectSetting (..), setting, getSetting,
+    BuildSetting(..), buildSetting,
     ToolchainSetting (..), settingsFileSetting,
 
     -- * Helpers
@@ -39,28 +40,14 @@ import GHC.Platform.ArchOS
 -- tracking the result in the Shake database.
 --
 -- * ROMES:TODO: How to handle target-platform-full?
-data Setting = CursesIncludeDir
-             | CursesLibDir
-             | DynamicExtension
-             | FfiIncludeDir
-             | FfiLibDir
-             | GhcMajorVersion
+data ProjectSetting =
+               GhcMajorVersion
              | GhcMinorVersion
              | GhcPatchLevel
              | GhcVersion
              | GhcSourcePath
              | LlvmMinVersion
              | LlvmMaxVersion
-             | GmpIncludeDir
-             | GmpLibDir
-             | IconvIncludeDir
-             | IconvLibDir
-             | LibdwIncludeDir
-             | LibdwLibDir
-             | LibnumaIncludeDir
-             | LibnumaLibDir
-             | LibZstdIncludeDir
-             | LibZstdLibDir
              | ProjectGitCommitId
              | ProjectName
              | ProjectVersion
@@ -75,6 +62,25 @@ data Setting = CursesIncludeDir
              | BourneShell
              | EmsdkVersion
 
+
+-- Things which configure how a specific stage is built
+data BuildSetting =
+               CursesIncludeDir
+             | CursesLibDir
+             | DynamicExtension
+             | FfiIncludeDir
+             | FfiLibDir
+             | GmpIncludeDir
+             | GmpLibDir
+             | IconvIncludeDir
+             | IconvLibDir
+             | LibdwIncludeDir
+             | LibdwLibDir
+             | LibnumaIncludeDir
+             | LibnumaLibDir
+             | LibZstdIncludeDir
+             | LibZstdLibDir
+
 -- TODO compute solely in Hadrian, removing these variables' definitions
 -- from aclocal.m4 whenever they can be calculated from other variables
 -- already fed into Hadrian.
@@ -95,13 +101,8 @@ data ToolchainSetting
 
 -- | Look up the value of a 'Setting' in @cfg/system.config@, tracking the
 -- result.
-setting :: Setting -> Action String
+setting :: ProjectSetting -> Action String
 setting key = lookupSystemConfig $ case key of
-    CursesIncludeDir   -> "curses-include-dir"
-    CursesLibDir       -> "curses-lib-dir"
-    DynamicExtension   -> "dynamic-extension"
-    FfiIncludeDir      -> "ffi-include-dir"
-    FfiLibDir          -> "ffi-lib-dir"
     GhcMajorVersion    -> "ghc-major-version"
     GhcMinorVersion    -> "ghc-minor-version"
     GhcPatchLevel      -> "ghc-patch-level"
@@ -109,16 +110,6 @@ setting key = lookupSystemConfig $ case key of
     GhcSourcePath      -> "ghc-source-path"
     LlvmMinVersion     -> "llvm-min-version"
     LlvmMaxVersion     -> "llvm-max-version"
-    GmpIncludeDir      -> "gmp-include-dir"
-    GmpLibDir          -> "gmp-lib-dir"
-    IconvIncludeDir    -> "iconv-include-dir"
-    IconvLibDir        -> "iconv-lib-dir"
-    LibdwIncludeDir    -> "libdw-include-dir"
-    LibdwLibDir        -> "libdw-lib-dir"
-    LibnumaIncludeDir  -> "libnuma-include-dir"
-    LibnumaLibDir      -> "libnuma-lib-dir"
-    LibZstdIncludeDir  -> "libzstd-include-dir"
-    LibZstdLibDir      -> "libzstd-lib-dir"
     ProjectGitCommitId -> "project-git-commit-id"
     ProjectName        -> "project-name"
     ProjectVersion     -> "project-version"
@@ -133,22 +124,51 @@ setting key = lookupSystemConfig $ case key of
     BourneShell        -> "bourne-shell"
     EmsdkVersion       -> "emsdk-version"
 
+buildSetting :: BuildSetting -> Stage -> Action String
+buildSetting key stage = tgtConfig stage $ case key of
+    CursesIncludeDir   -> "curses-include-dir"
+    CursesLibDir       -> "curses-lib-dir"
+    DynamicExtension   -> "dynamic-extension"
+    FfiIncludeDir      -> "ffi-include-dir"
+    FfiLibDir          -> "ffi-lib-dir"
+    GmpIncludeDir      -> "gmp-include-dir"
+    GmpLibDir          -> "gmp-lib-dir"
+    IconvIncludeDir    -> "iconv-include-dir"
+    IconvLibDir        -> "iconv-lib-dir"
+    LibdwIncludeDir    -> "libdw-include-dir"
+    LibdwLibDir        -> "libdw-lib-dir"
+    LibnumaIncludeDir  -> "libnuma-include-dir"
+    LibnumaLibDir      -> "libnuma-lib-dir"
+    LibZstdIncludeDir  -> "libzstd-include-dir"
+    LibZstdLibDir      -> "libzstd-lib-dir"
+  where
+    tgtConfig Stage0 {} = lookupHostBuildConfig
+    tgtConfig Stage1 = lookupHostBuildConfig
+    tgtConfig Stage2 = lookupTargetBuildConfig
+    tgtConfig Stage3 = lookupTargetBuildConfig
+
+
 -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the
 -- result.
 -- See Note [tooldir: How GHC finds mingw on Windows]
 -- ROMES:TODO: This should be queryTargetTargetConfig
-settingsFileSetting :: ToolchainSetting -> Action String
-settingsFileSetting key = lookupSystemConfig $ case key of
+settingsFileSetting :: ToolchainSetting -> Stage -> Action String
+settingsFileSetting key stage = tgtConfig stage $ case key of
     ToolchainSetting_OtoolCommand           -> "settings-otool-command"
     ToolchainSetting_InstallNameToolCommand -> "settings-install_name_tool-command"
     ToolchainSetting_LlcCommand             -> "settings-llc-command"
     ToolchainSetting_OptCommand             -> "settings-opt-command"
     ToolchainSetting_LlvmAsCommand          -> "settings-llvm-as-command"
     ToolchainSetting_DistroMinGW            -> "settings-use-distro-mingw" -- ROMES:TODO: This option doesn't seem to be in ghc-toolchain yet. It corresponds to EnableDistroToolchain
+  where
+    tgtConfig Stage0 {} = lookupHostBuildConfig
+    tgtConfig Stage1 = lookupHostBuildConfig
+    tgtConfig Stage2 = lookupTargetBuildConfig
+    tgtConfig Stage3 = lookupTargetBuildConfig
 
 -- | An expression that looks up the value of a 'Setting' in @cfg/system.config@,
 -- tracking the result.
-getSetting :: Setting -> Expr c b String
+getSetting :: ProjectSetting -> Expr c b String
 getSetting = expr . setting
 
 -- | The path to a Bourne shell interpreter.
@@ -251,7 +271,7 @@ libsuf :: Stage -> Way -> Action String
 libsuf st way
     | not (wayUnit Dynamic way) = return (waySuffix way ++ ".a") -- e.g., _p.a
     | otherwise = do
-        extension <- setting DynamicExtension -- e.g., .dll or .so
+        extension <- buildSetting DynamicExtension st-- e.g., .dll or .so
         version   <- ghcVersionStage st -- e.g. 8.4.4 or 8.9.xxxx
         let suffix = waySuffix (removeWayUnit Dynamic way)
         return (suffix ++ "-ghc" ++ version ++ extension)


=====================================
hadrian/src/Oracles/TestSettings.hs
=====================================
@@ -10,7 +10,7 @@ module Oracles.TestSettings
 
 import Base
 import Hadrian.Oracles.TextFile
-import Oracles.Setting (topDirectory, setting, Setting(..), crossStage)
+import Oracles.Setting (topDirectory, setting, ProjectSetting(..), crossStage)
 import Packages
 import Settings.Program (programContext)
 import Hadrian.Oracles.Path


=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -11,7 +11,6 @@ import qualified Data.Set as Set
 import Base
 import qualified Context
 import Expression
-import Hadrian.Oracles.TextFile (lookupSystemConfig)
 import Oracles.Flag hiding (arSupportsAtFile, arSupportsDashL)
 import Oracles.ModuleFiles
 import Oracles.Setting
@@ -50,10 +49,9 @@ ghcPrimDependencies = do
 
 rtsDependencies :: Expr [FilePath]
 rtsDependencies = do
-    stage   <- getStage
-    rtsPath <- expr (rtsBuildPath stage)
-    jsTarget <- expr (isJsTarget stage)
-    useSystemFfi <- expr (flag UseSystemFfi)
+    rtsPath <- staged rtsBuildPath
+    jsTarget <- staged isJsTarget
+    useSystemFfi <- staged (buildFlag UseSystemFfi)
 
     let -- headers common to native and JS RTS
         common_headers =
@@ -278,7 +276,7 @@ runInterpolations (Interpolations mk_substs) input = do
     return (subst input)
 
 -- | Interpolate the given variable with the value of the given 'Setting'.
-interpolateSetting :: String -> Setting -> Interpolations
+interpolateSetting :: String -> ProjectSetting -> Interpolations
 interpolateSetting name settng = interpolateVar name $ setting settng
 
 -- | Interpolate the @ProjectVersion@, @ProjectVersionMunged@, and @ProjectVersionForLib@ variables.
@@ -401,14 +399,14 @@ bindistRules = do
     , interpolateSetting "LlvmMinVersion" LlvmMinVersion
     , interpolateVar "LlvmTarget" $ getTarget tgtLlvmTarget
     , interpolateSetting "ProjectVersion" ProjectVersion
-    , interpolateVar "SettingsUseDistroMINGW" $ settingsFileSetting ToolchainSetting_DistroMinGW
+    , interpolateVar "SettingsUseDistroMINGW" $ interp (staged (settingsFileSetting ToolchainSetting_DistroMinGW))
     , interpolateVar "TablesNextToCode" $ yesNo <$> getTarget tgtTablesNextToCode
-    , interpolateVar "TargetHasLibm" $ lookupSystemConfig "target-has-libm"
+    , interpolateVar "TargetHasLibm" $ yesNo <$> interp (staged (buildFlag TargetHasLibm))
     , interpolateVar "TargetPlatform" $ getTarget targetPlatformTriple
     , interpolateVar "TargetWordBigEndian" $ getTarget isBigEndian
     , interpolateVar "TargetWordSize" $ getTarget wordSize
     , interpolateVar "Unregisterised" $ yesNo <$> getTarget tgtUnregisterised
-    , interpolateVar "UseLibdw" $ fmap yesNo $ interp $ getFlag UseLibdw
+    , interpolateVar "UseLibdw" $ fmap yesNo $ interp $ staged (buildFlag UseLibdw)
     , interpolateVar "UseLibffiForAdjustors" $ yesNo <$> getTarget tgtUseLibffiForAdjustors
     , interpolateVar "GhcWithSMP" $ yesNo <$> targetSupportsSMP Stage2
     ]
@@ -479,8 +477,8 @@ generateSettings settingsFile = do
         , ("ar supports at file", queryTarget stage arSupportsAtFile')
         , ("ar supports -L",      queryTarget stage arSupportsDashL')
         , ("ranlib command", queryTarget stage ranlibPath)
-        , ("otool command", expr $ settingsFileSetting ToolchainSetting_OtoolCommand)
-        , ("install_name_tool command", expr $ settingsFileSetting ToolchainSetting_InstallNameToolCommand)
+        , ("otool command", staged $ settingsFileSetting ToolchainSetting_OtoolCommand)
+        , ("install_name_tool command", staged $ settingsFileSetting ToolchainSetting_InstallNameToolCommand)
         , ("windres command", queryTarget stage (maybe "/bin/false" prgPath . tgtWindres)) -- TODO: /bin/false is not available on many distributions by default, but we keep it as it were before the ghc-toolchain patch. Fix-me.
         , ("unlit command", ("$topdir/../bin/" <>) <$> expr (programName (ctx { Context.package = unlit, Context.stage = predStage stage })))
         , ("cross compiling", expr $ yesNo <$> crossStage (predStage stage))
@@ -492,13 +490,13 @@ generateSettings settingsFile = do
         , ("target has GNU nonexec stack", queryTarget stage (yesNo . Toolchain.tgtSupportsGnuNonexecStack))
         , ("target has .ident directive",  queryTarget stage (yesNo . Toolchain.tgtSupportsIdentDirective))
         , ("target has subsections via symbols", queryTarget stage (yesNo . Toolchain.tgtSupportsSubsectionsViaSymbols))
-        , ("target has libm", expr $  lookupSystemConfig "target-has-libm")
+        , ("target has libm", yesNo <$> staged (buildFlag TargetHasLibm))
         , ("Unregisterised", queryTarget stage (yesNo . tgtUnregisterised))
         , ("LLVM target", queryTarget stage tgtLlvmTarget)
-        , ("LLVM llc command", expr $ settingsFileSetting ToolchainSetting_LlcCommand)
-        , ("LLVM opt command", expr $ settingsFileSetting ToolchainSetting_OptCommand)
-        , ("LLVM llvm-as command", expr $ settingsFileSetting ToolchainSetting_LlvmAsCommand)
-        , ("Use inplace MinGW toolchain", expr $ settingsFileSetting ToolchainSetting_DistroMinGW)
+        , ("LLVM llc command", staged $ settingsFileSetting ToolchainSetting_LlcCommand)
+        , ("LLVM opt command", staged $ settingsFileSetting ToolchainSetting_OptCommand)
+        , ("LLVM llvm-as command", staged $ settingsFileSetting ToolchainSetting_LlvmAsCommand)
+        , ("Use inplace MinGW toolchain", staged $ settingsFileSetting ToolchainSetting_DistroMinGW)
 
         , ("Use interpreter", expr $ yesNo <$> ghcWithInterpreter stage)
         , ("Support SMP", expr $ yesNo <$> targetSupportsSMP stage)
@@ -506,7 +504,7 @@ generateSettings settingsFile = do
         , ("Tables next to code", queryTarget stage (yesNo . tgtTablesNextToCode))
         , ("Leading underscore",  queryTarget stage (yesNo . tgtSymbolsHaveLeadingUnderscore))
         , ("Use LibFFI", expr $ yesNo <$> targetUseLibffiForAdjustors stage)
-        , ("RTS expects libdw", yesNo <$> getFlag UseLibdw)
+        , ("RTS expects libdw", yesNo <$> staged (buildFlag UseLibdw))
         , ("Relative Global Package DB", pure rel_pkg_db)
         ]
     let showTuple (k, v) = "(" ++ show k ++ ", " ++ show v ++ ")"


=====================================
hadrian/src/Rules/Gmp.hs
=====================================
@@ -17,7 +17,7 @@ import Settings.Builders.Common (cArgs, getStagedCCFlags)
 -- their paths.
 gmpObjects :: Stage -> Action [FilePath]
 gmpObjects s = do
-  isInTree <- flag GmpInTree
+  isInTree <- buildFlag GmpInTree s
   if not isInTree
     then return []
     else do
@@ -65,8 +65,9 @@ gmpRules = do
             packageP   = takeDirectory buildP
             librariesP = takeDirectory packageP
             stageP     = takeDirectory librariesP
+        stage <- parsePath parseStage "<stage>" (takeFileName stageP)
 
-        isInTree <- flag GmpInTree
+        isInTree <- buildFlag GmpInTree stage
 
         if isInTree
         then do


=====================================
hadrian/src/Rules/Libffi.hs
=====================================
@@ -87,7 +87,7 @@ libffiContext stage = do
 -- | The name of the library
 libffiName :: Expr String
 libffiName = do
-    useSystemFfi <- expr (flag UseSystemFfi)
+    useSystemFfi <- staged (buildFlag UseSystemFfi)
     if useSystemFfi
       then pure "ffi"
       else libffiLocalName Nothing
@@ -118,8 +118,8 @@ libffiHeaderDir stage = do
     path <- libffiBuildPath stage
     return $ path -/- "inst/include"
 
-libffiSystemHeaderDir :: Action FilePath
-libffiSystemHeaderDir = setting FfiIncludeDir
+libffiSystemHeaderDir :: Stage -> Action FilePath
+libffiSystemHeaderDir = buildSetting FfiIncludeDir
 
 fixLibffiMakefile :: FilePath -> String -> String
 fixLibffiMakefile top =


=====================================
hadrian/src/Rules/Rts.hs
=====================================
@@ -54,9 +54,9 @@ withLibffi stage action = needLibffi stage
 -- See Note [Packaging libffi headers] in GHC.Driver.CodeOutput.
 copyLibffiHeader :: Stage -> FilePath -> Action ()
 copyLibffiHeader stage header = do
-    useSystemFfi <- flag UseSystemFfi
+    useSystemFfi <- buildFlag UseSystemFfi stage
     (fromStr, headerDir) <- if useSystemFfi
-        then ("system",) <$> libffiSystemHeaderDir
+        then ("system",) <$> libffiSystemHeaderDir stage
         else needLibffi stage
           >> ("custom",) <$> libffiHeaderDir stage
     copyFile
@@ -115,7 +115,7 @@ rtsLibffiLibrary stage way = do
     name    <- interpretInContext ((rtsContext stage) { way = way }) libffiName
     suf <- if wayUnit Dynamic way
                 then do
-                  extension <- setting DynamicExtension -- e.g., .dll or .so
+                  extension <- buildSetting DynamicExtension stage -- e.g., .dll or .so
                   let suffix = waySuffix (removeWayUnit Dynamic way)
                   return (suffix ++ extension)
                 -- Static suffix
@@ -129,7 +129,7 @@ rtsLibffiLibrary stage way = do
 needRtsLibffiTargets :: Stage -> Action [FilePath]
 needRtsLibffiTargets stage = do
     rtsPath      <- rtsBuildPath stage
-    useSystemFfi <- flag UseSystemFfi
+    useSystemFfi <- buildFlag UseSystemFfi stage
     jsTarget     <- isJsTarget stage
 
     -- Header files (in the rts build dir).


=====================================
hadrian/src/Settings/Builders/Cabal.hs
=====================================
@@ -203,11 +203,11 @@ configureArgs cFlags' ldFlags' = do
     mconcat
         [ conf "CFLAGS"   cFlags
         , conf "LDFLAGS"  ldFlags
-        , conf "--with-iconv-includes"    $ arg =<< getSetting IconvIncludeDir
-        , conf "--with-iconv-libraries"   $ arg =<< getSetting IconvLibDir
-        , conf "--with-gmp-includes"      $ arg =<< getSetting GmpIncludeDir
-        , conf "--with-gmp-libraries"     $ arg =<< getSetting GmpLibDir
-        , conf "--with-curses-libraries"  $ arg =<< getSetting CursesLibDir
+        , conf "--with-iconv-includes"    $ arg =<< staged (buildSetting IconvIncludeDir)
+        , conf "--with-iconv-libraries"   $ arg =<< staged (buildSetting IconvLibDir)
+        , conf "--with-gmp-includes"      $ arg =<< staged (buildSetting GmpIncludeDir)
+        , conf "--with-gmp-libraries"     $ arg =<< staged (buildSetting GmpLibDir)
+        , conf "--with-curses-libraries"  $ arg =<< staged (buildSetting CursesLibDir)
         , conf "--host"                   $ arg =<< flip queryTarget targetPlatformTriple  . predStage' =<< getStage
         , conf "--with-cc" $ arg =<< getBuilderPath . (Cc CompileC) =<< getStage
         , ghcVersionH


=====================================
hadrian/src/Settings/Builders/Common.hs
=====================================
@@ -51,9 +51,9 @@ cppArgs = mempty
 cWarnings :: Args
 cWarnings = mconcat
     [ arg "-Wall"
-    , flag CcLlvmBackend ? arg "-Wno-unknown-pragmas"
-    , notM (flag CcLlvmBackend) ? not windowsHost ? arg "-Werror=unused-but-set-variable"
-    , notM (flag CcLlvmBackend) ? arg "-Wno-error=inline" ]
+    , staged (buildFlag CcLlvmBackend) ? arg "-Wno-unknown-pragmas"
+    , notM (staged (buildFlag CcLlvmBackend)) ? not windowsHost ? arg "-Werror=unused-but-set-variable"
+    , notM (staged (buildFlag CcLlvmBackend)) ? arg "-Wno-error=inline" ]
 
 packageDatabaseArgs :: Args
 packageDatabaseArgs = do


=====================================
hadrian/src/Settings/Builders/Ghc.hs
=====================================
@@ -102,7 +102,7 @@ ghcLinkArgs = builder (Ghc LinkHs) ? do
     context <- getContext
     distPath <- expr (Context.distDynDir context)
 
-    useSystemFfi <- expr (flag UseSystemFfi)
+    useSystemFfi <- staged (buildFlag UseSystemFfi)
     buildPath <- getBuildPath
     libffiName' <- libffiName
     debugged <- buildingCompilerStage' . ghcDebugged =<< expr flavour


=====================================
hadrian/src/Settings/Builders/Hsc2Hs.hs
=====================================
@@ -11,7 +11,7 @@ hsc2hsBuilderArgs :: Args
 hsc2hsBuilderArgs = builder Hsc2Hs ? do
     stage   <- getStage
     ccPath  <- getBuilderPath $ Cc CompileC stage
-    gmpDir  <- getSetting GmpIncludeDir
+    gmpDir  <- staged (buildSetting GmpIncludeDir)
     top     <- expr topDirectory
     hArch   <- queryHost queryArch
     hOs     <- queryHost queryOS


=====================================
hadrian/src/Settings/Builders/RunTest.hs
=====================================
@@ -113,9 +113,9 @@ inTreeCompilerArgs stg = do
     platform    <- queryTargetTarget ghcStage targetPlatformTriple
     wordsize    <- show @Int . (*8) <$> queryTargetTarget ghcStage (wordSize2Bytes . tgtWordSize)
 
-    llc_cmd   <- settingsFileSetting ToolchainSetting_LlcCommand
-    llvm_as_cmd <- settingsFileSetting ToolchainSetting_LlvmAsCommand
-    have_llvm <- liftIO (all isJust <$> mapM findExecutable [llc_cmd, llvm_as_cmd])
+    llc_cmd   <- settingsFileSetting ToolchainSetting_LlcCommand ghcStage
+    _llvm_as_cmd <- settingsFileSetting ToolchainSetting_LlvmAsCommand ghcStage
+    have_llvm <- liftIO (isJust <$> findExecutable llc_cmd)
 
     top         <- topDirectory
 


=====================================
hadrian/src/Settings/Packages.hs
=====================================
@@ -30,10 +30,10 @@ packageArgs = do
 
         compilerStageOption f = buildingCompilerStage' . f =<< expr flavour
 
-    cursesIncludeDir <- getSetting CursesIncludeDir
-    cursesLibraryDir <- getSetting CursesLibDir
-    ffiIncludeDir  <- getSetting FfiIncludeDir
-    ffiLibraryDir  <- getSetting FfiLibDir
+    cursesIncludeDir <- staged (buildSetting CursesIncludeDir)
+    cursesLibraryDir <- staged (buildSetting CursesLibDir)
+    ffiIncludeDir  <- staged (buildSetting FfiIncludeDir)
+    ffiLibraryDir  <- staged (buildSetting FfiLibDir)
     stageVersion <- readVersion <$> (expr $ ghcVersionStage stage)
 
     mconcat
@@ -80,14 +80,14 @@ packageArgs = do
             [ andM [expr (ghcWithInterpreter stage), notStage0] `cabalFlag` "internal-interpreter"
             , notM cross `cabalFlag` "terminfo"
             , arg "-build-tool-depends"
-            , flag UseLibzstd `cabalFlag` "with-libzstd"
+            , staged (buildFlag UseLibzstd) `cabalFlag` "with-libzstd"
             -- ROMES: While the boot compiler is not updated wrt -this-unit-id
             -- not being fixed to `ghc`, when building stage0, we must set
             -- -this-unit-id to `ghc` because the boot compiler expects that.
             -- We do it through a cabal flag in ghc.cabal
             , stageVersion < makeVersion [9,8,1] ? arg "+hadrian-stage0"
-            , flag StaticLibzstd `cabalFlag` "static-libzstd"
             , stage0 `cabalFlag` "bootstrap"
+            , staged (buildFlag StaticLibzstd) `cabalFlag` "static-libzstd"
             ]
 
           , builder (Haddock BuildPackage) ? arg ("--optghc=-I" ++ path) ]
@@ -117,9 +117,9 @@ packageArgs = do
 
         -------------------------------- ghcPrim -------------------------------
         , package ghcPrim ? mconcat
-          [ builder (Cabal Flags) ? flag NeedLibatomic `cabalFlag` "need-atomic"
+          [ builder (Cabal Flags) ? staged (buildFlag NeedLibatomic) `cabalFlag` "need-atomic"
 
-          , builder (Cc CompileC) ? (not <$> flag CcLlvmBackend) ?
+          , builder (Cc CompileC) ? (not <$> staged (buildFlag CcLlvmBackend)) ?
             input "**/cbits/atomic.c"  ? arg "-Wno-sync-nand" ]
 
         -------------------------------- ghcBoot ------------------------------
@@ -239,8 +239,8 @@ packageArgs = do
 ghcBignumArgs :: Args
 ghcBignumArgs = package ghcBignum ? do
     -- These are only used for non-in-tree builds.
-    librariesGmp <- getSetting GmpLibDir
-    includesGmp <- getSetting GmpIncludeDir
+    librariesGmp <- staged (buildSetting GmpLibDir)
+    includesGmp <- staged (buildSetting GmpIncludeDir)
 
     backend <- getBignumBackend
     check   <- getBignumCheck
@@ -263,15 +263,15 @@ ghcBignumArgs = package ghcBignum ? do
 
                        -- enable in-tree support: don't depend on external "gmp"
                        -- library
-                     , flag GmpInTree ? arg "--configure-option=--with-intree-gmp"
+                     , staged (buildFlag GmpInTree) ? arg "--configure-option=--with-intree-gmp"
 
                        -- prefer framework over library (on Darwin)
-                     , flag GmpFrameworkPref ?
+                     , staged (buildFlag GmpFrameworkPref) ?
                        arg "--configure-option=--with-gmp-framework-preferred"
 
                        -- Ensure that the ghc-bignum package registration includes
                        -- knowledge of the system gmp's library and include directories.
-                     , notM (flag GmpInTree) ? cabalExtraDirs includesGmp librariesGmp
+                     , notM (staged (buildFlag GmpInTree)) ? cabalExtraDirs includesGmp librariesGmp
                      ]
                   ]
                _ -> mempty
@@ -300,15 +300,15 @@ rtsPackageArgs = package rts ? do
     way            <- getWay
     path           <- getBuildPath
     top            <- expr topDirectory
-    useSystemFfi   <- getFlag UseSystemFfi
-    ffiIncludeDir  <- getSetting FfiIncludeDir
-    ffiLibraryDir  <- getSetting FfiLibDir
-    libdwIncludeDir   <- getSetting LibdwIncludeDir
-    libdwLibraryDir   <- getSetting LibdwLibDir
-    libnumaIncludeDir <- getSetting LibnumaIncludeDir
-    libnumaLibraryDir <- getSetting LibnumaLibDir
-    libzstdIncludeDir <- getSetting LibZstdIncludeDir
-    libzstdLibraryDir <- getSetting LibZstdLibDir
+    useSystemFfi   <- staged (buildFlag UseSystemFfi)
+    ffiIncludeDir  <- staged (buildSetting FfiIncludeDir)
+    ffiLibraryDir  <- staged (buildSetting FfiLibDir)
+    libdwIncludeDir   <- staged (buildSetting LibdwIncludeDir)
+    libdwLibraryDir   <- staged (buildSetting LibdwLibDir)
+    libnumaIncludeDir <- staged (buildSetting LibnumaIncludeDir)
+    libnumaLibraryDir <- staged (buildSetting LibnumaLibDir)
+    libzstdIncludeDir <- staged (buildSetting LibZstdIncludeDir)
+    libzstdLibraryDir <- staged (buildSetting LibZstdLibDir)
 
 
     -- Arguments passed to GHC when compiling C and .cmm sources.
@@ -402,10 +402,10 @@ rtsPackageArgs = package rts ? do
           -- any warnings in the module. See:
           -- https://gitlab.haskell.org/ghc/ghc/wikis/working-conventions#Warnings
 
-          , (not <$> flag CcLlvmBackend) ?
+          , (not <$> staged (buildFlag CcLlvmBackend)) ?
             inputs ["**/Compact.c"] ? arg "-finline-limit=2500"
 
-          , input "**/RetainerProfile.c" ? flag CcLlvmBackend ?
+          , input "**/RetainerProfile.c" ? staged (buildFlag CcLlvmBackend) ?
             arg "-Wno-incompatible-pointer-types"
           ]
 
@@ -415,18 +415,18 @@ rtsPackageArgs = package rts ? do
           , any (wayUnit Debug) rtsWays     `cabalFlag` "debug"
           , any (wayUnit Dynamic) rtsWays   `cabalFlag` "dynamic"
           , any (wayUnit Threaded) rtsWays  `cabalFlag` "threaded"
-          , flag UseLibm                    `cabalFlag` "libm"
-          , flag UseLibrt                   `cabalFlag` "librt"
-          , flag UseLibdl                   `cabalFlag` "libdl"
+          , staged (buildFlag UseLibm)                    `cabalFlag` "libm"
+          , staged (buildFlag UseLibrt)                   `cabalFlag` "librt"
+          , staged (buildFlag UseLibdl)                   `cabalFlag` "libdl"
           , useSystemFfi                    `cabalFlag` "use-system-libffi"
           , targetUseLibffiForAdjustors stage     `cabalFlag` "libffi-adjustors"
-          , flag UseLibpthread              `cabalFlag` "need-pthread"
-          , flag UseLibbfd                  `cabalFlag` "libbfd"
-          , flag NeedLibatomic              `cabalFlag` "need-atomic"
-          , flag UseLibdw                   `cabalFlag` "libdw"
-          , flag UseLibnuma                 `cabalFlag` "libnuma"
-          , flag UseLibzstd                 `cabalFlag` "libzstd"
-          , flag StaticLibzstd              `cabalFlag` "static-libzstd"
+          , staged (buildFlag UseLibpthread)             `cabalFlag` "need-pthread"
+          , staged (buildFlag UseLibbfd    )              `cabalFlag` "libbfd"
+          , staged (buildFlag NeedLibatomic)              `cabalFlag` "need-atomic"
+          , staged (buildFlag UseLibdw     )              `cabalFlag` "libdw"
+          , staged (buildFlag UseLibnuma   )              `cabalFlag` "libnuma"
+          , staged (buildFlag UseLibzstd   )              `cabalFlag` "libzstd"
+          , staged (buildFlag StaticLibzstd)              `cabalFlag` "static-libzstd"
           , queryTargetTarget stage tgtSymbolsHaveLeadingUnderscore `cabalFlag` "leading-underscore"
           , ghcUnreg                        `cabalFlag` "unregisterised"
           , ghcEnableTNC                    `cabalFlag` "tables-next-to-code"
@@ -447,7 +447,7 @@ rtsPackageArgs = package rts ? do
         , builder HsCpp ? pure
           [ "-DTOP="             ++ show top ]
 
-        , builder HsCpp ? flag UseLibdw ? arg "-DUSE_LIBDW" ]
+        , builder HsCpp ? staged (buildFlag UseLibdw) ? arg "-DUSE_LIBDW" ]
 
 -- Compile various performance-critical pieces *without* -fPIC -dynamic
 -- even when building a shared library.  If we don't do this, then the


=====================================
hadrian/src/Settings/Warnings.hs
=====================================
@@ -10,16 +10,15 @@ import Packages
 -- | Default Haskell warning-related arguments.
 defaultGhcWarningsArgs :: Args
 defaultGhcWarningsArgs = do
-   stage <- getStage
    mconcat
     [ notStage0 ? arg "-Wnoncanonical-monad-instances"
-    , notM (flag CcLlvmBackend) ? arg "-optc-Wno-error=inline"
-    , flag CcLlvmBackend ? arg "-optc-Wno-unknown-pragmas"
+    , notM (staged (buildFlag CcLlvmBackend)) ? arg "-optc-Wno-error=inline"
+    , staged (buildFlag CcLlvmBackend) ? arg "-optc-Wno-unknown-pragmas"
       -- Cabal can seemingly produce filepaths with incorrect case on filesystems
       -- with case-insensitive names. Ignore such issues for now as they seem benign.
       -- See #17798.
-    , isOsxTarget stage ? arg "-optP-Wno-nonportable-include-path"
-    , isWinTarget stage ? arg "-optP-Wno-nonportable-include-path"
+    , staged isOsxTarget ? arg "-optP-Wno-nonportable-include-path"
+    , staged isWinTarget ? arg "-optP-Wno-nonportable-include-path"
     ]
 
 -- | Package-specific warnings-related arguments, mostly suppressing various warnings.



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f3e44e88a241706a07b9ad363f409eba5f3f34d3...4a8b0a9ac64a3e6afb701ea809684230a444f8d1

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f3e44e88a241706a07b9ad363f409eba5f3f34d3...4a8b0a9ac64a3e6afb701ea809684230a444f8d1
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/20240926/d72ed4ac/attachment-0001.html>


More information about the ghc-commits mailing list