Manage and Build Code

TopicTools
Build Systemcargo is the primary build system for Rust.
Build ScriptsUse build.rs files in your project.
Build ProfilesConfigure build options in Cargo.toml for debug, release, etc.
Cross-Compilationcross simplifies cross-compilation, target specifications in Cargo.toml.
Link-Time Optimization (LTO)Controlled via Cargo.toml.
Build DependenciesManaged by cargo
Incremental CompilationHandled by cargo.
Build Automation (for complex builds)xtask
Compiler FlagsConfigurable in Cargo.toml
Code GenerationOften done with procedural macros or build scripts.

Save and run project-specific Commands with the just Command Runner

just just-crates.io just-github just-lib.rs cat-development-tools cat-command-line-utilities

just is a command runner. It is a Rust-based equivalent to make without the ability to detect file changes, but with significantly fewer syntactic warts.

Consult the Just programmer's manual⮳.

Create a justfile

Place the following example justfile in the root folder of your project. Run just to see a list of recipes. Run just <recipe> to execute the corresponding recipe.

# Load a .env file, if present.
set dotenv-load

default:
 @just --list --unsorted

# Check a local package and all of its dependencies for errors
check:
 @cargo check

# Compile a local package and all of its dependencies
build: check
 @cargo build

# Run a binary or example of the local package
run: check
 @cargo run

system-info:
 @echo "This is an {{arch()}} machine".

# Shebang script example
foo:
  #!/usr/bin/env bash
  set -euxo pipefail
  hello='Yo'
  echo "$hello from Bash!"

Install just in a Dev Container

just

FROM mcr.microsoft.com/devcontainers/base:bullseye
# Or perhaps `mcr.microsoft.com/devcontainers/rust:bullseye` if you want Rust & `cargo`

SHELL ["bash", "-c"]

# Prerequisites to Install Just: https://just.systems/man/en
RUN <<EOF
 wget -qO - 'https://proget.makedeb.org/debian-feeds/prebuilt-mpr.pub' | gpg --dearmor | sudo tee /usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg 1> /dev/null
 echo "deb [arch=all,$(dpkg --print-architecture) signed-by=/usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg] https://proget.makedeb.org prebuilt-mpr $(lsb_release -cs)" | sudo tee /etc/apt/sources.list.d/prebuilt-mpr.list
 sudo apt update
EOF

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
  && apt-get -y install just \
  && apt-get autoremove -y && apt-get clean -y

For Alpine, use apk⮳:

RUN apk add just

Check Your Rust Code in the Background

bacon bacon-crates.io bacon-github bacon-lib.rs cat-development-tools cat-command-line-utilities

bacon is a background rust code checker. It is designed for minimal interaction, so that you can just let it run, alongside your editor, and be notified of warnings, errors, or test failures in your Rust code.

# Install or Update `bacon`
cargo install --locked bacon

# Check the current project
bacon

# Run `clippy` instead of `cargo check`
bacon clippy

Consider cargo-make if you want something with a bulkier syntax but more cross-platform portability.

See Building.