From a998f69d2de062b7290e78221d55e8c49bf95bbc Mon Sep 17 00:00:00 2001 From: Cheng Shao <terrorjack@type.dance> Date: Mon, 16 Sep 2024 06:09:22 +0000 Subject: [PATCH] ghc-internal: add missing CPPs for wasm This patch adds some missing CPP guards to ghc-internal, given those functions are non existent on wasm and would cause linking issues. --- .../ghc-internal/src/GHC/Internal/Conc/Bound.hs | 13 +++++++++++-- .../src/GHC/Internal/System/Posix/Internals.hs | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libraries/ghc-internal/src/GHC/Internal/Conc/Bound.hs b/libraries/ghc-internal/src/GHC/Internal/Conc/Bound.hs index 8bde7c57452..c4acb7d3429 100644 --- a/libraries/ghc-internal/src/GHC/Internal/Conc/Bound.hs +++ b/libraries/ghc-internal/src/GHC/Internal/Conc/Bound.hs @@ -112,13 +112,21 @@ forkOS_entry stableAction = do action <- deRefStablePtr stableAction action -foreign import ccall forkOS_createThread - :: StablePtr (IO ()) -> IO CInt + failNonThreaded :: IO a failNonThreaded = fail $ "RTS doesn't support multiple OS threads " ++"(use ghc -threaded when linking)" +#if defined(wasm32_HOST_ARCH) + +forkOS _ = failNonThreaded + +#else + +foreign import ccall forkOS_createThread + :: StablePtr (IO ()) -> IO CInt + forkOS action0 | rtsSupportsBoundThreads = do mv <- newEmptyMVar @@ -141,6 +149,7 @@ forkOS action0 freeStablePtr entry return tid | otherwise = failNonThreaded +#endif -- | Like 'forkIOWithUnmask', but the child thread is a bound thread, -- as with 'forkOS'. diff --git a/libraries/ghc-internal/src/GHC/Internal/System/Posix/Internals.hs b/libraries/ghc-internal/src/GHC/Internal/System/Posix/Internals.hs index cdb05265444..db100866e0a 100644 --- a/libraries/ghc-internal/src/GHC/Internal/System/Posix/Internals.hs +++ b/libraries/ghc-internal/src/GHC/Internal/System/Posix/Internals.hs @@ -745,8 +745,13 @@ foreign import capi unsafe "HsBase.h read" foreign import capi safe "HsBase.h read" c_safe_read :: CInt -> Ptr Word8 -> CSize -> IO CSsize +#if !defined(HAVE_UMASK) +c_umask :: CMode -> IO CMode +c_umask _ = ioError (ioeSetLocation unsupportedOperation "umask") +#else foreign import ccall unsafe "HsBase.h umask" c_umask :: CMode -> IO CMode +#endif -- See Note [Windows types] foreign import capi unsafe "HsBase.h write" -- GitLab