Cargo Build System

Rust Enhanced has a custom build system tailored for running Cargo. It will display errors and warnings inline using Sublime's phantoms (see Diagnostic Messages for settings to control how messages are displayed). It also supports a variety of configuration options to control how Cargo is run.

testingrust

Usage

When Sublime is set to use "Automatic" build system detection, it will choose the build system based on the syntax of the currently active view. When you have a file open with the .rs extension, Sublime will automatically select the Rust Enhanced syntax highlighting, and the Automatic build system will pick Rust Enhanced to perform the build. If you want to ensure the Rust Enhanced build system is used regardless of which file is open, choose it via Tools > Build System > RustEnhanced.

The basic Sublime commands available are:

CommandKeyboardMenuDescription
BuildCtrl-B / ⌘-BTools > BuildRuns the currently active build variant.
Build With...Ctrl-Shift-B / ⌘-Shift-BTools > Build With...Choose the build variant.
Cancel BuildCtrl-Break / Ctrl-CTools > Cancel BuildAbort the currently running build.
Show Build ResultsTools > Build Results > Show Build ResultsOpens the output panel with build results.
Next ResultF4Tools > Build Results > Next ResultGo to the next warning/error message.
Previous ResultShift-F4Tools > Build Results > Previous ResultGo to the previous warning/error message.

See the Build Settings chapter for information on customizing how the build commands are run.

Build Variants

When you select the RustEnhanced build system in Sublime, there are a few variants that you can select with Tools > Build With... (Ctrl-Shift-B / ⌘-Shift-B). They are:

VariantCommandDescription
(Default)cargo buildBuilds the project.
AutomaticAutomatically detect the command to run based on the currently active view (tests do test, binaries and examples do run, libraries do build, benches do bench).
Runcargo runRuns the binary.
Run (with args)...cargo run -⁠-⁠ argsRuns the binary with optional arguments you specify.
Testcargo testRuns unit and integration tests.
Test (with args)...cargo test -⁠-⁠ argsRuns the test with optional arguments you specify.
Benchcargo benchRuns benchmarks.
Cleancargo cleanRemoves all built files.
Documentcargo docBuilds package documentation.
Clippycargo clippyRuns Clippy. Clippy must be installed, and currently requires the nightly toolchain.
Scriptcargo script $pathRuns Cargo Script. Cargo Script must be installed. This is an addon that allows you to run a Rust source file like a script (without a Cargo.toml manifest).

You can add custom build variants, see Custom Build Variants for more.

Multiple Cargo Projects (Advanced)

You can have multiple Cargo projects in a single Sublime project (such as when using Cargo workspaces, or if you simply have multiple projects in different folders).

If you have multiple Cargo projects in your Sublime window, the build system will use the currently active view to attempt to determine which project to build. Otherwise it will show an input panel to select a package.

You can set the default_path setting to always use a specific path. It is specified at the same level as paths (see Build Settings). This can be set using the Rust: Configure Cargo Build command.