diff --git a/cardano-diffusion/changelog.d/20251021_214416_pablo.lamela_prepare_for_wasm.md b/cardano-diffusion/changelog.d/20251021_214416_pablo.lamela_prepare_for_wasm.md new file mode 100644 index 00000000000..807eaf46895 --- /dev/null +++ b/cardano-diffusion/changelog.d/20251021_214416_pablo.lamela_prepare_for_wasm.md @@ -0,0 +1,6 @@ + +### Non-Breaking + +- Patched so that it compiles to wasm + + diff --git a/cardano-diffusion/lib/Cardano/Network/NodeToClient.hs b/cardano-diffusion/lib/Cardano/Network/NodeToClient.hs index 387cac9e2af..989c33c993e 100644 --- a/cardano-diffusion/lib/Cardano/Network/NodeToClient.hs +++ b/cardano-diffusion/lib/Cardano/Network/NodeToClient.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE NamedFieldPuns #-} @@ -171,7 +172,11 @@ nodeToClientProtocols protocols _version _versionData = maximumMiniProtocolLimits :: MiniProtocolLimits maximumMiniProtocolLimits = MiniProtocolLimits { +#if !defined(wasm32_HOST_ARCH) maximumIngressQueue = 0xffffffff +#else + maximumIngressQueue = 0x7fffffff +#endif } diff --git a/cardano-diffusion/lib/Cardano/Network/NodeToNode.hs b/cardano-diffusion/lib/Cardano/Network/NodeToNode.hs index e25f712f305..14fb021c8a9 100644 --- a/cardano-diffusion/lib/Cardano/Network/NodeToNode.hs +++ b/cardano-diffusion/lib/Cardano/Network/NodeToNode.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE NamedFieldPuns #-} @@ -77,7 +78,11 @@ import Data.ByteString.Lazy qualified as BL import Data.Word import Network.Mux qualified as Mx +#if !defined(wasm32_HOST_ARCH) import Network.Socket (Socket, StructLinger (..)) +#else +import Network.Socket (Socket) +#endif import Network.Socket qualified as Socket import Cardano.Network.NodeToNode.Version @@ -401,6 +406,7 @@ connectTo -> Maybe Socket.SockAddr -> Socket.SockAddr -> IO (Either SomeException (Either a b)) +#if !defined(wasm32_HOST_ARCH) connectTo sn tr = connectToNode sn makeSocketBearer ConnectToArgs { @@ -418,7 +424,9 @@ connectTo sn tr = Socket.setSockOpt sock Socket.Linger (StructLinger { sl_onoff = 1, sl_linger = 0 }) - +#else +connectTo _ _ = error "connecTo not supported in wasm" +#endif -- | Node-To-Node protocol connections which negotiated -- `InitiatorAndResponderDiffusionMode` are `Duplex`. -- diff --git a/network-mux/changelog.d/20251021_214605_pablo.lamela_prepare_for_wasm.md b/network-mux/changelog.d/20251021_214605_pablo.lamela_prepare_for_wasm.md new file mode 100644 index 00000000000..a3faa783a1b --- /dev/null +++ b/network-mux/changelog.d/20251021_214605_pablo.lamela_prepare_for_wasm.md @@ -0,0 +1,4 @@ +### Non-Breaking + +- Patched so that it compiles to wasm + diff --git a/network-mux/src/Network/Mux/Channel.hs b/network-mux/src/Network/Mux/Channel.hs index 099ddbba15c..eaf70d94e65 100644 --- a/network-mux/src/Network/Mux/Channel.hs +++ b/network-mux/src/Network/Mux/Channel.hs @@ -313,6 +313,8 @@ socketAsChannel socket = --- --- This is primarily for testing purposes since it does not allow actual IPC. --- +-- __Exceptions:__ +-- May throw 'IOError' when compiling to @wasm@. createSocketConnectedChannels :: Socket.Family -- ^ Usually AF_UNIX or AF_INET -> IO (ByteChannel IO, ByteChannel IO) diff --git a/ouroboros-network/changelog.d/20251021_214658_pablo.lamela_prepare_for_wasm.md b/ouroboros-network/changelog.d/20251021_214658_pablo.lamela_prepare_for_wasm.md new file mode 100644 index 00000000000..a3faa783a1b --- /dev/null +++ b/ouroboros-network/changelog.d/20251021_214658_pablo.lamela_prepare_for_wasm.md @@ -0,0 +1,4 @@ +### Non-Breaking + +- Patched so that it compiles to wasm + diff --git a/ouroboros-network/demo/connection-manager.hs b/ouroboros-network/demo/connection-manager.hs index bdc7740086a..3e2c10814c2 100644 --- a/ouroboros-network/demo/connection-manager.hs +++ b/ouroboros-network/demo/connection-manager.hs @@ -647,7 +647,8 @@ optionParser = <> showDefault ) - +-- | __Exceptions:__ +-- May throw 'IOError' when compiling to @wasm@. run :: (Addr, Port) -> (Addr, Port) -> DiffTime -- ^ protocol idle timeout diff --git a/ouroboros-network/framework/lib/Ouroboros/Network/Snocket.hs b/ouroboros-network/framework/lib/Ouroboros/Network/Snocket.hs index 01f21ac9c45..7845d3ce088 100644 --- a/ouroboros-network/framework/lib/Ouroboros/Network/Snocket.hs +++ b/ouroboros-network/framework/lib/Ouroboros/Network/Snocket.hs @@ -346,6 +346,8 @@ type SocketSnocket = Snocket IO Socket SockAddr -- | Create a 'Snocket' for the given 'Socket.Family'. In the 'bind' method set -- 'Socket.ReuseAddr` and 'Socket.ReusePort'. -- +-- __Exceptions:__ +-- May throw 'IOError' when compiling to @wasm@. socketSnocket :: IOManager -- ^ 'IOManager' interface. We use it when we create a new socket and when we @@ -452,6 +454,8 @@ type LocalSnocket = Snocket IO LocalSocket LocalAddress -- around this, the address passed to 'open' via 'LocalFamily' will be -- referenced by 'LocalSocket'. -- +-- __Exceptions:__ +-- May throw 'IOError' when compiling to @wasm@. localSnocket :: IOManager -> LocalSnocket #if defined(mingw32_HOST_OS) localSnocket ioManager = Snocket { diff --git a/ouroboros-network/framework/lib/Ouroboros/Network/Socket.hs b/ouroboros-network/framework/lib/Ouroboros/Network/Socket.hs index 94cfa9f18be..fdb75145c65 100644 --- a/ouroboros-network/framework/lib/Ouroboros/Network/Socket.hs +++ b/ouroboros-network/framework/lib/Ouroboros/Network/Socket.hs @@ -61,7 +61,9 @@ import Codec.CBOR.Read qualified as CBOR import Codec.CBOR.Term qualified as CBOR import Control.Applicative (Alternative) import Control.Concurrent.Class.MonadSTM.Strict +#if !defined(wasm32_HOST_ARCH) import Control.Monad (unless, when) +#endif import Control.Monad.Class.MonadAsync import Control.Monad.Class.MonadThrow import Control.Monad.Class.MonadTime.SI @@ -72,8 +74,11 @@ import Data.Hashable import Data.Monoid.Synchronisation (FirstToFinish (..)) import Data.Typeable (Typeable) import Data.Word (Word16) - +#if !defined(wasm32_HOST_ARCH) import Network.Socket (SockAddr, Socket, StructLinger (..)) +#else +import Network.Socket (SockAddr, Socket) +#endif import Network.Socket qualified as Socket import Control.Tracer @@ -136,6 +141,7 @@ sockAddrFamily Socket.SockAddrUnix {} = Socket.AF_UNIX -- is expected. -- configureSocket :: Socket -> Maybe SockAddr -> IO () +#if !defined(wasm32_HOST_ARCH) configureSocket sock addr = do let fml = sockAddrFamily <$> addr Socket.setSocketOption sock Socket.ReuseAddr 1 @@ -157,7 +163,10 @@ configureSocket sock addr = do -- it is enabled by default on some systems. Disabled here since we run a separate -- IPv4 server instance if configured to use IPv4. $ Socket.setSocketOption sock Socket.IPv6Only 1 - +#else +configureSocket _ _ = + error "configureSocket not supported in wasm" +#endif -- | Configure sockets passed through systemd socket activation. -- Currently 'ReuseAddr' and 'Linger' options are not configurable with @@ -165,6 +174,7 @@ configureSocket sock addr = do -- options we only trace if they are not set. -- configureSystemdSocket :: Tracer IO SystemdSocketTracer -> Socket -> SockAddr -> IO () +#if !defined(wasm32_HOST_ARCH) configureSystemdSocket tracer sock addr = do let fml = sockAddrFamily addr case fml of @@ -190,6 +200,10 @@ configureSystemdSocket tracer sock addr = do ipv6OnlyOpt <- Socket.getSocketOption sock Socket.IPv6Only unless (ipv6OnlyOpt /= 0) $ traceWith tracer (SocketOptionNotSet Socket.IPv6Only) +#else +configureSystemdSocket _ _ _ = + error "configureSystemdSocket not supported in wasm" +#endif data SystemdSocketTracer = SocketOptionNotSet Socket.SocketOption deriving Show diff --git a/ouroboros-network/ouroboros-network.cabal b/ouroboros-network/ouroboros-network.cabal index fa18938acb1..f0106ef703b 100644 --- a/ouroboros-network/ouroboros-network.cabal +++ b/ouroboros-network/ouroboros-network.cabal @@ -464,9 +464,10 @@ test-suite tests-lib-tests tasty, tasty-quickcheck, - ghc-options: - -rtsopts - -threaded + if !arch(wasm32) + ghc-options: + -rtsopts + -threaded library framework-tests-lib import: ghc-options @@ -532,9 +533,10 @@ test-suite framework-sim-tests typed-protocols:{typed-protocols, cborg, examples}, with-utf8, - ghc-options: - -rtsopts - -threaded + if !arch(wasm32) + ghc-options: + -rtsopts + -threaded if flag(ipv6) cpp-options: -DOUROBOROS_NETWORK_IPV6 @@ -575,6 +577,9 @@ test-suite framework-io-tests -rtsopts -threaded + if arch(wasm32) + buildable: False + library orphan-instances import: ghc-options visibility: public @@ -633,6 +638,9 @@ executable demo-ping-pong ouroboros-network:{api, framework}, typed-protocols:examples, + if arch(wasm32) + buildable: False + executable demo-connection-manager import: ghc-options hs-source-dirs: demo @@ -811,10 +819,13 @@ test-suite protocols-tests tasty, ghc-options: - -threaded -Wall -Wunused-packages - -rtsopts + + if !arch(wasm32) + ghc-options: + -threaded + -rtsopts -- Simulation Test Library library ouroboros-network-tests-lib @@ -895,11 +906,14 @@ test-suite ouroboros-network-sim-tests ghc-options: -fno-ignore-asserts - -threaded - -rtsopts - +RTS - -T - -RTS + + if !arch(wasm32) + ghc-options: + -threaded + -rtsopts + +RTS + -T + -RTS -- Tests which require system calls provided by `Win32-network` or `network` -- library. These tests are compiled natively & run on all supported @@ -939,12 +953,13 @@ test-suite ouroboros-network-io-tests else build-depends: process - ghc-options: - -threaded - -rtsopts - +RTS - -T - -RTS + if !arch(wasm32) + ghc-options: + -threaded + -rtsopts + +RTS + -T + -RTS benchmark sim-benchmarks import: ghc-options-tests @@ -964,10 +979,13 @@ benchmark sim-benchmarks -- https://gitlab.haskell.org/ghc/ghc/-/issues/25165 ghc-options: -fno-ignore-asserts - -threaded - -rtsopts - -with-rtsopts=-A32m - -fproc-alignment=64 - +RTS - -T - -RTS + + if !arch(wasm32) + ghc-options: + -threaded + -rtsopts + -with-rtsopts=-A32m + -fproc-alignment=64 + +RTS + -T + -RTS diff --git a/ouroboros-network/tests/io/Test/Ouroboros/Network/Socket.hs b/ouroboros-network/tests/io/Test/Ouroboros/Network/Socket.hs index 8bedf308491..748192de213 100644 --- a/ouroboros-network/tests/io/Test/Ouroboros/Network/Socket.hs +++ b/ouroboros-network/tests/io/Test/Ouroboros/Network/Socket.hs @@ -1,4 +1,5 @@ {-# LANGUAGE BangPatterns #-} +{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} @@ -129,7 +130,11 @@ testVersionCodecCBORTerm !_ = decodeTerm :: CBOR.Term -> Either Text TestVersionData decodeTerm (CBOR.TList [CBOR.TInt x]) | x >= 0 +#if !defined(wasm32_HOST_ARCH) , x <= 0xffffffff +#else + , x <= 0x7fffffff +#endif = Right TestVersionData { networkMagic = NetworkMagic (fromIntegral x) @@ -180,7 +185,8 @@ prop_socket_demo :: TestBlockChainAndUpdates -> Property prop_socket_demo (TestBlockChainAndUpdates chain updates) = ioProperty $ demo chain updates - +-- | __Exceptions:__ +-- May throw 'IOError' when compiling to @wasm@. demo :: forall block . ( Chain.HasHeader block , Serialise (Chain.HeaderHash block) diff --git a/scripts/ci/check-stylish-ignore b/scripts/ci/check-stylish-ignore index e3661c4a837..438c62c08fc 100644 --- a/scripts/ci/check-stylish-ignore +++ b/scripts/ci/check-stylish-ignore @@ -1,5 +1,6 @@ */Setup.hs ouroboros-network/api/lib/Ouroboros/Network/Protocol/Type.hs +cardano-diffusion/lib/Cardano/Network/NodeToClient.hs ouroboros-network/lib/Ouroboros/Network/BlockFetch/Decision/Genesis.hs ouroboros-network/lib/Ouroboros/Network/PeerSelection/Governor/Types.hs network-mux/src/Network/Mux/TCPInfo.hs