Rust WASI Example
A toy program implementing HQ9+ to demo compiling Rust to WASI and running it with Wasmer.
Setting up
You will need the Rust toolchain installed.
First, let's clone the repo:
Ensure you have an up to date version of Rust and run:
Building
Running
Uploading to WAPM
Setting up wapm
cli
To upload to WAPM we must first make an account:
- Go to wapm.io
- Create an account (sign up)
- Log in with the
wapm
cli client
Setting up the project for wapm
To run the project with wapm
we must create a wapm.toml
manifest file to instruct wapm
how to run the wasm binary.
Our wapm.toml
contains 3 sections:
-
[package]
This is where the metadata about the package lives -
[[module]]
This is where metadata about the module (wasm binary) lives -
[[command]]
This is where we tellwapm
how to run the module and what to call it
For more information about these sections see the documentation.
IMPORTANT:
To publish the project to the wapm registry, you must change the namespace (the package.name
field before the /
) to match the username you made while signing up and that you are now logged in as (wapm whoami
).
For your convenience, you may run the following snippet to edit it for you.
When making a new wapm
project, this step is not necessary; the wapm init
command creates a wapm.toml
skeleton, with your name as the namespace, for you.
Running the project with wapm
locally
Now that we're all set up, we can use wapm
to run our wasm binary!
Uploading to WAPM
Now that we've set up wapm
and verified that it works locally, we're ready to upload to the WAPM registry: