Repository navigation
Run the session in WebAssembly instead of native addons - #23
Merged
Merged
Conversation
Neo's Rust session moves from four per-platform Node-API addons on wechat-protocol 2.2.0 to one WebAssembly build on wechat-protocol 3.8.0's async API with its pure-Rust crypto backend. - wasm/ replaces native/. The session logic is the same, ported to the async calls: login, the push connection's heartbeat, sync and poll, sends, profile lookup, renewal and logout. An async lock serializes session access, as the Rust mutex did. - The protocol's network and clock come from the JavaScript host. src/host.ts opens TCP connections with node:net, reports failures as timeout, interrupted or disconnected so login polling still retries, and supplies Node's clocks. Random bytes come from crypto.getRandomValues. - src/session.ts (was native.ts) loads the wasm-bindgen output from wasm/pkg. The platform, glibc and Windows-on-ARM checks are gone: one file runs wherever Node.js 26 runs. - npm run build:wasm builds the crate for wasm32-unknown-unknown, runs wasm-bindgen (the tool must match the crate version) and writes the third-party notices. No C compiler, Make or Perl is needed. - CI builds once on Linux (fmt, clippy for the host and wasm32, Rust tests, npm test), installs the tarball on Linux x64 and ARM64, macOS ARM64 and Windows x64, then assembles the tarball for the unchanged publish job. - The npm tarball drops from 16.8 MB to 447 KB. WebAssembly cannot accept incoming connections, so a login that WeChat routes through its local-network check now fails instead of completing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thisnick
marked this pull request as ready for review
December 3, 2026 01:42
The WebAssembly file and the Node APIs Neo uses behave the same on every platform, so one Linux job builds, tests, installs the tarball in a fresh project and keeps it for publishing. macOS and Windows runners are no longer needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Neo's Rust session moves from four per-platform Node-API addons on
wechat-protocol2.2.0 to one WebAssembly build onwechat-protocol3.8.0's async API with its pure-Rust crypto backend. One package now runs wherever Node.js 26 runs, and installing it compiles nothing. This follows the direction in #21: one wasm core, with Node as the first host.Changes
wasm/replacesnative/. The session logic is unchanged, ported to the async calls: QR login, the push connection's heartbeat, sync and poll, sends, profile lookup, renewal and logout. An async lock serializes session access, as the Rust mutex did. The Rust tests move over unchanged in substance (11 pass).src/host.tsopens TCP connections withnode:netand implements the protocol's stream contract: bytes, end of stream, or timed out. It reports failures astimeout,interruptedordisconnected, so QR polling still retries after a dropped connection, and it supplies Node's clocks. Random bytes come fromcrypto.getRandomValues.src/session.ts(wasnative.ts) loads the wasm-bindgen output fromwasm/pkg. The platform, glibc and Windows-on-ARM checks are gone.npm run build:wasmbuilds forwasm32-unknown-unknown, runswasm-bindgen(checked against the crate version inCargo.lock) and writes the third-party notices. No C compiler, Make or Perl is needed.npm test, then a clean install of the packed tarball with the package tests. It keeps that tarball for the unchanged publish job. The WebAssembly file and the Node APIs Neo uses behave the same on every platform, so macOS and Windows runners are no longer needed.One gap: WebAssembly can't accept incoming connections, so a login that WeChat routes through its local-network check now fails instead of completing; the user scans again. Native 2.2.0 opened a local listener for this.
Testing
cargo fmt --check, clippy with-D warningsfor the host andwasm32-unknown-unknown, andcargo test(11 pass).npm test(9 pass, including the session test against the real wasm build) andnpm run test:packageon Node.js 26, linux-x64.net.Socket, and a poll returnedpending.Logged in as 昊罡.), thenReady. A directdingand a groupdingeach got onedong, the group reply going to the group. Signing out from the phone printedLogged out: WeChat ended the sessionwith no error event. Upstream CI only type-checkswechat-protocolfor wasm32, so this is the first full session over wasm.🤖 Generated with Claude Code