我尝试使用rustwasm引用https://rustwasm.github.io/book/game-of-life/hello-world.html,all正常工作。
但是当我在Cargo.toml中添加reqwest = "0.9.22"
时,然后在我的项目中执行wasm-pack build
命令时,编译器会报告这样的错误:
$ wasm-pack build > log.log
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
Compiling net2 v0.2.33
Compiling openssl-sys v0.9.53
Compiling http v0.1.21
Compiling string v0.2.1
Compiling tokio-buf v0.1.1
Compiling backtrace v0.3.40
Compiling mime_guess v2.0.1
Compiling cookie v0.12.0
error[E0432]: unresolved import sys
--> D:\cargo\registry\src\github.com-1ecc6299db9ec823\net2-0.2.33\src\tcp.rs:18:5
|
18 | use sys::c;
| ^^^ maybe a missing crate sys?
error[E0432]: unresolved import sys
--> D:\cargo\registry\src\github.com-1ecc6299db9ec823\net2-0.2.33\src\udp.rs:18:5
|
18 | use sys::c;
| ^^^ maybe a missing crate sys?
error[E0432]: unresolved import sys
--> D:\cargo\registry\src\github.com-1ecc6299db9ec823\net2-0.2.33\src\socket.rs:22:5
|
22 | use sys;
| ^^^ no sys in the root
error[E0432]: unresolved import sys
--> D:\cargo\registry\src\github.com-1ecc6299db9ec823\net2-0.2.33\src\socket.rs:23:5
|
23 | use sys::c;
| ^^^ maybe a missing crate sys?
error[E0432]: unresolved import sys
--> D:\cargo\registry\src\github.com-1ecc6299db9ec823\net2-0.2.33\src\ext.rs:19:5
|
19 | use sys;
| ^^^ no sys in the root
error[E0432]: unresolved import sys
--> D:\cargo\registry\src\github.com-1ecc6299db9ec823\net2-0.2.33\src\ext.rs:20:5
|
20 | use sys::c;
| ^^^ maybe a missing crate sys?
error[E0412]: cannot find type c_uint in this scope
--> D:\cargo\registry\src\github.com-1ecc6299db9ec823\net2-0.2.33\src\ext.rs:1335:39
|
1335 | fn to_ipv6mr_interface(value: u32) -> c_uint {
| ^^^^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
|
13 | use std::os::raw::c_uint;
error[E0599]: no method named as_sock found for type &udp::UdpBuilder in the current scope
...省略类似错误 -> D:\ cargo \ registry \ src \ github.com-1ecc6299db9ec823 \ net2-0.2.33 \ src \ ext.rs:1499:22 | 1499 | get_opt(self.as_sock(),SOL_SOCKET,SO_ERROR).map(int2err) |在&udp :: UdpBuilder中找不到^^^^^^^^方法 | =帮助:特征中的项目只能在特征已实现且作用域内的情况下使用 =注意:以下特征定义了项as_sock,也许您需要实现它: 候选人#1:ext :: AsSock
error: aborting due to 317 previous errors
Some errors have detailed explanations: E0046, E0412, E0422, E0425, E0432, E0599.
For more information about an error, try rustc --explain E0046.
error: could not compile net2.
warning: build failed, waiting for other jobs to finish...
error: build failed
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute cargo build: exited with exit code: 101
我的环境
wasm-pack version: wasm-pack 0.8.1
rustc version: rustc 1.39.0 (4560ea788 2019-11-04)
operation system: windows10
答案 0 :(得分:0)
我有类似的问题。感谢csmoe on Github,我发现net2
不支持目标wasm32
。参见https://github.com/rust-lang-nursery/net2-rs/blob/eda403f03033b58560d81b821f0df822f50cde4d/src/socket.rs#L15-L16