Deploy a Rust Web App with Rocket


You can use Render to host a Rust web application built with Rocket in just a few clicks.

The app in this guide is based on Rocket’s Hello World example and available on https://rocket-rust.onrender.com.

  1. Fork render-examples/rocket-rust-hello-world on GitHub. This is the content of the app we’re deploying:

    #![feature(proc_macro_hygiene, decl_macro)]
    
    #[macro_use] extern crate rocket;
    
    #[cfg(test)] mod tests;
    
    #[get("/")]
    fn hello() -> &'static str {
       "Hello, world!"
    }
    
    fn main() {
       rocket::ignite().mount("/", routes![hello]).launch();
    }
  2. Create a new Web Service on Render, and give Render permission to access your new repo.
  3. Use the following values during creation:

    EnvironmentRust
    Build Commandcargo build --release
    Start Commandcargo run --release

That’s it! Your web service will be live on your Render URL as soon as the build finishes.

Going forward, every push to your repo will automatically build your app and deploy it in production. If the build fails, Render will automatically stop the deploy process and the existing version of your app will keep running until the next successful deploy.

Specifying Rust toolchains

By default, Render uses the latest stable Rust toolchain, but you can specify a different toolchain by adding a file called rust-toolchain at the root of your repo. It should contain a single line specifying the version. For example:

nightly-06-01-2019

or

beta

Render will automatically install the toolchain specified in this file and use it for your app.

You can also use the RUST_TOOLCHAIN environment variable, which takes precedence over toolchain files.

If you override the toolchain in your build command with cargo +nightly ..., the specified toolchain must already be installed. You can install new toolchains using rustup as part of your build command.

Learn more about specifying a Rust toolchain.