From b562e3a6fab87422f40997f84b11a05505df2fcb Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Wed, 16 Oct 2024 18:31:54 +0000
Subject: [PATCH] driver: fix getGccSearchDirectory for wasm target

This commit fixes getGccSearchDirectory logic for wasm target, ensures
the correct search directory containing libc.so etc can be found by
GHC. getGccSearchDirectory is also exported so it can be used
elsewhere to obtain the wasi-sdk libdir and pass to the dyld script.
---
 compiler/GHC/Linker/Loader.hs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/compiler/GHC/Linker/Loader.hs b/compiler/GHC/Linker/Loader.hs
index d05539c4612..c3ffd24c040 100644
--- a/compiler/GHC/Linker/Loader.hs
+++ b/compiler/GHC/Linker/Loader.hs
@@ -32,6 +32,7 @@ module GHC.Linker.Loader
    , rmDupLinkables
    , modifyLoaderState
    , initLinkDepsOpts
+   , getGccSearchDirectory
    )
 where
 
@@ -1496,12 +1497,11 @@ searchForLibUsingGcc logger dflags so dirs = do
 --   libraries and components. See Note [Fork/Exec Windows].
 getGCCPaths :: Logger -> DynFlags -> OS -> IO [FilePath]
 getGCCPaths logger dflags os
-  = case os of
-      OSMinGW32 ->
+  | os == OSMinGW32 || platformArch (targetPlatform dflags) == ArchWasm32 =
         do gcc_dirs <- getGccSearchDirectory logger dflags "libraries"
            sys_dirs <- getSystemDirectories
            return $ nub $ gcc_dirs ++ sys_dirs
-      _         -> return []
+  | otherwise = return []
 
 -- | Cache for the GCC search directories as this can't easily change
 --   during an invocation of GHC. (Maybe with some env. variable but we'll)
@@ -1534,7 +1534,7 @@ getGccSearchDirectory logger dflags key = do
                   modifyIORef' gccSearchDirCache ((key, dirs):)
                   return val
       where split :: FilePath -> [FilePath]
-            split r = case break (==';') r of
+            split r = case break (`elem` [';', ':']) r of
                         (s, []    ) -> [s]
                         (s, (_:xs)) -> s : split xs
 
-- 
GitLab