Skip to main content

wasmrun init

Create a new project from a template.

Synopsis​

wasmrun init [NAME] [--template <TEMPLATE>] [--directory <DIR>]

Aliases: new

Description​

Writes a small, working project into a new directory and prints the command that runs it. Each template is one of the repository's examples, compiled into wasmrun, so a new project is one that CI already builds and runs. The example's name is replaced with yours wherever it appears: the crate or package name, the module path, the README.

Most templates are for server mode, but nodejs and wasi start projects for the other modes, so init is the starting point for all of them.

Options​

OptionDefaultDescription
NAMEmy-wasmrun-projectThe project's name, used for the directory and inside the files
-t, --template <TEMPLATE>rustWhich template to start from (see below)
-d, --directory <DIR>NAMEWhere to create it, when that differs from the name

init refuses a directory that already exists, so it never writes over your files.

Templates​

TemplateModeComes fromRun it with
rustServerexamples/rust-hellowasmrun my-app
goServerexamples/go-hellowasmrun my-app
cServerexamples/c-hellowasmrun my-app
ascServerexamples/asc-hellowasmrun my-app
pythonServerexamples/python-hellowasmrun my-app
nodejsOS, or an agent session's serverexamples/nodejs-http-apiwasmrun os my-app
wasiExecexamples/native-rustcargo build --release --target wasm32-wasip1, then wasmrun exec the .wasm

A server-mode template still needs its language's toolchain and plugin to build, as any project does. See Languages for what each one needs.

Usage​

wasmrun init hello-wasm
+ Cargo.toml
+ src/lib.rs
+ README.md
+ .gitignore

✅ Created hello-wasm from the rust template (server mode). Next:
wasmrun hello-wasm

A Node.js HTTP server for OS mode:

wasmrun init api --template nodejs
wasmrun os api

A WASI program for exec mode, in a directory other than its name:

wasmrun init tool -t wasi -d tools/tool
cd tools/tool && cargo build --release --target wasm32-wasip1
wasmrun exec target/wasm32-wasip1/release/tool.wasm

See Also​