fix(tokio-postgres): support wasm32-wasip2 compilation#1
Open
nicolasauler wants to merge 1 commit intomasterfrom
Open
fix(tokio-postgres): support wasm32-wasip2 compilation#1nicolasauler wants to merge 1 commit intomasterfrom
nicolasauler wants to merge 1 commit intomasterfrom
Conversation
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.
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.
With tokio 1.51 shipping wasm32-wasip2 networking, tokio-postgres is close to compiling on that target.
The
keepalivemodule andsocket2dependency are already gated:But
connect_socket.rs,connect.rs, andcancel_query.rsstill import them unconditionally, causing compile errors on wasm32. This PR extends the existingcfg(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
whoamidependency for a separatestd::os::wasistability issue on wasip2. With both patches, tokio-postgres compiles onwasm32-wasip2.