This example demonstrates how to manipulate linear memory.
Now let's build and run this example.
-
Install
rustup
andRust
Go to the official Rust webpage and follow the instructions to install
rustup
andRust
.It is recommended to use Rust 1.71 or above in the stable channel.
Then, add
wasm32-wasi
target to the Rustup toolchain:rustup target add wasm32-wasi
-
Install WasmEdge Runtime
Refer to the Quick Install section of WasmEdge Runtime Book to install WasmEdge Runtime. Or, use the following command directly
# NOTICE that the installation script needs `sudo` access # install wasmedge to the directory /usr/local/ curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -v 0.14.0 source $HOME/.wasmedge/env
For users in China mainland (中国大陆地区), try the following command to install WasmEdge Runtime if failed to run the command above
# NOTICE that the installation script needs `sudo` access bash install_zh.sh -v 0.14.0 source $HOME/.wasmedge/env
-
Download example
git clone git@github.com:second-state/wasmedge-rustsdk-examples.git cd wasmedge-rustsdk-examples/manipulate-linear-memory
-
Build & run
cargo run
If the command runs successfully, then the following result is printed out on the screen:
The memory size (in pages): 1 The data size (in bytes): 65536 The memory size (in pages) after growing memory additional 2 pages: 3 The data size (in bytes) after growing memory additional 2 pages: 196608 Set 0xFEFEFFE at the memory address 0x2220 Retrieve the value at the memory address 0x2220: 0xFEFEFFE Set 0xFEA09 at the memory address 0x1FFFC Retrieve the value at the memory address 0x1FFFC: 0xFEA09