Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting "unresolved import crate::sys::IoSourceState" error running wasm-pack build on a project with reqwest/tokio dependencies #1300

Closed
beyonddream opened this issue Jul 12, 2021 · 19 comments

Comments

@beyonddream
Copy link

I added reqwest/tokio as a dependency to a webassembly project created via wasm-pack-template. When I built the project using wasm-pack build command, it is giving me a long list of errors while compiling mio v0.7.13.

The documentation for reqwest suggests that it support's WASM so I am confused why the target "wasm32-unknown-unknown" is failing. I can guess it is because the mio's socket usage (udp/tcp) may not have an equivalent on the browser api but is there any alternate way of building reqwest that would build successfully by using browser's fetch ?

Steps to reproduce:

  1. cargo generate --git https://github.com/rustwasm/wasm-pack-template and create a sample project.
  2. Cd into the sample project
  3. Update Cargo.toml dependencies below:
wasm-bindgen = "0.2.63" // added as part of cargo generate
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] }
  1. Run wasm-pack build (full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown")
  2. Rust version - rustc 1.53.0 (53cb7b09b 2021-06-17)

Partial Error below (since the errors list is huge):

$ wasm-pack build
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
   Compiling mio v0.7.13
   Compiling idna v0.2.3
   Compiling wasm-bindgen-backend v0.2.74
   Compiling tokio-macros v1.3.0
error[E0432]: unresolved import `crate::sys::IoSourceState`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/io_source.rs:12:5
   |
12 | use crate::sys::IoSourceState;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^ no `IoSourceState` in `sys`

error[E0433]: failed to resolve: could not find `Selector` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/poll.rs:354:18
    |
354 |             sys::Selector::new().map(|selector| Poll {
    |                  ^^^^^^^^ could not find `Selector` in `sys`

error[E0433]: failed to resolve: could not find `event` in `sys`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:24:14
   |
24 |         sys::event::token(&self.inner)
   |              ^^^^^ could not find `event` in `sys`

error[E0433]: failed to resolve: could not find `event` in `sys`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:29:14
   |
29 |         sys::event::is_readable(&self.inner)
   |              ^^^^^ could not find `event` in `sys`

error[E0433]: failed to resolve: could not find `event` in `sys`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:34:14
   |
34 |         sys::event::is_writable(&self.inner)
   |              ^^^^^ could not find `event` in `sys`

error[E0433]: failed to resolve: could not find `event` in `sys`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:59:14
   |
59 |         sys::event::is_error(&self.inner)
   |              ^^^^^ could not find `event` in `sys`

error[E0433]: failed to resolve: could not find `event` in `sys`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:90:14
   |
90 |         sys::event::is_read_closed(&self.inner)
   |              ^^^^^ could not find `event` in `sys`

error[E0433]: failed to resolve: could not find `event` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:120:14
    |
120 |         sys::event::is_write_closed(&self.inner)
    |              ^^^^^ could not find `event` in `sys`

error[E0433]: failed to resolve: could not find `event` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:142:14
    |
142 |         sys::event::is_priority(&self.inner)
    |              ^^^^^ could not find `event` in `sys`

error[E0433]: failed to resolve: could not find `event` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:164:14
    |
164 |         sys::event::is_aio(&self.inner)
    |              ^^^^^ could not find `event` in `sys`

error[E0433]: failed to resolve: could not find `event` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:174:14
    |
174 |         sys::event::is_lio(&self.inner)
    |              ^^^^^ could not find `event` in `sys`

error[E0433]: failed to resolve: could not find `event` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:212:26
    |
212 |                     sys::event::debug_details(f, self.0)
    |                          ^^^^^ could not find `event` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/listener.rs:91:18
   |
91 |             sys::tcp::accept(inner).map(|(stream, addr)| (TcpStream::from_std(stream), addr))
   |                  ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:22:15
   |
22 |     sys: sys::tcp::TcpSocket,
   |               ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:53:14
   |
53 |         sys::tcp::new_v4_socket().map(|sys| TcpSocket { sys })
   |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:60:14
   |
60 |         sys::tcp::new_v6_socket().map(|sys| TcpSocket { sys })
   |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:73:14
   |
73 |         sys::tcp::bind(self.sys, addr)
   |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:82:27
   |
82 |         let stream = sys::tcp::connect(self.sys, addr)?;
   |                           ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:92:29
   |
92 |         let listener = sys::tcp::listen(self.sys, backlog)?;
   |                             ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:101:14
    |
101 |         sys::tcp::set_reuseaddr(self.sys, reuseaddr)
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:106:14
    |
106 |         sys::tcp::get_reuseaddr(self.sys)
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:125:14
    |
125 |         sys::tcp::set_linger(self.sys, dur)
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:130:14
    |
130 |         sys::tcp::get_linger(self.sys)
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:135:14
    |
135 |         sys::tcp::set_recv_buffer_size(self.sys, size)
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:159:14
    |
159 |         sys::tcp::get_recv_buffer_size(self.sys)
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:164:14
    |
164 |         sys::tcp::set_send_buffer_size(self.sys, size)
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:188:14
    |
188 |         sys::tcp::get_send_buffer_size(self.sys)
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:195:14
    |
195 |         sys::tcp::set_keepalive(self.sys, keepalive)
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:200:14
    |
200 |         sys::tcp::get_keepalive(self.sys)
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:242:14
    |
242 |         sys::tcp::set_keepalive_params(self.sys, keepalive)
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:260:14
    |
260 |         sys::tcp::get_keepalive_time(self.sys)
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:328:14
    |
328 |         sys::tcp::get_localaddr(self.sys)
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `tcp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:334:14
    |
334 |         sys::tcp::close(self.sys);
    |              ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `udp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/udp.rs:122:14
    |
122 |         sys::udp::bind(addr).map(UdpSocket::from_std)
    |              ^^^ could not find `udp` in `sys`

error[E0433]: failed to resolve: could not find `udp` in `sys`
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/udp.rs:517:14
    |
517 |         sys::udp::only_v6(&self.inner)

Let me know if you need any other information.

@beyonddream
Copy link
Author

It seem most likely due to the fact that tokio/mio doesn't support it yet - tokio-rs/tokio#1597

@seanmonstar
Copy link
Owner

It shouldn't need Tokio/Mio's support. CI checks that reqwest can be built for WASM, so it is definitely possible: https://github.com/seanmonstar/reqwest/blob/master/.github/workflows/ci.yml#L292-L323.

@beyonddream
Copy link
Author

Yes, it does build without tokio but I was planning to use tokio to spawn multiple cooperating tasks which make non blocking api requests. I am curious, if I use blocking client version would the wasm target still compile to use Promise.All to make multiple fetch asynchronously on the browser side ?

@seanmonstar
Copy link
Owner

The blocking version of reqwest is not meant to work in WASM.

@beyonddream
Copy link
Author

beyonddream commented Jul 13, 2021

@seanmonstar I saw this example - https://github.com/seanmonstar/reqwest/blob/master/examples/wasm_github_fetch/src/lib.rs#L36 and it seem like what I need. Does the return type really have to be JSValue if I target wasm ?

If it is possible, I would like to keep everything rust type since I will be making multiple api calls , the result of first api call will be fed into the second one etc. It seem to me the only way to do it is to convert the JsValue back to rust type and pass that to the second api call ?

@seanmonstar
Copy link
Owner

The return type of all functions doesn't need to be a JsValue. Only when you want to call that function and use it in JavaScript. If you have multiple functions in Rust that call each other, without JavaScript in the way, you can use Rust return types no problem.

@beyonddream
Copy link
Author

@seanmonstar I was able to accomplish the wasm integration without needing to use tokio with reqwest. I will close this ticket. Thanks for your help and clarification.

@ghost
Copy link

ghost commented Feb 22, 2022

nope, still not working

@samdenty
Copy link

In your [workspace] / [package] configuration, try adding the line resolver = "2".

Resolver 2 is the default in editions 2021 onwards, but it's possible you have some dependencies with 2018 edition which will make it fallback to version 1

@zmlgirl
Copy link

zmlgirl commented Feb 1, 2023

it seems like mio does't support wasm32

@sosaucily
Copy link

I believe Reqwest will use some Mio features of Tokio if both are imported in the project, and Mio doesn't work on wasm currently.

So you can add [target.'cfg(not(target_arch = "wasm32"))'.dependencies] to your cargo.toml file to only import tokio when not compiling for wasm. Reqwest will work without it, as seanmonstar mentions.

Similarly to how reqwest does it here: https://github.com/seanmonstar/reqwest/blob/master/Cargo.toml#L100

This file is a great example of dependency management when compiling for various platforms!

@Ahidada
Copy link

Ahidada commented Apr 22, 2023

Problem solved?

@araujo-luis
Copy link

I think this issue should be reopened

@sht6
Copy link

sht6 commented May 8, 2023

是的,它确实在没有 tokio 的情况下构建,但我打算使用 tokio 来生成多个协作任务,这些任务会发出非阻塞 api 请求。我很好奇,如果我使用阻塞客户端版本,wasm 目标是否仍会编译为使用 Promise.Allfetch在浏览器端异步生成多个?

这个解决了没

@mixolydianmel
Copy link

In your [workspace] / [package] configuration, try adding the line resolver = "2".

Resolver 2 is the default in editions 2021 onwards, but it's possible you have some dependencies with 2018 edition which will make it fallback to version 1

This worked for me, though I'm using yew and building with trunk.

@reidaruss
Copy link

I am also using yew and building with trunk, but unfortunately specifying the resolver did not work for me. Cargo build works fine, but trunk build fails with the same errors as OP.

@aamargant
Copy link

aamargant commented Aug 19, 2023

Any news/updates on this issue ? Getting the same error:

Compiling mio v0.8.8
Compiling rustc-hash v1.1.0
error: Broken pipe (os error 32)
warning: build failed, waiting for other jobs to finish...
Error: 🚫 Building project failed: error[E0432]: unresolved import crate::sys::IoSourceStatestc-has...
--> /Users/arnauamargant/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.8/src/io_source.rs:12:5
|
12 | use crate::sys::IoSourceState;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ no `IoSourceState" in "sys"

@xziy
Copy link

xziy commented Sep 19, 2023

+1 same

@terwer
Copy link

terwer commented Nov 10, 2023

+1 I think this issue is not resolved. Still not work!

Repository owner locked and limited conversation to collaborators Nov 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests