Please install the prerequisites first!
$ docker run --rm --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm secondstate/rust-example-control:latest
Hello WasmEdge!
Howdy WasmEdge!
Hola WasmEdge!
Bonjour WasmEdge!
guten tag WasmEdge!
WasmEdge 你好!
こんにちは WasmEdge!
Salve WasmEdge!
Salve WasmEdge!
The src/main.rs source code shows
- The
forloop starts from value0and repeats10times, each increasing by1. - The
matchclause matches the control variable to specific values and branches to the corresponding statements. If control variable does not match any listed value, it will match to the_branch.
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/control.wasm
Hello WasmEdge!
Howdy WasmEdge!
Hola WasmEdge!
Bonjour WasmEdge!
guten tag WasmEdge!
WasmEdge 你好!
こんにちは WasmEdge!
Salve WasmEdge!
Salve WasmEdge!
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-control .
... ...
$ docker push secondstate/rust-example-control