Stream: general

Topic: ✔ rust <-> js in browser


view this post on Zulip Fabrice Desré (Dec 17 2021 at 22:59):

I'm toying around with a simple wit definition and it's generated code: I implemented the Rust side, and a way to call it from js (in the browser):

record FeatureDescription {
    name: string,
    description: string,
}

// Return the list of supported features.
get_features: function() -> list<FeatureDescription>
  let plugins = new Plugins();
  await plugins.instantiate(
    fetch("./target/wasm32-unknown-unknown/release/witplugins.wasm")
  );
  console.log(`Features: `, plugins.getFeatures());

the getFeatures() call fails because the JS side expects a "canonical_abi_free" export which is not provided. What am I missing on the Rust side?

Thanks!

view this post on Zulip Fabrice Desré (Dec 17 2021 at 23:26):

Nevermind, I figured it out thanks to the discussion in https://github.com/bytecodealliance/wit-bindgen/issues/59 : using wit_bindgen_rust::export!(...) instead of manually importing the Rust generated code does the trick!

The use case is the following: I am using the generated export Wasmtime bindings to execute a specific function through Wasmtime. This works fine for modules that have not been linked, but fails fo...

view this post on Zulip Notification Bot (Dec 18 2021 at 17:08):

Fabrice Desré has marked this topic as resolved.


Last updated: Dec 23 2024 at 12:05 UTC