Set up Rust for CDB EdgeCompute
The Legacy Rust SDK is based on the edgecompute crate, CDB's original Rust library for CDB EdgeCompute HTTP applications. Most existing CDB EdgeCompute applications written in Rust use this SDK. Use this setup when working with existing applications built on the edgecompute crate or when maintaining code that still targets wasm32-wasip1.
The crate provides the #[edgecompute::http] entry-point macro together with APIs for environment variables, secrets, key-value storage, dictionary access, and cache integration.
Rust and Cargo are required. On Windows, also install Visual Studio Build Tools with the Desktop development with C++ workload.
For new applications, the Modern Rust SDK (wstd, wasm32-wasip2) is the recommended direction — it uses the WASI-HTTP standard and reduces dependency on CDB-specific tooling.
Add the WebAssembly target
The Legacy SDK compiles to wasm32-wasip1. Add the target once — it applies to all future builds:
rustup target add wasm32-wasip1
Configure a project
CDB EdgeCompute applications compile to WebAssembly libraries rather than standalone executables. Two changes from the Cargo defaults are needed: the output type must be cdylib, and the edgecompute crate must be listed as a dependency.
-
Create the library crate:
cargo new --lib my-app cd my-app -
Replace the contents of
Cargo.toml:[package] name = "my_app" version = "0.1.0" edition = "2021" [lib] crate-type = ["cdylib"] [dependencies] edgecompute = "0.4" anyhow = "1.0"crate-type = ["cdylib"]changes the output to a format the CDB EdgeCompute runtime can load.edgecompute = "0.4"provides the entry-point macro and access to CDB EdgeCompute-specific APIs.anyhowis used for error handling in the verification example below.
Verify the toolchain
A minimal handler is enough to confirm the toolchain produces a valid WebAssembly binary. Replace src/lib.rs:
use edgecompute::body::Body;
use edgecompute::http::{Request, Response, StatusCode, Error};
#[edgecompute::http]
fn main(_req: Request<Body>) -> Result<Response<Body>, Error> {
Response::builder()
.status(StatusCode::OK)
.body(Body::from("OK"))
}
Build it:
cargo build --release --target wasm32-wasip1
The first build downloads dependencies and takes one to two minutes. When it completes without errors, the toolchain is ready — the compiled binary is at ./target/wasm32-wasip1/release/my_app.wasm. That file can be uploaded to CDB EdgeCompute directly or used as the starting point for the next tutorial.