sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.46k stars 439 forks source link

Support build on wasm32 #1146

Open L-jasmine opened 4 months ago

L-jasmine commented 4 months ago

In this line, the parameter KeepaliveConfig is ignored when compiled to wasm32, while there is no corresponding conditional compilation elsewhere. Therefore, I added a conditional compilation for wasm32 in the places where Keepalive is needed. This modification allows the crate to be used normally in wasm32 after replacing the underlying tokio with a patch.

sfackler commented 4 months ago

We already test that the crate compiles against wasm32: https://github.com/sfackler/rust-postgres/blob/master/.github/workflows/ci.yml#L50-L75.

If tokio gains direct wasm32 support I'd be happy to expand the supported feature set here, but I don't want to make changes that only work when building against an unspecified tokio fork.

L-jasmine commented 4 months ago

This is not specific to a particular tokio; it’s just that this crate does not define KeepaliveConfig in wasm32. I’ve ignored all references to KeepaliveConfig in wasm32, and I believe these changes are reasonable.

sfackler commented 4 months ago

The runtime Cargo feature is not supported on wasm32 at this time, and can't be without changes to tokio.

L-jasmine commented 4 months ago

I am pretty sure that my changes work with standard tokio. Your CI still passes with this PR.