# Deploy Rust on forkrail

> Cross-compile Axum, Actix-web, or Vercel `vercel_runtime` `[[bin]]` targets to native Linux arm64 with `cargo zigbuild --release`, cached Cargo registries, and sub-50 ms cold starts.

- Framework: Rust
- Category: APIs & backends
- Status: Production ready
- Adapter / Preset: None (Axum/Actix on PORT, or vercel_runtime [[bin]])
- Runtime: AWS Lambda provided.al2023 (aarch64 glibc 2.34)
- Detection: Cargo.toml ([[bin]] or server crate)
- Memory: 256–640 MB
- URL: https://www.forkrail.com/frameworks/rust

## Capabilities

| Capability | Support | Details |
| --- | --- | --- |
| Axum / Actix / Tokio | Supported | Any Rust HTTP server listening on process PORT |
| Vercel api/ binaries | Supported | Cargo [[bin]] endpoints with vercel_runtime unchanged |
| Cached cargo builds | Supported | Cargo registry and target/ persisted across deployments |
| Native arm64 speed | Supported | Compiled with cargo zigbuild --release for Amazon Linux 2023 |

## 1. Web server or vercel_runtime [[bin]]

Deploy a standard Rust HTTP server (such as Axum or Actix-web) listening on `PORT`, or keep Vercel’s `api/*.rs` `[[bin]]` layout using the `vercel_runtime` crate (forkrail passes `VERCEL_DEV_PORT` automatically):

**src/main.rs (Axum)**

```rust
use axum::{routing::get, Json, Router};
use serde_json::json;

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/health", get(|| async { Json(json!({ "ok": true })) }));

    let port = std::env::var("PORT").unwrap_or_else(|_| "8080".into());
    let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{port}")).await.unwrap();
    axum::serve(listener, app).await.unwrap();
}
```

**Cargo.toml (api/ bins)**

```toml
[package]
name = "rust-api"
version = "0.1.0"
edition = "2024"

[[bin]]
name = "hello"
path = "api/hello.rs"

[dependencies]
vercel_runtime = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
```

## 2. Deploy & cache builds

forkrail compiles releases with `cargo zigbuild --release` targeting Amazon Linux 2023’s glibc 2.34 (`aarch64-unknown-linux-gnu.2.34`) and caches both the Cargo registry and `target/` directory so incremental deploys stay fast.

**Deploy Rust service**

```bash
forkrail deploy
forkrail deploy --prod
```

## Related documentation

- [Functions in api/](https://www.forkrail.com/docs/functions.md)
- [Concurrent compute](https://www.forkrail.com/docs/concurrent-compute.md)
- [Spend budgets](https://www.forkrail.com/docs/spend-budgets.md)
