Skip to content

Commit f61401e

Browse files
committed
Support build on wasm32
Signed-off-by: csh <[email protected]>
1 parent a1bdd0b commit f61401e

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

tokio-postgres/src/cancel_query.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ where
3434
config.port,
3535
config.connect_timeout,
3636
config.tcp_user_timeout,
37+
#[cfg(not(target_arch = "wasm32"))]
3738
config.keepalive.as_ref(),
3839
)
3940
.await?;

tokio-postgres/src/client.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::codec::{BackendMessages, FrontendMessage};
22
use crate::config::SslMode;
33
use crate::connection::{Request, RequestMessages};
44
use crate::copy_out::CopyOutStream;
5-
#[cfg(feature = "runtime")]
5+
#[cfg(all(feature = "runtime", not(target_arch = "wasm32")))]
66
use crate::keepalive::KeepaliveConfig;
77
use crate::query::RowStream;
88
use crate::simple_query::SimpleQueryStream;
@@ -27,7 +27,7 @@ use std::collections::HashMap;
2727
use std::fmt;
2828
#[cfg(feature = "runtime")]
2929
use std::net::IpAddr;
30-
#[cfg(feature = "runtime")]
30+
#[cfg(all(feature = "runtime", unix))]
3131
use std::path::PathBuf;
3232
use std::sync::Arc;
3333
use std::task::{Context, Poll};
@@ -160,6 +160,7 @@ pub(crate) struct SocketConfig {
160160
pub port: u16,
161161
pub connect_timeout: Option<Duration>,
162162
pub tcp_user_timeout: Option<Duration>,
163+
#[cfg(not(target_arch = "wasm32"))]
163164
pub keepalive: Option<KeepaliveConfig>,
164165
}
165166

tokio-postgres/src/connect.rs

+2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ where
146146
port,
147147
config.connect_timeout,
148148
config.tcp_user_timeout,
149+
#[cfg(not(target_arch = "wasm32"))]
149150
if config.keepalives {
150151
Some(&config.keepalive_config)
151152
} else {
@@ -216,6 +217,7 @@ where
216217
port,
217218
connect_timeout: config.connect_timeout,
218219
tcp_user_timeout: config.tcp_user_timeout,
220+
#[cfg(not(target_arch = "wasm32"))]
219221
keepalive: if config.keepalives {
220222
Some(config.keepalive_config.clone())
221223
} else {

tokio-postgres/src/connect_socket.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::client::Addr;
2+
#[cfg(not(target_arch = "wasm32"))]
23
use crate::keepalive::KeepaliveConfig;
34
use crate::{Error, Socket};
5+
#[cfg(not(target_arch = "wasm32"))]
46
use socket2::{SockRef, TcpKeepalive};
57
use std::future::Future;
68
use std::io;
@@ -17,7 +19,7 @@ pub(crate) async fn connect_socket(
1719
#[cfg_attr(not(target_os = "linux"), allow(unused_variables))] tcp_user_timeout: Option<
1820
Duration,
1921
>,
20-
keepalive_config: Option<&KeepaliveConfig>,
22+
#[cfg(not(target_arch = "wasm32"))] keepalive_config: Option<&KeepaliveConfig>,
2123
) -> Result<Socket, Error> {
2224
match addr {
2325
Addr::Tcp(ip) => {
@@ -26,6 +28,7 @@ pub(crate) async fn connect_socket(
2628

2729
stream.set_nodelay(true).map_err(Error::connect)?;
2830

31+
#[cfg(not(target_arch = "wasm32"))]
2932
let sock_ref = SockRef::from(&stream);
3033
#[cfg(target_os = "linux")]
3134
{
@@ -34,6 +37,7 @@ pub(crate) async fn connect_socket(
3437
.map_err(Error::connect)?;
3538
}
3639

40+
#[cfg(not(target_arch = "wasm32"))]
3741
if let Some(keepalive_config) = keepalive_config {
3842
sock_ref
3943
.set_tcp_keepalive(&TcpKeepalive::from(keepalive_config))

0 commit comments

Comments
 (0)