Invalid function signature when loading Rust-generated webassembly binary from Python

Viewed 33

The full code is here:

https://github.com/dmerejkowsky/chuck-norris-webassembly-plugins

Here's what's wrong

There's a get_fact method written in Rust and exported with wasm_bindgen:

#[wasm_bindgen]
pub fn get_fact() -> String {
    "Chuck Norris can slam a revolving door".to_string()
}

When I build the wasm file with wasm-pack --target nodejs I can call the get_fact just fine from Javascript:

const assert = require('node:assert/strict');
const ck = require('../pkg/chuck_norris.js');

const actual = ck.get_fact();
assert.ok(actual.includes("Chuck Norris"));

But when trying to write the same test in Python:

from wasmer import engine, Store, Module, Instance
from wasmer_compiler_cranelift import Compiler

rust_wasm = Path / "to" / "chucknorris_bg.wasm"

store = Store(engine.Universal(Compiler))
module = Module(store, rust_wasm.read_bytes())
instance = Instance(module)
get_fact = instance.exports.get_fact
actual = get_fact()
assert "Chuck Norris" in actual

I get :

RuntimeError: Parameters of type [] did not match signature [I32] -> []

Any clues as to why NodeJs and Python disagree on the signature of the get_fact() function ?

1 Answers
Related