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

Support for WASM without browser (wasm_bindgen) #2538

Open
k0pernicus opened this issue Feb 3, 2025 · 2 comments
Open

Support for WASM without browser (wasm_bindgen) #2538

k0pernicus opened this issue Feb 3, 2025 · 2 comments

Comments

@k0pernicus
Copy link

I was wondering if any support for WASM outside the browser (so, excluding wasm_bindgen from reqwest) is planned or not?

As an example, running this simple program on wasmtime does not work, regarding some components use wasm_bindgen to achieve some goals:

pub async fn fetch_data(url: &str) -> Result<String, reqwest::Error> {
    let client = reqwest::Client::new();
    let response = client.get(url).send().await?;
    response.text().await
}

#[tokio::main(flavor = "current_thread")]
async fn main() {
    fetch_data("https://www.google.com").await;
}

Compilation step:

cargo build --target="wasm32-wasip1"

Running step:

wasmtime target/wasm32-wasip1/debug/reqwest_wasi_test.wasm

thread 'main' panicked at /Users/antonin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/js-sys-0.3.77/src/lib.rs:3441:1:
cannot call wasm-bindgen imported functions on non-wasm targets
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Error: failed to run main module target/wasm32-wasip1/debug/reqwest_wasi_test.wasm

The full log output:

Caused by:
    0: failed to invoke command default
    1: error while executing at wasm backtrace:
           0: 0x1760e5 - reqwest_wasi_test-b78f6a095419b422.wasm!__rust_start_panic
           1: 0x175ec6 - reqwest_wasi_test-b78f6a095419b422.wasm!rust_panic
           2: 0x175e02 - reqwest_wasi_test-b78f6a095419b422.wasm!std::panicking::rust_panic_with_hook::hcbca50d2f726c5b9
           3: 0x17501b - reqwest_wasi_test-b78f6a095419b422.wasm!std::panicking::begin_panic_handler::{{closure}}::hd5f594164b327db3
           4: 0x174f5a - reqwest_wasi_test-b78f6a095419b422.wasm!std::sys::backtrace::__rust_end_short_backtrace::h1dcad5b9bbce3e4b
           5: 0x17573e - reqwest_wasi_test-b78f6a095419b422.wasm!rust_begin_unwind
           6: 0x17fe04 - reqwest_wasi_test-b78f6a095419b422.wasm!core::panicking::panic_fmt::h0e15628bec7245b3
           7: 0x51429 - reqwest_wasi_test-b78f6a095419b422.wasm!js_sys::Object::new::__wbg_new_405e22f390576ce2::h07baa0578ae28fb4
           8: 0x5058f - reqwest_wasi_test-b78f6a095419b422.wasm!js_sys::Object::new::h92cdb7fa2c2c059b
           9: 0x4d011 - reqwest_wasi_test-b78f6a095419b422.wasm!web_sys::features::gen_RequestInit::RequestInit::new::hb315d70a8d03ee06
          10: 0x9484 - reqwest_wasi_test-b78f6a095419b422.wasm!reqwest::wasm::client::fetch::{{closure}}::hd1f7c3f3e07eb377
          11: 0x153ce - reqwest_wasi_test-b78f6a095419b422.wasm!reqwest::wasm::request::RequestBuilder::send::{{closure}}::hfbe6ac045409436e
          12: 0xc5e1 - reqwest_wasi_test-b78f6a095419b422.wasm!reqwest_wasi_test::fetch_data::{{closure}}::h95bc5d1465332d7e
          13: 0xcb69 - reqwest_wasi_test-b78f6a095419b422.wasm!reqwest_wasi_test::main::{{closure}}::h3c7599de9cb0c5c8
          14: 0xc39c - reqwest_wasi_test-b78f6a095419b422.wasm!<core::pin::Pin<P> as core::future::future::Future>::poll::h5a94842c7850d5b0
          15: 0x6890 - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}::{{closure}}::h822a08e5871a3356
          16: 0x5474 - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}::hf4428530e193b4aa
          17: 0x52ed - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::scheduler::current_thread::Context::enter::h9d2059f410c3916b
          18: 0x6412 - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::h2c8db4f0698941fc
          19: 0x6283 - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::scheduler::current_thread::CoreGuard::enter::{{closure}}::h60ec7de4102377f1
          20: 0x7225 - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::context::scoped::Scoped<T>::set::h4b019683759bdfee
          21: 0x36cd - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::context::set_scheduler::{{closure}}::h1c3bef6d7c13badb
          22: 0xd818 - reqwest_wasi_test-b78f6a095419b422.wasm!std::thread::local::LocalKey<T>::try_with::h803f311836ccd027
          23: 0xd60b - reqwest_wasi_test-b78f6a095419b422.wasm!std::thread::local::LocalKey<T>::with::haf178bfffafaecee
          24: 0x35fe - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::context::set_scheduler::hbf7381da4acfc7f4
          25: 0x5bd5 - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::scheduler::current_thread::CoreGuard::enter::h4afd3059c2e6e0ee
          26: 0x49d9 - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::scheduler::current_thread::CoreGuard::block_on::h54c655a74657d586
          27: 0x46e6 - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::scheduler::current_thread::CurrentThread::block_on::{{closure}}::h4cd71b623d2902ae
          28: 0x737e - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::context::runtime::enter_runtime::h10973758b664391e
          29: 0x3f24 - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::scheduler::current_thread::CurrentThread::block_on::h6bb0b760c37c2c29
          30: 0x12978 - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::runtime::Runtime::block_on_inner::h560ceb03fbd88de2
          31: 0x12a14 - reqwest_wasi_test-b78f6a095419b422.wasm!tokio::runtime::runtime::Runtime::block_on::ha8f0660e9646de76
          32: 0x9323 - reqwest_wasi_test-b78f6a095419b422.wasm!reqwest_wasi_test::main::hadf609d4e5abd2f9
          33: 0xe6f3 - reqwest_wasi_test-b78f6a095419b422.wasm!core::ops::function::FnOnce::call_once::hc5d798b5e9289b30
          34: 0xe2b8 - reqwest_wasi_test-b78f6a095419b422.wasm!std::sys::backtrace::__rust_begin_short_backtrace::hd7a74e6dcf9b902d
          35: 0xb22b - reqwest_wasi_test-b78f6a095419b422.wasm!std::rt::lang_start::{{closure}}::h7fc69762e5c0df08
          36: 0x173907 - reqwest_wasi_test-b78f6a095419b422.wasm!std::rt::lang_start_internal::ha2dbbf0137776456
          37: 0xb1c7 - reqwest_wasi_test-b78f6a095419b422.wasm!std::rt::lang_start::h72e8b69396a82c2e
          38: 0x938b - reqwest_wasi_test-b78f6a095419b422.wasm!__main_void
          39: 0x1c5a - reqwest_wasi_test-b78f6a095419b422.wasm!_start
       note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information
    2: wasm trap: wasm `unreachable` instruction executed

Thanks in advance for your response.

@seanmonstar
Copy link
Owner

Hey there! Supporting more environments is usually something we'd be happy to do. All of reqwest's WASM support is contributed by others, I don't have any active work in WASM. So, if you want to help propose how to add support, and implement it, that'd be welcome!

@k0pernicus
Copy link
Author

Thanks Sean.
As I am getting into support for WASM (for servers, not browsers) I don't promise anything but I will look at the code later and check how I can modify this or this in order to get both browser & server (without wasm_bindgen) support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants