Skip to content

Commit 492577b

Browse files
committed
Patches for compiling to wasm
deprecations
1 parent 74ba1f3 commit 492577b

File tree

5 files changed

+79
-29
lines changed

5 files changed

+79
-29
lines changed

cardano-diffusion/lib/Cardano/Network/NodeToClient.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE DataKinds #-}
23
{-# LANGUAGE GADTs #-}
34
{-# LANGUAGE NamedFieldPuns #-}
@@ -171,7 +172,11 @@ nodeToClientProtocols protocols _version _versionData =
171172
maximumMiniProtocolLimits :: MiniProtocolLimits
172173
maximumMiniProtocolLimits =
173174
MiniProtocolLimits {
175+
#if !defined(wasm32_HOST_ARCH)
174176
maximumIngressQueue = 0xffffffff
177+
#else
178+
maximumIngressQueue = 0x7fffffff
179+
#endif
175180
}
176181

177182

cardano-diffusion/lib/Cardano/Network/NodeToNode.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE DataKinds #-}
23
{-# LANGUAGE FlexibleInstances #-}
34
{-# LANGUAGE NamedFieldPuns #-}
@@ -77,7 +78,11 @@ import Data.ByteString.Lazy qualified as BL
7778
import Data.Word
7879

7980
import Network.Mux qualified as Mx
81+
#if !defined(wasm32_HOST_ARCH)
8082
import Network.Socket (Socket, StructLinger (..))
83+
#else
84+
import Network.Socket (Socket)
85+
#endif
8186
import Network.Socket qualified as Socket
8287

8388
import Cardano.Network.NodeToNode.Version
@@ -401,6 +406,7 @@ connectTo
401406
-> Maybe Socket.SockAddr
402407
-> Socket.SockAddr
403408
-> IO (Either SomeException (Either a b))
409+
#if !defined(wasm32_HOST_ARCH)
404410
connectTo sn tr =
405411
connectToNode sn makeSocketBearer
406412
ConnectToArgs {
@@ -418,7 +424,9 @@ connectTo sn tr =
418424
Socket.setSockOpt sock Socket.Linger
419425
(StructLinger { sl_onoff = 1,
420426
sl_linger = 0 })
421-
427+
#else
428+
connectTo _ _ = error "connecTo not supported in wasm"
429+
#endif
422430
-- | Node-To-Node protocol connections which negotiated
423431
-- `InitiatorAndResponderDiffusionMode` are `Duplex`.
424432
--

ouroboros-network/framework/lib/Ouroboros/Network/Socket.hs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ import Codec.CBOR.Read qualified as CBOR
6161
import Codec.CBOR.Term qualified as CBOR
6262
import Control.Applicative (Alternative)
6363
import Control.Concurrent.Class.MonadSTM.Strict
64+
#if !defined(wasm32_HOST_ARCH)
6465
import Control.Monad (unless, when)
66+
#endif
6567
import Control.Monad.Class.MonadAsync
6668
import Control.Monad.Class.MonadThrow
6769
import Control.Monad.Class.MonadTime.SI
@@ -72,8 +74,11 @@ import Data.Hashable
7274
import Data.Monoid.Synchronisation (FirstToFinish (..))
7375
import Data.Typeable (Typeable)
7476
import Data.Word (Word16)
75-
77+
#if !defined(wasm32_HOST_ARCH)
7678
import Network.Socket (SockAddr, Socket, StructLinger (..))
79+
#else
80+
import Network.Socket (SockAddr, Socket)
81+
#endif
7782
import Network.Socket qualified as Socket
7883

7984
import Control.Tracer
@@ -136,6 +141,7 @@ sockAddrFamily Socket.SockAddrUnix {} = Socket.AF_UNIX
136141
-- is expected.
137142
--
138143
configureSocket :: Socket -> Maybe SockAddr -> IO ()
144+
#if !defined(wasm32_HOST_ARCH)
139145
configureSocket sock addr = do
140146
let fml = sockAddrFamily <$> addr
141147
Socket.setSocketOption sock Socket.ReuseAddr 1
@@ -157,14 +163,18 @@ configureSocket sock addr = do
157163
-- it is enabled by default on some systems. Disabled here since we run a separate
158164
-- IPv4 server instance if configured to use IPv4.
159165
$ Socket.setSocketOption sock Socket.IPv6Only 1
160-
166+
#else
167+
configureSocket _ _ =
168+
error "configureSocket not supported in wasm"
169+
#endif
161170

162171
-- | Configure sockets passed through systemd socket activation.
163172
-- Currently 'ReuseAddr' and 'Linger' options are not configurable with
164173
-- 'systemd.socket', these options are set by this function. For other socket
165174
-- options we only trace if they are not set.
166175
--
167176
configureSystemdSocket :: Tracer IO SystemdSocketTracer -> Socket -> SockAddr -> IO ()
177+
#if !defined(wasm32_HOST_ARCH)
168178
configureSystemdSocket tracer sock addr = do
169179
let fml = sockAddrFamily addr
170180
case fml of
@@ -190,6 +200,10 @@ configureSystemdSocket tracer sock addr = do
190200
ipv6OnlyOpt <- Socket.getSocketOption sock Socket.IPv6Only
191201
unless (ipv6OnlyOpt /= 0) $
192202
traceWith tracer (SocketOptionNotSet Socket.IPv6Only)
203+
#else
204+
configureSystemdSocket _ _ _ =
205+
error "configureSystemdSocket not supported in wasm"
206+
#endif
193207

194208
data SystemdSocketTracer = SocketOptionNotSet Socket.SocketOption
195209
deriving Show

ouroboros-network/ouroboros-network.cabal

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,10 @@ test-suite tests-lib-tests
464464
tasty,
465465
tasty-quickcheck,
466466

467-
ghc-options:
468-
-rtsopts
469-
-threaded
467+
if !arch(wasm32)
468+
ghc-options:
469+
-rtsopts
470+
-threaded
470471

471472
library framework-tests-lib
472473
import: ghc-options
@@ -532,9 +533,10 @@ test-suite framework-sim-tests
532533
typed-protocols:{typed-protocols, cborg, examples},
533534
with-utf8,
534535

535-
ghc-options:
536-
-rtsopts
537-
-threaded
536+
if !arch(wasm32)
537+
ghc-options:
538+
-rtsopts
539+
-threaded
538540

539541
if flag(ipv6)
540542
cpp-options: -DOUROBOROS_NETWORK_IPV6
@@ -575,6 +577,9 @@ test-suite framework-io-tests
575577
-rtsopts
576578
-threaded
577579

580+
if arch(wasm32)
581+
buildable: False
582+
578583
library orphan-instances
579584
import: ghc-options
580585
visibility: public
@@ -633,6 +638,9 @@ executable demo-ping-pong
633638
ouroboros-network:{api, framework},
634639
typed-protocols:examples,
635640

641+
if arch(wasm32)
642+
buildable: False
643+
636644
executable demo-connection-manager
637645
import: ghc-options
638646
hs-source-dirs: demo
@@ -811,10 +819,13 @@ test-suite protocols-tests
811819
tasty,
812820

813821
ghc-options:
814-
-threaded
815822
-Wall
816823
-Wunused-packages
817-
-rtsopts
824+
825+
if !arch(wasm32)
826+
ghc-options:
827+
-threaded
828+
-rtsopts
818829

819830
-- Simulation Test Library
820831
library ouroboros-network-tests-lib
@@ -895,11 +906,14 @@ test-suite ouroboros-network-sim-tests
895906

896907
ghc-options:
897908
-fno-ignore-asserts
898-
-threaded
899-
-rtsopts
900-
+RTS
901-
-T
902-
-RTS
909+
910+
if !arch(wasm32)
911+
ghc-options:
912+
-threaded
913+
-rtsopts
914+
+RTS
915+
-T
916+
-RTS
903917

904918
-- Tests which require system calls provided by `Win32-network` or `network`
905919
-- library. These tests are compiled natively & run on all supported
@@ -939,12 +953,13 @@ test-suite ouroboros-network-io-tests
939953
else
940954
build-depends: process
941955

942-
ghc-options:
943-
-threaded
944-
-rtsopts
945-
+RTS
946-
-T
947-
-RTS
956+
if !arch(wasm32)
957+
ghc-options:
958+
-threaded
959+
-rtsopts
960+
+RTS
961+
-T
962+
-RTS
948963

949964
benchmark sim-benchmarks
950965
import: ghc-options-tests
@@ -964,10 +979,13 @@ benchmark sim-benchmarks
964979
-- https://gitlab.haskell.org/ghc/ghc/-/issues/25165
965980
ghc-options:
966981
-fno-ignore-asserts
967-
-threaded
968-
-rtsopts
969-
-with-rtsopts=-A32m
970-
-fproc-alignment=64
971-
+RTS
972-
-T
973-
-RTS
982+
983+
if !arch(wasm32)
984+
ghc-options:
985+
-threaded
986+
-rtsopts
987+
-with-rtsopts=-A32m
988+
-fproc-alignment=64
989+
+RTS
990+
-T
991+
-RTS

ouroboros-network/tests/io/Test/Ouroboros/Network/Socket.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE BangPatterns #-}
23
{-# LANGUAGE DataKinds #-}
34
{-# LANGUAGE FlexibleContexts #-}
@@ -129,7 +130,11 @@ testVersionCodecCBORTerm !_ =
129130
decodeTerm :: CBOR.Term -> Either Text TestVersionData
130131
decodeTerm (CBOR.TList [CBOR.TInt x])
131132
| x >= 0
133+
#if !defined(wasm32_HOST_ARCH)
132134
, x <= 0xffffffff
135+
#else
136+
, x <= 0x7fffffff
137+
#endif
133138
= Right
134139
TestVersionData {
135140
networkMagic = NetworkMagic (fromIntegral x)

0 commit comments

Comments
 (0)