Repository: seanmonstar/reqwest (language: rust)

Issue:
v0.12.11 breaks my wasm-unknown-unknown build
It adds a dependency on tower which adds a dependency on tokio and mio which does not support wasm. Lots of build errors for UdpPacket and TcpPacket bindings.

I think it was this commit specifically. v0.12.9 builds perfectly.
https://github.com/seanmonstar/reqwest/commit/2a7c1b61e0693f8b9924e2e89257aa131a30ee83




Discussion / hints:
It might be the `timeout` feature of tower. Interesting, we have a CO job building wasm, it didn't seem to complain.

cc @jlizen 
Yeah, interesting that the CI job did not complain. I can find a fix for this tomorrow. @jonatino can you share some error outputs to help confirm our reproduction matches your issue?

I agree that it likely looks the transitive dependency on `tokio/time` that the timeout layer adds. I see that we have that explicitly scoped out of WASM dependencies (https://github.com/seanmonstar/reqwest/blob/master/Cargo.toml#L121). Probably we need to do similar here.

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 6891258ce..8ab1d3abf 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -105,7 +105,6 @@ url = "2.4"
 bytes = "1.0"
 serde = "1.0"
 serde_urlencoded = "0.7.1"
-tower = { version = "0.5.2", default-features = false, features = ["timeout", "util"] }
 tower-service = "0.3"
 futures-core = { version = "0.3.28", default-features = false }
 futures-util = { version = "0.3.28", default-features = false }
@@ -130,6 +129,7 @@ log = "0.4.17"
 mime = "0.3.16"
 percent-encoding = "2.3"
 tokio = { version = "1.0", default-features = false, features = ["net", "time"] }
+tower = { version = "0.5.2", default-features = false, features = ["timeout", "util"] }
 pin-project-lite = "0.2.11"
 ipnet = "2.3"
 
diff --git a/src/error.rs b/src/error.rs
index 6a9f07e51..fd044814d 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -169,6 +169,7 @@ impl Error {
 /// internal equivalents.
 ///
 /// Currently only is used for `tower::timeout::error::Elapsed`.
+#[cfg(not(target_arch = "wasm32"))]
 pub(crate) fn cast_to_internal_error(error: BoxError) -> BoxError {
     if error.is::<tower::timeout::error::Elapsed>() {
         Box::new(crate::error::TimedOut) as BoxError
diff --git a/src/lib.rs b/src/lib.rs
index cf3d39d0f..981c075ca 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -173,7 +173,7 @@
 //!
 //! The Client implementation automatically switches to the WASM one when the target_arch is wasm32,
 //! the usage is basically the same as the async api. Some of the features are disabled in wasm
-//! : [`tls`], [`cookie`], [`blocking`].
+//! : [`tls`], [`cookie`], [`blocking`], as well as various `ClientBuilder` methods such as `timeout()` and `connector_layer()`.
 //!
 //!
 //! ## Optional Features


Test patch: