Skip to main content
Version: 1.x

Build

The wash CLI command includes a build subcommand that can be used to build WebAssembly components.

info

See the wash build CLI reference page for more information on available flags.

The rest of this page will focus on practical examples of using the wash build command.

Language support

Some languages (like Rust and Go) have support built-in to wash, while others require extra customization. A list of languages with built-in support is published in the wasmcloud.toml specification.

Example projects written in languages with native support can be built by running:

console
wash build

While you can always use the standard Rust toolchain and Bytecode Alliance tooling (like wkg for fetching WIT packages) to build your components, wash build's native support for Rust projects makes building components easier.

The wash build subcommand performs the same tasks as the following commands using tooling from the wider ecosystem:

console
# Fetch wit dependencies (see https://github.com/bytecodealliance/wasm-pkg-tools)
wkg wit fetch
# Build the WebAssembly component with the native Rust toolchain
cargo build --release --target wasm32-wasip2
# Sign the built WebAssembly component with your generated keys, using information in wasmcloud.toml
wash claims sign ./target/wasm32-wasip2/release/http_hello_world.wasm --destination http_hello_world_s.wasm

With native support for Rust implemented in wash build, the above simplifies to:

console
wash build

Interface dependencies and wash build

When you run wash build, wash reads the specified world in your WIT files and downloads the appropriate dependencies automatically into the wit/deps directory. As such, in most cases you should add wit/deps to your .gitignore file and commit the generated wasmcloud.lock file.

Without any additional configuration, wash can download dependencies from the following namespaces (i.e. the wasi in wasi:http@0.2.1):

In most cases, dependency fetching and management should be fairly straightforward! As your usage of Wasm grows, however, you are likely to use dependencies that are not in the above namespaces (such as internal registries or other remappings). Also, if you plan to publish any custom interfaces, you will need to configure your registry with credentials. For instructions on registry authentication, see the Publish page.

WIT interfaces are packaged and distributed as OCI artifacts. You can learn more about how the wasmCloud ecosystem uses OCI artifacts on the Packaging page.

Migrating from wit-deps

Older versions of wash required a separate step using a wit-deps tool to download dependencies. This is no longer necessary with the newest versions of wash. To preserve backwards compatibility, if a deps.toml file is found in the wit directory of the project, wash will not fetch dependencies for you. To migrate to the new dependency management system, simply remove the deps.toml file and run wash build again. wash build will automatically remove all the old dependencies and download the new ones into your wit/deps directory.

warning

If you are using some of the provided wrpc interfaces like wrpc:blobstore, you will need to continue using wit-deps. This is due to an issue where some of the wrpc interfaces use syntax that is not yet available in the main WIT parser (but will be when WASI 0.3 is released) which causes the dependency resolution to fail.