Skip to content

fix(tokio-postgres): support wasm32-wasip2 compilation#1

Open
nicolasauler wants to merge 1 commit intomasterfrom
fix-wasip2-compile
Open

fix(tokio-postgres): support wasm32-wasip2 compilation#1
nicolasauler wants to merge 1 commit intomasterfrom
fix-wasip2-compile

Conversation

@nicolasauler
Copy link
Copy Markdown
Owner

@nicolasauler nicolasauler commented Apr 6, 2026

With tokio 1.51 shipping wasm32-wasip2 networking, tokio-postgres is close to compiling on that target.

The keepalive module and socket2 dependency are already gated:

// lib.rs
#[cfg(not(target_arch = "wasm32"))]
mod keepalive;
[target.'cfg(not(target_arch = "wasm32"))'..dependencies]
socket2 = { version = "0.6", features = ["all"] }

But connect_socket.rs, connect.rs, and cancel_query.rs still import them unconditionally, causing compile errors on wasm32. This PR extends the existing cfg(not(target_arch = "wasm32")) gating to those three files. On WASM targets, connections proceed without keepalive — correct since WASI sockets don't expose socket options.

Also requires a fix in the whoami dependency for a separate std::os::wasi stability issue on wasip2. With both patches, tokio-postgres compiles on wasm32-wasip2.

On wasm32-wasip2, socket2 is not available (WASI has no raw socket
options). The keepalive module and socket2 dependency are already gated
in lib.rs and Cargo.toml, but connect_socket.rs, connect.rs, and
cancel_query.rs still imported them unconditionally.

Gate the keepalive_config parameter and socket2 usage in these three
files behind cfg(not(target_arch = "wasm32")). On WASM targets, the
connection proceeds without keepalive — functionally correct since WASI
sockets don't support socket options anyway.

Combined with a fix for the whoami crate (which also fails on wasip2),
this allows tokio-postgres to compile on wasm32-wasip2.
@nicolasauler nicolasauler self-assigned this Apr 6, 2026
@nicolasauler nicolasauler changed the title Gate keepalive/socket2 behind cfg(not(wasm32)) for wasip2 support fix(tokio-postgres): support wasm32-wasip2 compilation Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant