Create a new applet
You can create a Rust applet called tutorial with the following command:
wasefire rust-applet-new tutorial
This creates a tutorial directory with an example Rust applet. Let’s look at Cargo.toml:
- The
wasefiredependency provides a Rust interface for the applet API. - The
wasefire-stuboptional dependency provides support for testing. - The
testfeature enables testing support.
And now let’s look at src/lib.rs:
- The
#![no_std]attribute is needed for building WASM modules without WASI. As a consequence, you cannot usestd. Instead, you need to usecoreandalloc. - The
wasefire::applet!();macro does a few things:- It makes sure the
main()function is executed when the applet starts. - It imports the
alloccrate. - It imports all the items of the
wasefirecrate.
- It makes sure the
- In the
testsmodule, theuse wasefire_stub as _;makes sure thewasefire-stubcrate is linked since it provides symbol definitions for the applet API.
Since most commands assume they are running from the root directory of the Rust applet (unless
--crate-dir is provided), you can change the working directory to the crate:
cd tutorial