Rust Runtime
Build and run Rust applications on Witchly.host with Cargo. Git-integrated deployment, release-mode builds, and dedicated resources.
languages (12 articles)
On This Page
Rust Runtime
The Rust egg clones your repo and compiles with cargo run --release. Ideal for Discord bots (serenity, twilight), high-performance HTTP services (axum, actix-web), CLI daemons, and anything where you want Rust’s safety + performance.
Quick deploy
- dash.witchly.host → Deploy → Languages → rust generic.
- On the Startup tab, set
Git Repo Addressto your repo URL. - Start — the first boot will
cargo build --release(takes 5–20 minutes depending on crate count).
Startup flow
if [[ -d .git ]] && [[ {{AUTO_UPDATE}} == "1" ]]; then git pull; fi
cargo run --release
cargo run --release rebuilds incrementally if your code changed, then runs the resulting binary.
Variables reference
| Variable | Purpose |
|---|---|
GIT_ADDRESS | Git repo URL |
BRANCH | Git branch |
AUTO_UPDATE | 1 to git pull on each start |
USERNAME, ACCESS_TOKEN | Private repo credentials |
Speeding up builds
Rust builds can be slow on smaller plans. A few tricks:
Use a leaner profile in Cargo.toml:
[profile.release]
lto = false # Link-time optimization off → faster builds, slight runtime cost
codegen-units = 16 # More parallelism
debug = false
strip = true
Check if you actually need --release: for Discord bots and non-CPU-bound apps, cargo run (debug mode) builds 5–10× faster with acceptable runtime performance. Edit the startup command to drop --release if build time matters more than raw speed.
Pre-compile and upload. Build locally for Linux/x86_64 and upload just the binary — same trick as Go:
cargo build --release --target x86_64-unknown-linux-gnu
# upload target/x86_64-unknown-linux-gnu/release/mybot to /home/container/
chmod +x mybot
Then change the startup to ./mybot.
HTTP server with Axum
// src/main.rs
use axum::{routing::get, Router};
use std::{env, net::SocketAddr};
#[tokio::main]
async fn main() {
let port: u16 = env::var("SERVER_PORT").unwrap().parse().unwrap();
let app = Router::new().route("/", get(|| async { "Hello from Rust!" }));
let addr = SocketAddr::from(([0, 0, 0, 0], port));
axum::Server::bind(&addr).serve(app.into_make_service()).await.unwrap();
}
# Cargo.toml
[dependencies]
axum = "0.7"
tokio = { version = "1", features = ["full"] }
Discord bot with Serenity
// src/main.rs
use serenity::async_trait;
use serenity::model::channel::Message;
use serenity::prelude::*;
struct Handler;
#[async_trait]
impl EventHandler for Handler {
async fn message(&self, ctx: Context, msg: Message) {
if msg.content == "!ping" {
let _ = msg.channel_id.say(&ctx.http, "pong").await;
}
}
}
#[tokio::main]
async fn main() {
let token = std::env::var("DISCORD_TOKEN").expect("DISCORD_TOKEN");
let intents = GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT;
let mut client = Client::builder(&token, intents).event_handler(Handler).await.unwrap();
client.start().await.unwrap();
}
Memory use during build
cargo build --release can use 1–2 GB of RAM during linking, especially with LTO enabled. If your server OOMs mid-build, upgrade temporarily or disable LTO as shown above.
Troubleshooting
- Build runs out of disk — Rust’s
target/directory gets huge (hundreds of MB). Runcargo cleanperiodically from the Console tab. - “linker: /usr/bin/ld: cannot find -lssl” — add
openssl-devvia a post-install script or switch torustlsin your Cargo dependencies (no C deps). - Server crashes with SIGKILL — OOM during build or runtime; check memory usage.
Next steps
- Combine with MariaDB or Postgres via
sqlx - Go runtime for faster compiles, similar performance