diff --git a/cabal.project b/cabal.project index 348279108..4b7c12563 100644 --- a/cabal.project +++ b/cabal.project @@ -88,41 +88,46 @@ if arch(wasm32) source-repository-package type: git - location: https://github.com/haskell-wasm/conduit.git - tag: ff33329247f2ef321dcab836e98c1bcfaff2bd13 + location: https://github.com/snoyberg/conduit.git + tag: 6b98f070fea09a3bf0a5d0897a2e27e3aa91c8fe subdir: conduit-extra + post-checkout-command: sh -c "patch -N -p1 < ../../../wasm/patches/conduit-extra.patch" source-repository-package type: git - location: https://github.com/haskell-wasm/foundation.git - tag: 8e6dd48527fb429c1922083a5030ef88e3d58dd3 + location: https://github.com/haskell-foundation/foundation.git + tag: foundation-v0.0.30 subdir: basement + post-checkout-command: sh -c "patch -N -p1 < ../../../wasm/patches/basement.patch" source-repository-package type: git - location: https://github.com/haskell-wasm/hs-memory.git - tag: a198a76c584dc2cfdcde6b431968de92a5fed65e + location: https://github.com/vincenthz/hs-memory.git + tag: memory-v0.18.0 + post-checkout-command: sh -c "patch -N -p1 < ../../../wasm/patches/memory.patch" source-repository-package type: git - location: https://github.com/haskell-wasm/streaming-commons.git - tag: 7e9c38b2fd55ce50d3f74fe708ca47db8c9bb315 + location: https://github.com/fpco/streaming-commons.git + tag: v0.2.3.1 + post-checkout-command: sh -c "patch -N -p1 < ../../../wasm/patches/streaming-commons.patch" source-repository-package type: git - location: https://github.com/haskell-wasm/xml.git - tag: bc793dc9bc29c92245d3482a54d326abd3ae1403 + location: https://github.com/snoyberg/xml.git + tag: xml-conduit/1.10.1.0 subdir: xml-conduit + post-checkout-command: sh -c "patch -N -p1 < ../../../wasm/patches/xml-conduit.patch" - -- https://github.com/haskellari/splitmix/pull/73 source-repository-package type: git - location: https://github.com/amesgen/splitmix - tag: 5f5b766d97dc735ac228215d240a3bb90bc2ff75 + location: https://github.com/haskellari/splitmix.git + tag: v0.1.3.2 + post-checkout-command: sh -c "patch -N -p1 < ../../../wasm/patches/splitmix.patch" source-repository-package type: git location: https://github.com/hslua/hslua tag: lua-2.3.4 subdir: lua - post-checkout-command: sh -c "patch -N -p1 < ../../../wasm/patches/lua-tmpfile.patch && patch -N -p1 < ../../../wasm/patches/lua-tmpnam.patch && patch -N -p1 < ../../../wasm/patches/lua-system.patch" + post-checkout-command: sh -c "patch -N -p1 < ../../../wasm/patches/lua.patch" diff --git a/pandoc.cabal b/pandoc.cabal index dc99fe5bd..32dc8b8eb 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -212,6 +212,10 @@ extra-source-files: -- documentation INSTALL.md, AUTHORS.md, README.md, CONTRIBUTING.md, BUGS, + -- patches for dependencies to build with wasm32 + wasm/patches/*.patch + -- JavaScript interface for pandoc.wasm + wasm/pandoc.js -- tests test/bodybg.gif test/*.native diff --git a/wasm/patches/basement.patch b/wasm/patches/basement.patch new file mode 100644 index 000000000..d13ae036e --- /dev/null +++ b/wasm/patches/basement.patch @@ -0,0 +1,306 @@ +--- a/basement/Basement/Bits.hs ++++ b/basement/Basement/Bits.hs +@@ -53,10 +53,6 @@ import GHC.Word + import GHC.Int + import Basement.Compat.Primitive + +-#if WORD_SIZE_IN_BITS < 64 +-import GHC.IntWord64 +-#endif +- + -- | operation over finite bits + class FiniteBitsOps bits where + -- | get the number of bits in the given object +--- a/basement/Basement/From.hs ++++ b/basement/Basement/From.hs +@@ -272,23 +272,14 @@ instance (NatWithinBound (CountOf ty) n, KnownNat n, PrimType ty) + tryFrom = BlockN.toBlockN . UArray.toBlock . BoxArray.mapToUnboxed id + + instance (KnownNat n, NatWithinBound Word8 n) => From (Zn64 n) Word8 where +-#if __GLASGOW_HASKELL__ >= 904 +- from = narrow . unZn64 where narrow (W64# w) = W8# (wordToWord8# (word64ToWord# (GHC.Prim.word64ToWord# w))) +-#else +- from = narrow . unZn64 where narrow (W64# w) = W8# (wordToWord8# (word64ToWord# w)) +-#endif ++ from = narrow . unZn64 where narrow (W64# w) = W8# (wordToWord8# (GHC.Prim.word64ToWord# w)) ++ + instance (KnownNat n, NatWithinBound Word16 n) => From (Zn64 n) Word16 where +-#if __GLASGOW_HASKELL__ >= 904 +- from = narrow . unZn64 where narrow (W64# w) = W16# (wordToWord16# (word64ToWord# (GHC.Prim.word64ToWord# w))) +-#else +- from = narrow . unZn64 where narrow (W64# w) = W16# (wordToWord16# (word64ToWord# w)) +-#endif ++ from = narrow . unZn64 where narrow (W64# w) = W16# (wordToWord16# (GHC.Prim.word64ToWord# w)) ++ + instance (KnownNat n, NatWithinBound Word32 n) => From (Zn64 n) Word32 where +-#if __GLASGOW_HASKELL__ >= 904 +- from = narrow . unZn64 where narrow (W64# w) = W32# (wordToWord32# (word64ToWord# (GHC.Prim.word64ToWord# w))) +-#else +- from = narrow . unZn64 where narrow (W64# w) = W32# (wordToWord32# (word64ToWord# w)) +-#endif ++ from = narrow . unZn64 where narrow (W64# w) = W32# (wordToWord32# (GHC.Prim.word64ToWord# w)) ++ + instance From (Zn64 n) Word64 where + from = unZn64 + instance From (Zn64 n) Word128 where +@@ -297,23 +288,14 @@ instance From (Zn64 n) Word256 where + from = from . unZn64 + + instance (KnownNat n, NatWithinBound Word8 n) => From (Zn n) Word8 where +-#if __GLASGOW_HASKELL__ >= 904 +- from = narrow . naturalToWord64 . unZn where narrow (W64# w) = W8# (wordToWord8# (word64ToWord# (GHC.Prim.word64ToWord# w))) +-#else +- from = narrow . naturalToWord64 . unZn where narrow (W64# w) = W8# (wordToWord8# (word64ToWord# w)) +-#endif ++ from = narrow . naturalToWord64 . unZn where narrow (W64# w) = W8# (wordToWord8# (GHC.Prim.word64ToWord# w)) ++ + instance (KnownNat n, NatWithinBound Word16 n) => From (Zn n) Word16 where +-#if __GLASGOW_HASKELL__ >= 904 +- from = narrow . naturalToWord64 . unZn where narrow (W64# w) = W16# (wordToWord16# (word64ToWord# (GHC.Prim.word64ToWord# w))) +-#else +- from = narrow . naturalToWord64 . unZn where narrow (W64# w) = W16# (wordToWord16# (word64ToWord# w)) +-#endif ++ from = narrow . naturalToWord64 . unZn where narrow (W64# w) = W16# (wordToWord16# (GHC.Prim.word64ToWord# w)) ++ + instance (KnownNat n, NatWithinBound Word32 n) => From (Zn n) Word32 where +-#if __GLASGOW_HASKELL__ >= 904 +- from = narrow . naturalToWord64 . unZn where narrow (W64# w) = W32# (wordToWord32# (word64ToWord# (GHC.Prim.word64ToWord# w))) +-#else +- from = narrow . naturalToWord64 . unZn where narrow (W64# w) = W32# (wordToWord32# (word64ToWord# w)) +-#endif ++ from = narrow . naturalToWord64 . unZn where narrow (W64# w) = W32# (wordToWord32# (GHC.Prim.word64ToWord# w)) ++ + instance (KnownNat n, NatWithinBound Word64 n) => From (Zn n) Word64 where + from = naturalToWord64 . unZn + instance (KnownNat n, NatWithinBound Word128 n) => From (Zn n) Word128 where +--- a/basement/Basement/Numerical/Additive.hs ++++ b/basement/Basement/Numerical/Additive.hs +@@ -29,10 +29,6 @@ import Basement.Types.Word256 (Word256) + import qualified Basement.Types.Word128 as Word128 + import qualified Basement.Types.Word256 as Word256 + +-#if WORD_SIZE_IN_BITS < 64 +-import GHC.IntWord64 +-#endif +- + -- | Represent class of things that can be added together, + -- contains a neutral element and is commutative. + -- +@@ -80,15 +76,9 @@ instance Additive Int32 where + instance Additive Int64 where + azero = 0 + #if WORD_SIZE_IN_BITS == 64 +-#if __GLASGOW_HASKELL__ >= 904 + (I64# a) + (I64# b) = I64# (GHC.Prim.intToInt64# (GHC.Prim.int64ToInt# a +# GHC.Prim.int64ToInt# b)) +- +-#else +- (I64# a) + (I64# b) = I64# (a +# b) +- +-#endif + #else +- (I64# a) + (I64# b) = I64# (a `plusInt64#` b) ++ (I64# a) + (I64# b) = I64# (a `GHC.Prim.plusInt64#` b) + #endif + scale = scaleNum + instance Additive Word where +@@ -114,15 +104,9 @@ instance Additive Word32 where + instance Additive Word64 where + azero = 0 + #if WORD_SIZE_IN_BITS == 64 +-#if __GLASGOW_HASKELL__ >= 904 + (W64# a) + (W64# b) = W64# (GHC.Prim.wordToWord64# (GHC.Prim.word64ToWord# a `plusWord#` GHC.Prim.word64ToWord# b)) +- +-#else +- (W64# a) + (W64# b) = W64# (a `plusWord#` b) +- +-#endif + #else +- (W64# a) + (W64# b) = W64# (int64ToWord64# (word64ToInt64# a `plusInt64#` word64ToInt64# b)) ++ (W64# a) + (W64# b) = W64# (GHC.Prim.int64ToWord64# (GHC.Prim.word64ToInt64# a `GHC.Prim.plusInt64#` GHC.Prim.word64ToInt64# b)) + #endif + scale = scaleNum + instance Additive Word128 where +--- a/basement/Basement/Numerical/Conversion.hs ++++ b/basement/Basement/Numerical/Conversion.hs +@@ -19,16 +19,12 @@ module Basement.Numerical.Conversion + #include "MachDeps.h" + + import GHC.Types +-import GHC.Prim hiding (word64ToWord#) ++import GHC.Prim + import qualified GHC.Prim + import GHC.Int + import GHC.Word + import Basement.Compat.Primitive + +-#if WORD_SIZE_IN_BITS < 64 +-import GHC.IntWord64 +-#endif +- + intToInt64 :: Int -> Int64 + #if WORD_SIZE_IN_BITS == 64 + #if __GLASGOW_HASKELL__ >= 904 +@@ -41,15 +37,7 @@ intToInt64 (I# i) = I64# (intToInt64# i) + #endif + + int64ToInt :: Int64 -> Int +-#if WORD_SIZE_IN_BITS == 64 +-#if __GLASGOW_HASKELL__ >= 904 + int64ToInt (I64# i) = I# (int64ToInt# i) +-#else +-int64ToInt (I64# i) = I# i +-#endif +-#else +-int64ToInt (I64# i) = I# (int64ToInt# i) +-#endif + + wordToWord64 :: Word -> Word64 + #if WORD_SIZE_IN_BITS == 64 +@@ -63,15 +51,7 @@ wordToWord64 (W# i) = W64# (wordToWord64# i) + #endif + + word64ToWord :: Word64 -> Word +-#if WORD_SIZE_IN_BITS == 64 +-#if __GLASGOW_HASKELL__ >= 904 +-word64ToWord (W64# i) = W# (GHC.Prim.word64ToWord# i) +-#else +-word64ToWord (W64# i) = W# i +-#endif +-#else + word64ToWord (W64# i) = W# (word64ToWord# i) +-#endif + + word64ToInt64 :: Word64 -> Int64 + #if WORD_SIZE_IN_BITS == 64 +@@ -105,17 +85,8 @@ word64ToWord# i = i + data Word32x2 = Word32x2 {-# UNPACK #-} !Word32 + {-# UNPACK #-} !Word32 + +-#if WORD_SIZE_IN_BITS == 64 + word64ToWord32s :: Word64 -> Word32x2 +-#if __GLASGOW_HASKELL__ >= 904 +-word64ToWord32s (W64# w64) = Word32x2 (W32# (wordToWord32# (uncheckedShiftRL# (GHC.Prim.word64ToWord# w64 ) 32#))) (W32# (wordToWord32# (GHC.Prim.word64ToWord# w64))) +-#else +-word64ToWord32s (W64# w64) = Word32x2 (W32# (wordToWord32# (uncheckedShiftRL# w64 32#))) (W32# (wordToWord32# w64)) +-#endif +-#else +-word64ToWord32s :: Word64 -> Word32x2 +-word64ToWord32s (W64# w64) = Word32x2 (W32# (word64ToWord# (uncheckedShiftRL64# w64 32#))) (W32# (word64ToWord# w64)) +-#endif ++word64ToWord32s (W64# w64) = Word32x2 (W32# (wordToWord32# (word64ToWord# (uncheckedShiftRL64# w64 32#)))) (W32# (wordToWord32# (GHC.Prim.word64ToWord# w64))) + + wordToChar :: Word -> Char + wordToChar (W# word) = C# (chr# (word2Int# word)) +--- a/basement/Basement/PrimType.hs ++++ b/basement/Basement/PrimType.hs +@@ -53,10 +53,6 @@ import Basement.Monad + import Basement.Nat + import qualified Prelude (quot) + +-#if WORD_SIZE_IN_BITS < 64 +-import GHC.IntWord64 +-#endif +- + #ifdef FOUNDATION_BOUNDS_CHECK + + divBytes :: PrimType ty => Offset ty -> (Int -> Int) +--- a/basement/Basement/Terminal/Size.hsc ++++ b/basement/Basement/Terminal/Size.hsc +@@ -31,6 +31,13 @@ import Graphics.Win32.Misc (getStdHandle, sTD_OUTPUT_HANDLE, StdHandle + #let alignment t = "%lu", (unsigned long)offsetof(struct {char x__; t (y__); }, y__) + #endif + ++#if defined(wasm32_HOST_ARCH) ++ ++getDimensions :: IO (CountOf Char, CountOf Char) ++getDimensions = error "Basement.Terminal.Size.getDimensions" ++ ++#else ++ + #ifdef FOUNDATION_SYSTEM_UNIX + data Winsize = Winsize + { ws_row :: !Word16 +@@ -188,3 +195,5 @@ getDimensions = + #endif + where + defaultSize = (80, 24) ++ ++#endif +--- a/basement/Basement/Types/OffsetSize.hs ++++ b/basement/Basement/Types/OffsetSize.hs +@@ -69,10 +69,6 @@ import Basement.IntegralConv + import Data.List (foldl') + import qualified Prelude + +-#if WORD_SIZE_IN_BITS < 64 +-import GHC.IntWord64 +-#endif +- + -- | File size in bytes + newtype FileSize = FileSize Word64 + deriving (Show,Eq,Ord) +@@ -225,49 +221,31 @@ countOfRoundUp alignment (CountOf n) = CountOf ((n + (alignment-1)) .&. compleme + + csizeOfSize :: CountOf Word8 -> CSize + #if WORD_SIZE_IN_BITS < 64 +-csizeOfSize (CountOf (I# sz)) = CSize (W32# (int2Word# sz)) ++csizeOfSize (CountOf (I# sz)) = CSize (W32# (wordToWord32# (int2Word# sz))) + #else +-#if __GLASGOW_HASKELL__ >= 904 + csizeOfSize (CountOf (I# sz)) = CSize (W64# (wordToWord64# (int2Word# sz))) +- +-#else +-csizeOfSize (CountOf (I# sz)) = CSize (W64# (int2Word# sz)) +- +-#endif + #endif + + csizeOfOffset :: Offset8 -> CSize + #if WORD_SIZE_IN_BITS < 64 +-csizeOfOffset (Offset (I# sz)) = CSize (W32# (int2Word# sz)) ++csizeOfOffset (Offset (I# sz)) = CSize (W32# (wordToWord32# (int2Word# sz))) + #else +-#if __GLASGOW_HASKELL__ >= 904 + csizeOfOffset (Offset (I# sz)) = CSize (W64# (wordToWord64# (int2Word# sz))) +-#else +-csizeOfOffset (Offset (I# sz)) = CSize (W64# (int2Word# sz)) +-#endif + #endif + + sizeOfCSSize :: CSsize -> CountOf Word8 + sizeOfCSSize (CSsize (-1)) = error "invalid size: CSSize is -1" + #if WORD_SIZE_IN_BITS < 64 +-sizeOfCSSize (CSsize (I32# sz)) = CountOf (I# sz) ++sizeOfCSSize (CSsize (I32# sz)) = CountOf (I# (int32ToInt# sz)) + #else +-#if __GLASGOW_HASKELL__ >= 904 + sizeOfCSSize (CSsize (I64# sz)) = CountOf (I# (int64ToInt# sz)) +-#else +-sizeOfCSSize (CSsize (I64# sz)) = CountOf (I# sz) +-#endif + #endif + + sizeOfCSize :: CSize -> CountOf Word8 + #if WORD_SIZE_IN_BITS < 64 +-sizeOfCSize (CSize (W32# sz)) = CountOf (I# (word2Int# sz)) ++sizeOfCSize (CSize (W32# sz)) = CountOf (I# (word2Int# (word32ToWord# sz))) + #else +-#if __GLASGOW_HASKELL__ >= 904 + sizeOfCSize (CSize (W64# sz)) = CountOf (I# (word2Int# (word64ToWord# sz))) +-#else +-sizeOfCSize (CSize (W64# sz)) = CountOf (I# (word2Int# sz)) +-#endif + #endif + + natValCountOf :: forall n ty proxy . (KnownNat n, NatWithinBound (CountOf ty) n) => proxy n -> CountOf ty +--- a/basement/cbits/foundation_system.h ++++ b/basement/cbits/foundation_system.h +@@ -53,6 +53,8 @@ + #elif defined(_POSIX_VERSION) + #define FOUNDATION_SYSTEM_UNIX + // POSIX ++#elif defined(wasm32_HOST_ARCH) ++ #define FOUNDATION_SYSTEM_UNIX + #else + # error "foundation: system: Unknown compiler" + #endif diff --git a/wasm/patches/conduit-extra.patch b/wasm/patches/conduit-extra.patch new file mode 100644 index 000000000..c287d1a12 --- /dev/null +++ b/wasm/patches/conduit-extra.patch @@ -0,0 +1,44 @@ +--- a/conduit-extra/conduit-extra.cabal ++++ b/conduit-extra/conduit-extra.cabal +@@ -26,9 +26,6 @@ Library + Data.Conduit.Filesystem + Data.Conduit.Foldl + Data.Conduit.Lazy +- Data.Conduit.Network +- Data.Conduit.Network.UDP +- Data.Conduit.Network.Unix + Data.Conduit.Process + Data.Conduit.Process.Typed + Data.Conduit.Text +@@ -38,6 +35,12 @@ Library + -- These architectures are able to perform unaligned memory accesses + cpp-options: -DALLOW_UNALIGNED_ACCESS + ++ if !arch(wasm32) ++ Exposed-modules: Data.Conduit.Network ++ Data.Conduit.Network.UDP ++ if !os(windows) && !arch(wasm32) ++ Exposed-modules: Data.Conduit.Network.Unix ++ + Build-depends: base >= 4.12 && < 5 + , conduit >= 1.3 && < 1.4 + +@@ -49,7 +52,6 @@ Library + , async + , attoparsec >= 0.10 + , directory + , filepath +- , network >= 2.3 + , primitive >= 0.5 + , process + , resourcet >= 1.1 +@@ -58,6 +60,9 @@ Library + , unliftio-core + , typed-process >= 0.2.6 + ++ if !arch(wasm32) ++ Build-depends: network >= 2.3 ++ + ghc-options: -Wall + + test-suite test diff --git a/wasm/patches/lua.patch b/wasm/patches/lua.patch new file mode 100644 index 000000000..c79f8c79e --- /dev/null +++ b/wasm/patches/lua.patch @@ -0,0 +1,58 @@ +--- a/lua/cbits/lua-5.4.8/liolib.c ++++ b/lua/cbits/lua-5.4.8/liolib.c +@@ -301,10 +301,14 @@ + + + static int io_tmpfile (lua_State *L) { ++#if defined(LUA_STUB_TMPFILE) ++ return 1; ++#else + LStream *p = newfile(L); + errno = 0; + p->f = tmpfile(); + return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1; ++#endif + } + + +--- a/lua/cbits/lua-5.4.8/loslib.c ++++ b/lua/cbits/lua-5.4.8/loslib.c +@@ -101,7 +101,12 @@ + */ + #if !defined(lua_tmpnam) /* { */ + +-#if defined(LUA_USE_POSIX) /* { */ ++#if defined(LUA_STUB_TMPNAM) /* { */ ++ ++#define LUA_TMPNAMBUFSIZE 32 ++#define lua_tmpnam(b,e) { e = 1; } ++ ++#elif defined(LUA_USE_POSIX) /* }{ */ + + #include + +@@ -131,7 +136,7 @@ + /* }================================================================== */ + + +-#if !defined(l_system) ++#if !defined(l_system) && !defined(LUA_STUB_SYSTEM) + #if defined(LUA_USE_IOS) + /* Despite claiming to be ISO C, iOS does not implement 'system'. */ + #define l_system(cmd) ((cmd) == NULL ? 0 : -1) +@@ -142,6 +147,9 @@ + + + static int os_execute (lua_State *L) { ++#if defined(LUA_STUB_SYSTEM) ++ return 1; ++#else + const char *cmd = luaL_optstring(L, 1, NULL); + int stat; + errno = 0; +@@ -152,6 +160,7 @@ + lua_pushboolean(L, stat); /* true if there is a shell */ + return 1; + } ++#endif + } diff --git a/wasm/patches/memory.patch b/wasm/patches/memory.patch new file mode 100644 index 000000000..eca2f5537 --- /dev/null +++ b/wasm/patches/memory.patch @@ -0,0 +1,128 @@ +--- a/Data/Memory/Internal/CompatPrim64.hs ++++ b/Data/Memory/Internal/CompatPrim64.hs +@@ -150,14 +150,8 @@ + w64# w _ _ = w + + #elif WORD_SIZE_IN_BITS == 32 +-import GHC.IntWord64 +-import GHC.Prim (Word#) + +-timesWord64# :: Word64# -> Word64# -> Word64# +-timesWord64# a b = +- let !ai = word64ToInt64# a +- !bi = word64ToInt64# b +- in int64ToWord64# (timesInt64# ai bi) ++import GHC.Prim + + w64# :: Word# -> Word# -> Word# -> Word64# + w64# _ hw lw = +--- a/Data/Memory/MemMap/Posix.hsc ++++ b/Data/Memory/MemMap/Posix.hsc +@@ -17,7 +17,9 @@ + -- + ----------------------------------------------------------------------------- + ++#if !defined(wasm32_HOST_ARCH) + #include ++#endif + #include + + {-# LANGUAGE ForeignFunctionInterface #-} +@@ -117,18 +119,26 @@ + deriving (Show,Read,Eq) + + cvalueOfMemoryProts :: [MemoryProtection] -> CInt ++#if defined(wasm32_HOST_ARCH) ++cvalueOfMemoryProts _ = error "Data.Memory.MemMap.cvalueOfMemoryProts" ++#else + cvalueOfMemoryProts = foldl (.|.) 0 . map toProt + where toProt :: MemoryProtection -> CInt + toProt MemoryProtectionNone = (#const PROT_NONE) + toProt MemoryProtectionRead = (#const PROT_READ) + toProt MemoryProtectionWrite = (#const PROT_WRITE) + toProt MemoryProtectionExecute = (#const PROT_EXEC) ++#endif + + cvalueOfMemorySync :: [MemorySyncFlag] -> CInt ++#if defined(wasm32_HOST_ARCH) ++cvalueOfMemorySync _ = error "Data.Memory.MemMap.cvalueOfMemorySync" ++#else + cvalueOfMemorySync = foldl (.|.) 0 . map toSync + where toSync MemorySyncAsync = (#const MS_ASYNC) + toSync MemorySyncSync = (#const MS_SYNC) + toSync MemorySyncInvalidate = (#const MS_INVALIDATE) ++#endif + + -- | Map pages of memory. + -- +@@ -139,10 +149,13 @@ + memoryMap :: Maybe (Ptr a) -- ^ The address to map to if MapFixed is used. + -> CSize -- ^ The length of the mapping + -> [MemoryProtection] -- ^ the memory protection associated with the mapping +- -> MemoryMapFlag -- ^ ++ -> MemoryMapFlag -- ^ + -> Maybe Fd + -> COff + -> IO (Ptr a) ++#if defined(wasm32_HOST_ARCH) ++memoryMap _ _ _ _ _ _ = error "Data.Memory.MemMap.memoryMap" ++#else + memoryMap initPtr sz prots flag mfd off = + throwErrnoIf (== m1ptr) "mmap" (c_mmap (maybe nullPtr id initPtr) sz cprot cflags fd off) + where m1ptr = nullPtr `plusPtr` (-1) +@@ -161,6 +174,7 @@ + + toMapFlag MemoryMapShared = (#const MAP_SHARED) + toMapFlag MemoryMapPrivate = (#const MAP_PRIVATE) ++#endif + + -- | Unmap pages of memory + -- +@@ -172,6 +186,9 @@ + -- + -- call 'madvise' + memoryAdvise :: Ptr a -> CSize -> MemoryAdvice -> IO () ++#if defined(wasm32_HOST_ARCH) ++memoryAdvise _ _ _ = error "Data.Memory.MemMap.memoryAdvise" ++#else + memoryAdvise ptr sz adv = throwErrnoIfMinus1_ "madvise" (c_madvise ptr sz cadv) + where cadv = toAdvice adv + #if defined(POSIX_MADV_NORMAL) +@@ -187,6 +204,7 @@ + toAdvice MemoryAdviceWillNeed = (#const MADV_WILLNEED) + toAdvice MemoryAdviceDontNeed = (#const MADV_DONTNEED) + #endif ++#endif + + -- | lock a range of process address space + -- +--- a/Data/Memory/PtrMethods.hs ++++ b/Data/Memory/PtrMethods.hs +@@ -35,7 +35,7 @@ + memCreateTemporary size f = allocaBytesAligned size 8 f + + -- | xor bytes from source1 and source2 to destination +--- ++-- + -- d = s1 xor s2 + -- + -- s1, nor s2 are modified unless d point to s1 or s2 +@@ -63,7 +63,7 @@ + + -- | Copy a set number of bytes from @src to @dst + memCopy :: Ptr Word8 -> Ptr Word8 -> Int -> IO () +-memCopy dst src n = c_memcpy dst src (fromIntegral n) ++memCopy dst src n = c_memcpy dst src (fromIntegral n) >>= \_ -> return () + {-# INLINE memCopy #-} + + -- | Set @n number of bytes to the same value @v +@@ -114,7 +114,7 @@ + loop (i+1) (acc .|. e) + + foreign import ccall unsafe "memset" +- c_memset :: Ptr Word8 -> Word8 -> CSize -> IO () ++ c_memset :: Ptr Word8 -> Word8 -> CSize -> IO (Ptr Word8) + + foreign import ccall unsafe "memcpy" +- c_memcpy :: Ptr Word8 -> Ptr Word8 -> CSize -> IO () ++ c_memcpy :: Ptr Word8 -> Ptr Word8 -> CSize -> IO (Ptr Word8) diff --git a/wasm/patches/splitmix.patch b/wasm/patches/splitmix.patch new file mode 100644 index 000000000..f8ba6d857 --- /dev/null +++ b/wasm/patches/splitmix.patch @@ -0,0 +1,25 @@ +--- /dev/null ++++ b/cbits-wasi/init.c +@@ -0,0 +1,8 @@ ++#include ++#include ++ ++uint64_t splitmix_init() { ++ uint64_t result; ++ int r = getentropy(&result, sizeof(uint64_t)); ++ return r == 0 ? result : 0xfeed1000; ++} +--- a/splitmix.cabal ++++ b/splitmix.cabal +@@ -80,7 +80,10 @@ library + frameworks: Security + + else +- c-sources: cbits-unix/init.c ++ if arch(wasm32) ++ c-sources: cbits-wasi/init.c ++ else ++ c-sources: cbits-unix/init.c + + else + cpp-options: -DSPLITMIX_INIT_COMPAT=1 diff --git a/wasm/patches/streaming-commons.patch b/wasm/patches/streaming-commons.patch new file mode 100644 index 000000000..96a19bb93 --- /dev/null +++ b/wasm/patches/streaming-commons.patch @@ -0,0 +1,37 @@ +--- a/streaming-commons.cabal ++++ b/streaming-commons.cabal +@@ -30,20 +30,21 @@ library + Data.Streaming.ByteString.Builder.Buffer + Data.Streaming.FileRead + Data.Streaming.Filesystem +- Data.Streaming.Network +- Data.Streaming.Network.Internal + Data.Streaming.Process + Data.Streaming.Process.Internal + Data.Streaming.Text + Data.Streaming.Zlib + Data.Streaming.Zlib.Lowlevel + ++ if !arch(wasm32) ++ exposed-modules: Data.Streaming.Network ++ Data.Streaming.Network.Internal ++ + build-depends: base >= 4.12 && < 5 + , array + , async + , bytestring + , directory +- , network >= 2.4.0.0 + , random + , process + , stm +@@ -51,6 +52,9 @@ library + , transformers + , zlib + ++ if !arch(wasm32) ++ build-depends: network >= 2.4.0.0 ++ + c-sources: cbits/zlib-helper.c + cbits/text-helper.c + include-dirs: include diff --git a/wasm/patches/xml-conduit.patch b/wasm/patches/xml-conduit.patch new file mode 100644 index 000000000..557f85f70 --- /dev/null +++ b/wasm/patches/xml-conduit.patch @@ -0,0 +1,18 @@ +--- a/xml-conduit/xml-conduit.cabal ++++ b/xml-conduit/xml-conduit.cabal +@@ -12,13 +12,10 @@ description: Hackage documentation generation is not reliable. For up to dat + category: XML, Conduit + stability: Stable +-build-type: Custom ++build-type: Simple + homepage: http://github.com/snoyberg/xml + extra-source-files: README.md + ChangeLog.md +-tested-with: GHC >=8.0 && <9.12 +- +-custom-setup +- setup-depends: base >= 4 && <5, Cabal <4, cabal-doctest >= 1 && <1.1 ++tested-with: GHC >=8.0 && <9.14 + + library + build-depends: base >= 4.12 && < 5