0

I am starting out with web-assembly following this guide: https://depth-first.com/articles/2020/06/29/compiling-rust-to-webassembly-a-simple-example/

When I compile the source with cargo build --target wasm32-unknown-unknown --release i get a .wasm file. Instead of importing this module in JavaScript, I want to uses wasmer. I have installed wasmer 2.2.1, but when I try to run wasmer run target/wasm32-unknown-unknown/release/hello.wasm, I get the following error:

error: failed to run `target/wasm32-unknown-unknown/release/hello.wasm`
╰─▶ 1: No export `_start` found in the module.
       Similar functions found: `add_one`.
       Try with: wasmer target/wasm32-unknown-unknown/release/hello.wasm -i add_one

Is this the intended use of wasmer? If so, where should I search for culprits?

EDIT

I did not read the error message properly, it seems as if wasmer run target/wasm32-unknown-unknown/release/hello.wasm -i add_one 1 does work and will return 2.

Kevin
  • 3,096
  • 2
  • 8
  • 37
  • I imagine to make it work with `wasmer run hello.wasm` your crate should be a binary instead of a library – kmdreko Jun 25 '22 at 15:55
  • @kmdreko You're right, just learning how it works. I want to eventually be able to read data from a network socket, so I think the `cargo build --target wasm32-wasi` is better suited for this. However, there is also `cargo wasi` and `wasm-bindgen` as seen in the sections *Writing Libraries* and *WebAssembly Interface Types* for the rust wasmtime docs: https://docs.wasmtime.dev/wasm-rust.html#writing-libraries. I believe the `wasm-bindgen` is only used for targeting web stuff with JavaScript interoperability, but why would one use `cargo wasi build` over `cargo build --target wasm32-wasi` ? – Kevin Jun 25 '22 at 16:59

0 Answers0