-
Notifications
You must be signed in to change notification settings - Fork 824
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
wai-bindgen-wasmer::wasmer doesn't work on the web #3870
Comments
kajacx
changed the title
wai-bindgen-wasmer::wasmer doesn't work, but standalone wasmer does
wai-bindgen-wasmer::wasmer doesn't work on the web
May 16, 2023
Ok, found the problem. /// Creates a new WebAssembly module skipping any kind of validation from a javascript module
///
pub(crate) unsafe fn from_js_module(
module: WebAssembly::Module,
binary: impl IntoBytes,
) -> Self {
let binary = binary.into_bytes();
// The module is now validated, so we can safely parse it's types
#[cfg(feature = "wasm-types-polyfill")]
let (type_hints, name) = {
let info = crate::js::module_info_polyfill::translate_module(&binary[..]).unwrap();
(
Some(ModuleTypeHints {
imports: info
.info
.imports()
.map(|import| import.ty().clone())
.collect::<Vec<_>>(),
exports: info
.info
.exports()
.map(|export| export.ty().clone())
.collect::<Vec<_>>(),
}),
info.info.name,
)
};
#[cfg(not(feature = "wasm-types-polyfill"))]
let (type_hints, name) = (None, None);
Self {
module,
type_hints,
name,
#[cfg(feature = "js-serializable-module")]
raw_bytes: Some(binary.into_bytes()),
}
} Pull request coming soon. |
kajacx
added a commit
to kajacx/wasmer
that referenced
this issue
May 18, 2023
Fixes wasmerio#3870 `wasm-types-polyfill` feature, which is enabled by `js-default`, is needed for type annotations.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
EDIT:
This "bug" is not caused by the difference between
wasmer
andwai-bindgen-rust::wasmer
, instead, it was caused by not including thewasm-types-polyfill
feature. See the next comment.Original post:
Describe the bug
Using
wai-bindgen-wasmer::wasmer
on the web (with thejs
feature) doesn't work correctly. When loading a function, wasmer thinks that the function has no arguments. Usingwasmer
directly, on the other hand, works.Steps to reproduce
wasmer-works-but-not-in-wai
tag.run-wasm-only-forked.sh
script and open it in browser to see the error in JS console.run-no-wai-web.sh
script and open it in browser to see it work correctly.Expected behavior
Using
wai-bindgen-wasmer::wasmer
should work exactly the same as usingwasmer
directly, since both folders use wasmer 3.3:wasm-only-forked
is usingwai-bindgen-wasmer
0.4.0, which is usingwasmer
3.3.0no-wai-web
is usingwasmer
3.3.0 directlyActual behavior
Getting a typed function in
wasm-only-forked
gives this error:should cast to typed: RuntimeError { source: Trap { inner: User(RuntimeStringError { details: "given types (
[I32]) for the function arguments don't match the actual types (
[])" }) }, wasm_trace: [] }
Additional context
The problem originates in file
wasm-only-forked/src/lib.rs
, lile 32:Here is the code in wasmer, for convenience:
Here is the WASM plugin in WAT format, decompiled by wasm2wat demo:
Note:
When using the
sys
feature (instead ofjs
), it works both when usingwai-bindgen-wasmer::wasmer
and inwasmer
directly.I have tried deleting the
target
folder and myCargo.lock
file, but with the same result.The text was updated successfully, but these errors were encountered: