From 7608bc46537ed2f171d08425b3517f2bc857456b Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Thu, 3 Oct 2024 16:46:15 +0000
Subject: [PATCH] hadrian/compiler: flip on support for shared libs & ghci for
 wasm

This commit flips on the support for shared libs and ghci for the wasm
target, given all required support logic has been added in previous
commits.

(cherry picked from commit 652e72394b715abc931b1104a4b683bb16909695)
(cherry picked from commit e11dc80550084af2ea8aeba96e8a2a8a67468c03)
---
 compiler/GHC/Platform.hs                                    | 1 -
 hadrian/src/Oracles/Flag.hs                                 | 3 +--
 hadrian/src/Oracles/Setting.hs                              | 6 ++++--
 hadrian/src/Settings/Builders/RunTest.hs                    | 2 +-
 .../driver/T20696/T20696-static.stderr-wasm32-unknown-wasi  | 3 +++
 5 files changed, 9 insertions(+), 6 deletions(-)
 create mode 100644 testsuite/tests/driver/T20696/T20696-static.stderr-wasm32-unknown-wasi

diff --git a/compiler/GHC/Platform.hs b/compiler/GHC/Platform.hs
index 57b27f1ac27..f7cb79c7fad 100644
--- a/compiler/GHC/Platform.hs
+++ b/compiler/GHC/Platform.hs
@@ -256,7 +256,6 @@ platformHasRTSLinker p = case archOS_arch (platformArchOS p) of
   ArchS390X         -> False
   ArchLoongArch64   -> False
   ArchJavaScript    -> False
-  ArchWasm32        -> False
   _                 -> True
 
 
diff --git a/hadrian/src/Oracles/Flag.hs b/hadrian/src/Oracles/Flag.hs
index 5f2d66f7ec3..e1328150c10 100644
--- a/hadrian/src/Oracles/Flag.hs
+++ b/hadrian/src/Oracles/Flag.hs
@@ -110,11 +110,10 @@ platformSupportsSharedLibs :: Action Bool
 -- FIXME: This is querying about the target but is named "platformXXX", targetSupportsSharedLibs would be better
 platformSupportsSharedLibs = do
     windows       <- isWinTarget
-    wasm          <- anyTargetArch [ ArchWasm32 ]
     ppc_linux     <- (&&) <$> anyTargetArch [ ArchPPC ] <*> anyTargetOs [ OSLinux ]
     solaris       <- (&&) <$> anyTargetArch [ ArchX86 ] <*> anyTargetOs [ OSSolaris2 ]
     javascript    <- anyTargetArch     [ ArchJavaScript ]
-    return $ not (windows || wasm || javascript || ppc_linux || solaris)
+    return $ not (windows || javascript || ppc_linux || solaris)
 
 -- | Does the target support threaded RTS?
 targetSupportsThreadedRts :: Action Bool
diff --git a/hadrian/src/Oracles/Setting.hs b/hadrian/src/Oracles/Setting.hs
index ea91a450fa0..5818750e407 100644
--- a/hadrian/src/Oracles/Setting.hs
+++ b/hadrian/src/Oracles/Setting.hs
@@ -200,12 +200,14 @@ ghcWithInterpreter :: Action Bool
 ghcWithInterpreter = do
     goodOs <- anyTargetOs [ OSMinGW32, OSLinux, OSSolaris2 -- TODO "cygwin32"?,
                           , OSFreeBSD, OSDragonFly, OSNetBSD, OSOpenBSD
-                          , OSDarwin, OSKFreeBSD ]
+                          , OSDarwin, OSKFreeBSD
+                          , OSWasi ]
     goodArch <- (||) <$>
                 anyTargetArch [ ArchX86, ArchX86_64, ArchPPC
                               , ArchAArch64, ArchS390X
                               , ArchPPC_64 ELF_V1, ArchPPC_64 ELF_V2
-                              , ArchRISCV64 ]
+                              , ArchRISCV64
+                              , ArchWasm32 ]
                               <*> isArmTarget
     return $ goodOs && goodArch
 
diff --git a/hadrian/src/Settings/Builders/RunTest.hs b/hadrian/src/Settings/Builders/RunTest.hs
index 316a9ea6c8e..8032f002af2 100644
--- a/hadrian/src/Settings/Builders/RunTest.hs
+++ b/hadrian/src/Settings/Builders/RunTest.hs
@@ -142,7 +142,7 @@ inTreeCompilerArgs stg = do
     -- For this information, we need to query ghc --info, however, that would
     -- require building ghc, which we don't want to do here. Therefore, the
     -- logic from `platformHasRTSLinker` is duplicated here.
-    let rtsLinker = not $ arch `elem` ["powerpc", "powerpc64", "powerpc64le", "s390x", "loongarch64", "javascript", "wasm32"]
+    let rtsLinker = not $ arch `elem` ["powerpc", "powerpc64", "powerpc64le", "s390x", "loongarch64", "javascript"]
 
     return TestCompilerArgs{..}
 
diff --git a/testsuite/tests/driver/T20696/T20696-static.stderr-wasm32-unknown-wasi b/testsuite/tests/driver/T20696/T20696-static.stderr-wasm32-unknown-wasi
new file mode 100644
index 00000000000..54d5ad5bddc
--- /dev/null
+++ b/testsuite/tests/driver/T20696/T20696-static.stderr-wasm32-unknown-wasi
@@ -0,0 +1,3 @@
+[1 of 3] Compiling C                ( C.hs, C.o, C.dyn_o )
+[2 of 3] Compiling B                ( B.hs, B.o )
+[3 of 3] Compiling A                ( A.hs, A.o )
-- 
GitLab