Please install the prerequisites first!
$ docker run --rm --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm secondstate/rust-example-move:latest
The src/main.rs
source code shows
- When the
hello
string variable is passed into thetake()
function, it is no longer available outside oftake()
. - You can create a
clone()
of thehello
string variable to pass totake()
. This way, the originalhello
is still available outside oftake()
. - You can also pass a reference of the
hello
string to theborrow()
function. Since theborrow()
function only borrowed a reference of this variable, the originalhello
is still available outside ofborrow()
.- The
&string
reference can be automatically cast to an immutable&str
. So, theborrow()
function can also take a&str
as argument.
- The
Compile the Rust source code project to a Wasm bytecode file.
$ cargo build --target wasm32-wasi --release
Run the Wasm bytecode file in WasmEdge CLI.
$ wasmedge target/wasm32-wasi/release/move.wasm
The Dockerfile
follows the above steps to build and package a lightweight OCI-compliant container image for the Wasm app.
Now, we need to publish the container image to Docker Hub. The process is slightly different depending on how you plan to use the image.
For containerd based systems, such as the Docker Desktop and many flavors of Kubernetes,
you just need to specify that the WasmEdge application image is for the wasi/wasm
platform.
$ docker buildx build --provenance=false --platform wasi/wasm -t secondstate/rust-example-move .
... ...
$ docker push secondstate/rust-example-move