Commit13461da9Recorded6 May 2026Repositorysigil-websocket

Make websocket aggregate WASM-safe

Message

Gate the public (sigil websocket) aggregate with cond-expand so WASM builds expose only the browser-safe client connection surface while native builds keep the frame and server exports. Update the WASM client smoke to import the public aggregate directly.nnVerification:n- sh test/integration/test-wasm-websocket-client.shn- ../sigil/build/dev/bin/sigil -L build/dev/lib eval '(load "test/test-websocket.sgl")'n- ../sigil/build/dev/bin/sigil -L build/dev/lib eval '(load "test/test-server.sgl")'n- ../sigil/build/dev/bin/sigil build --redirects dev-redirects.sgl --force

Changed
 src/sigil/websocket.sgl                                                                    | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------
 test/integration/apps/wasm-websocket-client-smoke/src/wasm-websocket-client-smoke/main.sgl |   2 +-
 test/integration/test-wasm-websocket-client.mjs                                            |   2 +-
 3 files changed, 92 insertions(+), 66 deletions(-)
Diff
src/sigil/websocket.sglmodified
@@ -39,74 +39,100 @@
39
;;; ```
40
41
(define-library (sigil websocket)
42
(import (sigil websocket frame)
43
(sigil websocket connection)
44
(sigil websocket server))
+42
(cond-expand
+43
(wasm
+44
(import (sigil websocket connection))
+45
(export
+46
;; Connection management
+47
ws-connect
+48
ws-close
+49
ws-connected?
+50
ws-connection?
+51
ws-connection-state
+52
ws-connection-url
53
46
(export
47
;; Connection management
48
ws-connect
49
ws-close
50
ws-connected?
51
ws-connection?
52
ws-connection-state
53
ws-connection-url
+54
;; Sending messages
+55
ws-send
+56
ws-send-binary
+57
ws-ping
58
55
;; Sending messages
56
ws-send
57
ws-send-binary
58
ws-ping
+59
;; Receiving messages
+60
ws-receive
+61
ws-message?
+62
ws-message-type
+63
ws-message-data
64
60
;; Receiving messages
61
ws-receive
62
ws-message?
63
ws-message-type
64
ws-message-data
+65
;; Low-level access (for advanced use)
+66
ws-connection-socket))
+67
(else
+68
(import (sigil websocket frame)
+69
(sigil websocket connection)
+70
(sigil websocket server))
71
66
;; Low-level access (for advanced use)
67
ws-connection-socket
+72
(export
+73
;; Connection management
+74
ws-connect
+75
ws-close
+76
ws-connected?
+77
ws-connection?
+78
ws-connection-state
+79
ws-connection-url
80
69
;; Frame types (for reference)
70
opcode-text
71
opcode-binary
72
opcode-close
73
opcode-ping
74
opcode-pong
+81
;; Sending messages
+82
ws-send
+83
ws-send-binary
+84
ws-ping
85
76
;; Frame encoding / decoding (re-exported for server use)
77
ws-frame
78
ws-frame?
79
ws-frame-fin?
80
ws-frame-opcode
81
ws-frame-payload
82
encode-frame
83
decode-frame
84
frame-decode-result?
85
frame-decode-result-frame
86
frame-decode-result-bytes-consumed
87
encode-server-text-frame
88
encode-server-binary-frame
89
encode-server-close-frame
90
encode-server-ping-frame
91
encode-server-pong-frame
+86
;; Receiving messages
+87
ws-receive
+88
ws-message?
+89
ws-message-type
+90
ws-message-data
91
93
;; Server handshake
94
ws-handshake-request
95
ws-handshake-request?
96
ws-handshake-request-method
97
ws-handshake-request-path
98
ws-handshake-request-host
99
ws-handshake-request-key
100
ws-handshake-request-version
101
ws-handshake-request-subprotocols
102
ws-handshake-request-headers
103
ws-handshake-request-x-forwarded-for
104
ws-handshake-error
105
ws-handshake-error?
106
ws-handshake-error-status
107
ws-handshake-error-reason
108
parse-handshake-request
109
handshake-request-bytes-needed?
110
build-handshake-response
111
build-handshake-error-response
112
compute-accept-key))
+92
;; Low-level access (for advanced use)
+93
ws-connection-socket
+94
+95
;; Frame types (for reference)
+96
opcode-text
+97
opcode-binary
+98
opcode-close
+99
opcode-ping
+100
opcode-pong
+101
+102
;; Frame encoding / decoding (re-exported for server use)
+103
ws-frame
+104
ws-frame?
+105
ws-frame-fin?
+106
ws-frame-opcode
+107
ws-frame-payload
+108
encode-frame
+109
decode-frame
+110
frame-decode-result?
+111
frame-decode-result-frame
+112
frame-decode-result-bytes-consumed
+113
encode-server-text-frame
+114
encode-server-binary-frame
+115
encode-server-close-frame
+116
encode-server-ping-frame
+117
encode-server-pong-frame
+118
+119
;; Server handshake
+120
ws-handshake-request
+121
ws-handshake-request?
+122
ws-handshake-request-method
+123
ws-handshake-request-path
+124
ws-handshake-request-host
+125
ws-handshake-request-key
+126
ws-handshake-request-version
+127
ws-handshake-request-subprotocols
+128
ws-handshake-request-headers
+129
ws-handshake-request-x-forwarded-for
+130
ws-handshake-error
+131
ws-handshake-error?
+132
ws-handshake-error-status
+133
ws-handshake-error-reason
+134
parse-handshake-request
+135
handshake-request-bytes-needed?
+136
build-handshake-response
+137
build-handshake-error-response
+138
compute-accept-key))))
test/integration/apps/wasm-websocket-client-smoke/src/wasm-websocket-client-smoke/main.sglmodified
@@ -1,6 +1,6 @@
1
(define-library (wasm-websocket-client-smoke main)
2
(import (sigil core)
3
(sigil websocket connection))
+3
(sigil websocket))
4
5
(export main)
6
test/integration/test-wasm-websocket-client.mjsmodified
@@ -308,7 +308,7 @@ async function main() {
308
wasi.start(instance);
309
310
callWithString(instance, instance.exports.sigil_wasm_eval, `
311
(import (sigil websocket connection))
+311
(import (sigil websocket))
312
(define conn (ws-connect "ws://127.0.0.1:${port}"))
313
(if (not conn) (error "ws-connect failed"))
314
(display "ws-connect-ok") (newline)