http-rs / surf

Fast and friendly HTTP client framework for async Rust
https://docs.rs/surf
Apache License 2.0
1.45k stars 119 forks source link

unable to build with wasm32-wasi target #301

Open ctaggart opened 3 years ago

ctaggart commented 3 years ago

I'm seeing if I can use surf with wasi. Unfortunately, the dependencies appear not to be correct, even with

[dependencies]
async-executor = "*"
futures-lite = "*"
surf = { version = "*", default-features = false, features = ["wasm-client"] }

I get a dependency on socket2

cargo tree --invert socket2 --target wasm32-wasi
socket2 v0.4.0
└── async-io v1.4.0
    ├── async-global-executor v2.0.2
    │   └── async-std v1.9.0
    │       ├── http-types v2.11.0
    │       │   ├── http-client v6.3.5
    │       │   │   └── surf v2.2.0
    │       │   │       └── try_wasi_async v0.1.0 (C:\Users\cataggar\rs\try_wasi_async)
    │       │   └── surf v2.2.0 (*)
    │       └── surf v2.2.0 (*)
    └── async-std v1.9.0 (*)

Test app is:

use async_executor::{Executor, Task};
use futures_lite::future;
use surf::Result;

fn main() -> Result<()> {
    let ex = Executor::new();
    let task: Task<Result<()>> = ex.spawn(async {
        let ip = surf::get("http://ip.jsontest.com/").await?.body_string().await?;
        println!("ip {}", &ip);
        Ok(())
    });
    future::block_on(ex.run(task))
}

Which I've pushed here: https://github.com/ctaggart/try_wasi_async