From cd7f0356d53deeec580fb9aa24b484d11a42eb7f Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Mon, 7 Oct 2024 16:30:59 +0000
Subject: [PATCH] hadrian/testsuite: implement config.cross logic

This commit implements the config.cross field in the testsuite driver.
It comes from the "cross compiling" ghc info field for both
in-tree/out-of-tree GHC, and is an accurate predicate of whether we're
cross-compiling or not (compared to the precense of target emulator),
and is useful to implement predicates to assert the precense of
internal interpreter (only available on non-cross GHC) for tests that
do require it (e.g. plugins).

(cherry picked from commit 2956a3f7ecd58a6fda81447100404941c0ed837d)
(cherry picked from commit 5500e1b3ac24643912487f0e015c1ce63aa96e89)
---
 hadrian/src/Oracles/TestSettings.hs      | 3 ++-
 hadrian/src/Settings/Builders/RunTest.hs | 3 +++
 testsuite/driver/testglobals.py          | 3 +++
 testsuite/ghc-config/ghc-config.hs       | 1 +
 4 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/hadrian/src/Oracles/TestSettings.hs b/hadrian/src/Oracles/TestSettings.hs
index 6abcb88dafd..6b9621b4136 100644
--- a/hadrian/src/Oracles/TestSettings.hs
+++ b/hadrian/src/Oracles/TestSettings.hs
@@ -30,6 +30,7 @@ data TestSetting = TestHostOS
                  | TestGhcDebugAssertions
                  | TestGhcWithNativeCodeGen
                  | TestGhcWithInterpreter
+                 | TestGhcCrossCompiling
                  | TestGhcWithRtsLinker
                  | TestGhcUnregisterised
                  | TestGhcTablesNextToCode
@@ -62,6 +63,7 @@ testSetting key = do
         TestGhcDebugAssertions    -> "GhcDebugAssertions"
         TestGhcWithNativeCodeGen  -> "GhcWithNativeCodeGen"
         TestGhcWithInterpreter    -> "GhcWithInterpreter"
+        TestGhcCrossCompiling     -> "CrossCompiling"
         TestGhcWithRtsLinker      -> "GhcWithRtsLinker"
         TestGhcUnregisterised     -> "GhcUnregisterised"
         TestGhcTablesNextToCode   -> "GhcTablesNextToCode"
@@ -126,4 +128,3 @@ stageOfTestCompiler "stage1" = Just stage0InTree
 stageOfTestCompiler "stage2" = Just Stage1
 stageOfTestCompiler "stage3" = Just Stage2
 stageOfTestCompiler _ = Nothing
-
diff --git a/hadrian/src/Settings/Builders/RunTest.hs b/hadrian/src/Settings/Builders/RunTest.hs
index 26dbe8acdea..0c5beac4812 100644
--- a/hadrian/src/Settings/Builders/RunTest.hs
+++ b/hadrian/src/Settings/Builders/RunTest.hs
@@ -65,6 +65,7 @@ data TestCompilerArgs = TestCompilerArgs{
  ,   leadingUnderscore :: Bool
  ,   withNativeCodeGen :: Bool
  ,   withInterpreter   :: Bool
+ ,   cross             :: Bool
  ,   unregisterised    :: Bool
  ,   tables_next_to_code :: Bool
  ,   targetWithSMP       :: Bool  -- does the target support SMP
@@ -156,6 +157,7 @@ outOfTreeCompilerArgs = do
     leadingUnderscore   <- getBooleanSetting TestLeadingUnderscore
     withNativeCodeGen   <- getBooleanSetting TestGhcWithNativeCodeGen
     withInterpreter     <- getBooleanSetting TestGhcWithInterpreter
+    cross               <- getBooleanSetting TestGhcCrossCompiling
     unregisterised      <- getBooleanSetting TestGhcUnregisterised
     tables_next_to_code <- getBooleanSetting TestGhcTablesNextToCode
     targetWithSMP       <- targetSupportsSMP
@@ -272,6 +274,7 @@ runTestBuilderArgs = builder Testsuite ? do
 
 
             , arg "-e", arg $ "config.have_interp=" ++ show withInterpreter
+            , arg "-e", arg $ "config.cross=" ++ show cross
             , arg "-e", arg $ "config.unregisterised=" ++ show unregisterised
             , arg "-e", arg $ "config.tables_next_to_code=" ++ show tables_next_to_code
 
diff --git a/testsuite/driver/testglobals.py b/testsuite/driver/testglobals.py
index e709ad9738e..f1e0a18bde2 100644
--- a/testsuite/driver/testglobals.py
+++ b/testsuite/driver/testglobals.py
@@ -139,6 +139,9 @@ class TestConfig:
         # Do we have interpreter support?
         self.have_interp = False
 
+        # Are we cross-compiling?
+        self.cross = False
+
         # Do we have RTS linker?
         self.have_RTS_linker = False
 
diff --git a/testsuite/ghc-config/ghc-config.hs b/testsuite/ghc-config/ghc-config.hs
index b792643dbb5..1ed382dbbc6 100644
--- a/testsuite/ghc-config/ghc-config.hs
+++ b/testsuite/ghc-config/ghc-config.hs
@@ -22,6 +22,7 @@ main = do
   getGhcFieldOrFail fields "GhcDebugAssertions" "Debug on"
   getGhcFieldOrFail fields "GhcWithNativeCodeGen" "Have native code generator"
   getGhcFieldOrFail fields "GhcWithInterpreter" "Have interpreter"
+  getGhcFieldOrFail fields "CrossCompiling" "cross compiling"
   getGhcFieldOrFail fields "GhcWithRtsLinker" "target has RTS linker"
   getGhcFieldOrFail fields "GhcUnregisterised" "Unregisterised"
   getGhcFieldOrFail fields "GhcWithSMP" "Support SMP"
-- 
GitLab