second-state / rustwasmc

Tool for building Rust functions for Node.js. Combine the performance of Rust, safety and portability of WebAssembly, and ease of use of JavaScript.
https://www.secondstate.io/articles/rustwasmc/
Apache License 2.0
130 stars 10 forks source link

ssvmup generated js file has imports['__wbindgen_placeholder__'] = module.exports; #9

Closed arthurgreef closed 3 years ago

arthurgreef commented 3 years ago

I run the following command: ssvmup build --target nodejs --dev

And I get the following line in the generated js file. imports['__wbindgen_placeholder__'] = module.exports;

Is there something I can do to fix this as it fails to load into nodejs?

TypeError: WebAssembly.Instance(): Import #0 module="__wbindgen_placeholder__" error: module is not an object or function

juntao commented 3 years ago

Just do the following. It targets to nodejs by default.

ssvmup build

If you want to make WASI tensorflow calls from the WebAssembly program, use

ssvmup build --enable-ext

or, if you want to generate AOT binaries together with the wasm bytecode.

ssvmup build --enable-aot

or, if you want to target deno

ssvmup build --target deno

arthurgreef commented 3 years ago

Thanks. Now when I load the wasm into nodejs but running: node --experimental-wasi-unstable-preview1 --experimental-wasm-bigint I get the following error: 2021-03-26 06:49:09,734 ERROR [default] instantiation failed: unknown import, Code: 0x62 2021-03-26 06:49:09,734 ERROR [default] When linking module: "__wbindgen_placeholder" , function name: "wbindgen_throw" 2021-03-26 06:49:09,734 ERROR [default] At AST node: import description 2021-03-26 06:49:09,734 ERROR [default] At AST node: import section 2021-03-26 06:49:09,734 ERROR [default] At AST node: module

juntao commented 3 years ago

You will need to install ssvm (or ssvm-extensions) via NPM. The ssvmup-generated JS bootstrap does not work with the V8 wasm engine in nodejs.

On Fri, Mar 26, 2021 at 9:52 PM Arthur Greef @.***> wrote:

Thanks. Now when I load the wasm into nodejs but running: node --experimental-wasi-unstable-preview1 --experimental-wasm-bigint I get the following error: 2021-03-26 06:49:09,734 ERROR [default] instantiation failed: unknown import, Code: 0x62 2021-03-26 06:49:09,734 ERROR [default] When linking module: " wbindgen_placeholder" , function name: "__wbindgen_throw" 2021-03-26 06:49:09,734 ERROR [default] At AST node: import description 2021-03-26 06:49:09,734 ERROR [default] At AST node: import section 2021-03-26 06:49:09,734 ERROR [default] At AST node: module

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/second-state/ssvmup/issues/9#issuecomment-808236522, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACUNSYF5QO26L5LGEIM5DTFSGR3ANCNFSM4Z2VB4OQ .

--

Michael Yuan, PhD Co-founder at Second State https://www.secondstate.io/ Fast, safe, portable & serverless Rust functions in Node.js https://cloud.secondstate.io/server-side-webassembly/getting-started Interested in Rust? Learn by examples https://rust-by-example-ext.com/!

arthurgreef commented 3 years ago

OK i think I have everything installed. I'm still confused by wasm bindgen.

If I have a function with no args and no return type I get a js file that works.

[wasm_bindgen]

pub fn mint_instruction() { } If I add an argument to the function then I get a wbindgen placeholder in the js file and loading fails.

[wasm_bindgen]

pub fn mint_instruction(p: &str) { } This is in the js file.

let imports = {}; imports['__wbindgen_placeholder__'] = module.exports; let wasm;

What are the valid argument and return types? I tried to search but nothing seems to work. I am using wasm-bindgen = "=0.2.61". Thanks.

arthurgreef commented 3 years ago

I think the issue is that we are using the wasm32-- wasi build target and wasm-bindgen does not seem to work with wasi generated wasm.

arthurgreef commented 3 years ago

I think the issue was not having the same version of wasm-bindgen in both the cargo.toml and the wasm-bindgen-cli install.

alexl0gan commented 3 years ago

@arthurgreef How did you solve this? I am seeing this happen when using serde for deserialization.

arthurgreef commented 3 years ago

I did not solve the problem. I went back to using nodejs wasi extensions and rewriting the js binding file.

alexl0gan commented 3 years ago

@arthurgreef don't close the issue then! I have raised one here https://github.com/second-state/rustwasmc/issues/14