Setup Rust
Creating Golem components in Rust requires installing the latest stable compiler, enabling the WASM target and installing the supported version of cargo-component
.
Installing Rust
Use the official guide (opens in a new tab) to install the latest stable version of the Rust compiler.
For MacOS the recommended way is using rustup
by running the following installation script:
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Enabling WebAssembly targets
With rust
and rustup
installed, the next step is to enable the WebAssembly support by running:
$ rustup target add wasm32-wasi
To verify if this step was successful, run:
$ rustc --print target-list | grep wasm32-wasi
wasm32-wasi
wasm32-wasip1
wasm32-wasip1-threads
wasm32-wasip2
Installing cargo-component
The last step is installing the cargo-component
extension for Rust's cargo
build tool. This will enable a set of subcommands for cargo
which allows compiling Rust projects into WebAssembly components, which are ready to be uploaded to Golem.
Golem requires a specific version of cargo-component
. Please make sure the correct version
is installed with the commands described below.
Install the version 0.13.2
of cargo-component
with cargo
itself:
$ cargo install --force --locked cargo-component@0.13.2
Verify that the correct version is installed:
$ cargo component --version
cargo-component 0.13.2 (wasi:040ec92)
Please refer to the cargo-component website (opens in a new tab) for more information.