Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cargo Processor

Purpose

Builds Rust projects using Cargo. Each Cargo.toml produces a cached success marker, allowing RSConstruct to skip rebuilds when source files haven’t changed.

How It Works

Discovers files named Cargo.toml in the project. For each Cargo.toml found, the processor runs cargo build (or a configured command) in that directory.

Input Tracking

The cargo processor tracks all .rs and .toml files in the Cargo.toml’s directory tree as inputs. This includes:

  • Cargo.toml and Cargo.lock
  • All Rust source files (src/**/*.rs)
  • Test files, examples, benches
  • Workspace member Cargo.toml files

When any tracked file changes, rsconstruct will re-run cargo.

Workspaces

For Cargo workspaces, each Cargo.toml (root and members) is discovered as a separate product. To build only the workspace root, use exclude_paths to skip member directories, or configure scan_dir to limit discovery.

Source Files

  • Input: Cargo.toml plus all .rs and .toml files in the project tree
  • Output: None (mass_generator — produces output in target directory)

Configuration

[processor.cargo]
cargo = "cargo"          # Cargo binary to use
command = "build"        # Cargo command (build, check, test, clippy, etc.)
args = []                # Extra arguments passed to cargo
profiles = ["dev", "release"]  # Cargo profiles to build
scan_dir = ""            # Directory to scan ("" = project root)
extensions = ["Cargo.toml"]
extra_inputs = []        # Additional files that trigger rebuilds
cache_output_dir = true  # Cache the target/ directory for fast restore after clean
KeyTypeDefaultDescription
cargostring"cargo"Path or name of the cargo binary
commandstring"build"Cargo subcommand to run
argsstring[][]Extra arguments passed to cargo
profilesstring[]["dev", "release"]Cargo profiles to build (creates one product per profile)
scan_dirstring""Directory to scan for Cargo.toml files
extensionsstring[]["Cargo.toml"]File names to match
exclude_dirsstring[]["/.git/", "/target/", ...]Directory patterns to exclude
exclude_pathsstring[][]Paths (relative to project root) to exclude
extra_inputsstring[][]Extra files whose changes trigger rebuilds
cache_output_dirbooleantrueCache the target/ directory so rsconstruct clean && rsconstruct build restores from cache. Consider disabling for large projects.

Examples

Basic Usage

[processor.cargo]

Release Only

[processor.cargo]
profiles = ["release"]

Dev Only

[processor.cargo]
profiles = ["dev"]

Use cargo check Instead of build

[processor.cargo]
command = "check"

Run clippy

[processor.cargo]
command = "clippy"
args = ["--", "-D", "warnings"]

Workspace Root Only

[processor.cargo]
exclude_paths = ["crates/"]

Notes

  • Cargo has its own incremental compilation, so rsconstruct’s caching mainly avoids invoking cargo at all when nothing changed
  • The target/ directory is automatically excluded from input scanning
  • For monorepos with multiple Rust projects, each Cargo.toml is built separately