Docs menu

Getting started with Rust

Deploy a minimal Rust web app to Primcloud end-to-end from a repo you create, in about ten minutes.

On this page

This guide walks through deploying a small Rust web app to Primcloud. You'll create a minimal app, push it to a repo, import it, watch the build, and reach the deployed app at a *.primcloud.app URL. Takes about ten minutes.

Before you start#

You'll need:

  • A Primcloud account. Standard accounts are free to create; compute is metered by the minute once you deploy, from around $5/mo for the smallest app.
  • A git provider connected to your account with access to at least one repo.
  • A current stable Rust toolchain installed locally, to create the app and its Cargo.lock.

The sample app#

Create a new binary package:

Terminal
cargo new rust-hello-world
cd rust-hello-world

Replace src/main.rs with a small HTTP server that listens on the port Primcloud assigns. This one uses only the standard library:

src/main.rs
use std::env;
use std::io::{Read, Write};
use std::net::TcpListener;

const BODY: &str = "Hello World!";

fn main() {
    let port = env::var("PORT").unwrap_or_else(|_| "8080".into());
    let listener = TcpListener::bind(format!("0.0.0.0:{port}")).expect("bind to $PORT");
    println!("Listening on port {port}");

    for stream in listener.incoming() {
        let Ok(mut stream) = stream else { continue };
        let _ = stream.read(&mut [0; 1024]);
        let _ = write!(
            stream,
            "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{BODY}",
            BODY.len()
        );
    }
}

Build it once so Cargo writes Cargo.lock, then commit and push to a repo your connected provider can see:

Terminal
cargo build
git add Cargo.toml Cargo.lock src
git commit -m "hello world"

The repo now holds the files a Rust app on Primcloud relies on:

  • A Cargo.toml at the root, which marks the repo as a Rust app.
  • A Cargo.lock. With it committed, the build compiles the exact dependency versions you built locally.

1. Create the application#

From the Primcloud dashboard, hit Import Git Repository on the applications list. The import wizard walks you through three quick steps:

  1. Pick a repository: select the repo you just pushed.
  2. Configure the deployment:
    • Branch: the branch you pushed to.
    • Region: US East (NYC).
  3. Review and create: Primcloud auto-provisions the app's primary *.primcloud.app subdomain on the production environment.

2. Deploy#

The first deployment kicks off automatically when the app is created. Watch it stream in the Deployments tab:

  • Detection. Primcloud sees the Cargo.toml at the repo root and picks the Rust toolchain.
  • Toolchain. With no rust-toolchain file in the repo, the current stable Rust release is installed.
  • Build. cargo build --release compiles every binary in the package; here, a single binary named rust-hello-world. Because Cargo.lock is committed, the build runs with --locked.
  • Release. With no Procfile, the binary gets a process named after it and is also the web process, which Primcloud starts on the pod formation.

The first build compiles everything from scratch. Later deploys reuse the cached toolchain, dependencies, and compiled artifacts.

When the deployment status flips to Release Succeeded, the app is live.

3. Reach the app#

The application dashboard shows the assigned *.primcloud.app URL in the header. Click it, and the app answers Hello World!.

If it doesn't come up:

  • Deployments: the build log has the raw output from cargo build.
  • Logs: runtime output from your app streams there, including any startup errors.
  • Confirm the app binds to 0.0.0.0 on the port in $PORT. Primcloud sets this to the constant 5000 on the web formation; the sample reads it with env::var("PORT").

Where to go next#