You deploy Rust applications to Azure Functions by compiling your code to a WebAssembly (WASM) binary or a native executable and packaging it within the standard Azure Functions runtime structure, as Azure does not natively support Rust as a first-class language. The most reliable approach is using the azure-functions-rust template to generate a project that compiles to a native binary for the Linux-based dotnet-isolated or python worker, or by leveraging the WASM worker if you prefer a lightweight, portable runtime.
For a native binary deployment on Linux, you typically compile your Rust code to a static executable and place it in the function directory alongside a function.json manifest. Here is a minimal example of a Cargo.toml setup and the deployment structure:
# Cargo.toml
[package]
name = "azure-func-rust"
version = "0.1.0"
edition = "2021"
[dependencies]
azure-functions = "0.1" # Or use a generic HTTP handler if using WASM
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Your project structure should look like this before zipping for deployment:
my-function/
├── function.json
├── host.json
└── azure-func-rust (compiled binary)
The function.json defines the trigger and binding:
{
"scriptFile": "azure-func-rust",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": ["get", "post"]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
To deploy, compile for the target architecture (usually x86_64-unknown-linux-musl for Azure Linux) and zip the contents:
# Compile for Linux musl target
rustup target add x86_64-unknown-linux-musl
cargo build --release --target x86_64-unknown-linux-musl
# Zip the function directory (excluding Cargo files)
cd target/x86_64-unknown-linux-musl/release
zip -r ../func-deploy.zip azure-func-rust ../my-function/function.json ../my-function/host.json
# Deploy via Azure CLI
az functionapp deployment source config-zip --resource-group MyResourceGroup --name MyFunctionApp --src func-deploy.zip
Alternatively, if you prefer the WASM approach, you can use the wasm32-wasi target. This requires enabling the WASM worker extension in your Azure Function App settings. Compile with cargo build --target wasm32-wasi --release, then package the .wasm file similarly. The WASM route is often preferred for its smaller footprint and faster cold starts, but you must ensure your Azure Function App is configured to use the wasm worker runtime in the host.json or portal settings. Both methods require careful attention to the target triple to match the Azure Linux container environment.