Skip to content

cgojin/running-wasm-by-wasmtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

running-wasm-by-wasmtime

Running wasm/wasi by wasmtime.

Build and Run native app.

cargo build
target/debug/hello
    Hello, world!

Build and Run wasm/wasi app

# add wasm32-wasi target, first only
rustup target add wasm32-wasi

# install wasmtime, first only
curl https://wasmtime.dev/install.sh -sSf | bash
# or install cargo-wasi, first only
cargo install cargo-wasi

# build .wasm
cargo build --target wasm32-wasi

# run .wasm
wasmtime target/wasm32-wasi/debug/hello.wasm
    Hello, world!

# build & run .wasm
cargo wasi run
    Hello, world!

# install wasm-tools, first only
cargo install wasm-tools

# show export methods
wasm-tools print target/wasm32-wasi/debug/hello.wasm | grep "(export" 
  (export "memory" (memory 0))
  (export "_start" (func $_start))
  (export "__main_void" (func $__main_void))

Build and Run wasm/wasi lib

# build .wasm
cargo wasi build

# run .wasm
wasmtime --invoke print_hello target/wasm32-wasi/debug/hellolib.wasm

# show export methods
wasm-tools print target/wasm32-wasi/debug/hellolib.wasm | grep "(export"
  (export "memory" (memory 0))
  (export "print_hello" (func $print_hello.command_export))
  (export "add" (func $add.command_export))

Python call wasm lib

cp target/wasm32-wasi/debug/hellolib.wasm .
pip install wasmtime
python src/test.py

References

Releases

No releases published

Packages

No packages published