Bot Uptime

How to Compile & Host a Rust Discord Bot (serenity / poise) on Linux x86_64

Rust is the undisputed king of ultra-lightweight Discord bots. While JavaScript and Python runtimes typically idle between 50 MB and 120 MB of RAM, a compiled Rust binary using serenity or poise often runs smoothly in just 4 MB to 15 MB of RAM with microsecond command response times and strict compile-time safety.

1. Why Compiling for Linux x86_64 (musl) Matters

Most developers write Rust code on Windows or macOS, which compiles a .exe or Mach-O binary that cannot run on Linux containers. Even compiling on a newer Ubuntu desktop can fail on minimal Linux containers if your binary dynamically links against a newer glibc version.

The cleanest production approach is building a static Linux x86_64 binary using the x86_64-unknown-linux-musl target and rustls-tls (instead of OpenSSL). The resulting single executable runs identically on virtually any Linux container with zero missing shared libraries.

Cargo.toml (TLS-safe dependencies)
[dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
serenity = { version = "0.12", default-features = false, features = [
  "client", "gateway", "rustls_backend", "model", "cache"
] }
poise = "0.6"

2. Build Automatically with GitHub Actions (Even from Windows)

You do not need a Linux PC or WSL to compile a Linux Rust binary. Push your code to GitHub and add a tiny GitHub Actions workflow that runs on ubuntu-latest, compiles your release binary with musl, and gives you a downloadable Linux artifact in about 2 minutes.

.github/workflows/release-linux.yml
name: Build Static Linux Bot
on:
  workflow_dispatch:
  push:
    branches: [main]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: x86_64-unknown-linux-musl
      - run: sudo apt-get update && sudo apt-get install -y musl-tools
      - run: cargo build --release --target x86_64-unknown-linux-musl
      - uses: actions/upload-artifact@v4
        with:
          name: discord-bot-linux
          path: target/x86_64-unknown-linux-musl/release/my-bot

3. Upload and Run Your Binary in Seconds

Create a Rust bot container in your dashboard, upload your compiled Linux binary named bot (or set BINARY_FILE in Startup Settings to your binary filename), create your .env file with DISCORD_TOKEN, and hit Start. The container automatically marks your binary executable (chmod +x) and launches it immediately — no slow compilation on the hosting node and instant sub-second restarts.

  • Add strip = true and lto = true under [profile.release] in Cargo.toml to shrink binary size by 60%+.
  • Prefer rustls over native-tls/openssl so you never hit libssl.so version mismatches.
  • Never upload Windows .exe binaries — Linux containers require ELF x86_64 executables.

Frequently Asked Questions

Why did my Rust binary exit with "Exec format error"?

You uploaded a Windows .exe or macOS ARM64 binary instead of a Linux x86_64 ELF binary. Compile using ubuntu-latest or WSL targeting x86_64-unknown-linux-musl.

Why does Bot Uptime use Rust for its own Ready-Made Bots?

Because compiled Rust binaries start in milliseconds, consume ~3–15 MB of RAM, never leak memory over weeks of uptime, and handle high guild traffic effortlessly.

Ready to deploy your bot 24/7?

Launch a custom Discord, Telegram, or WhatsApp container (Python, Node.js, Java, Rust) with Managed Databases and Free AI Agents — or deploy a ready-made Discord bot in 1 click on Bot Uptime.