Home

Awesome

VSCode Cargo Runner

10X Rust Developer Tool to Run, Build, or Test without Mental Overhead

cover

Cargo Runner is a powerful and intuitive tool designed to streamline the development workflow for Rust programmers. It integrates seamlessly into your development environment, allowing you to execute essential tasks like running, building, and testing Rust projects with minimal effort and maximum efficiency.

Features

Demo Screenshot

Cargo Run

  1. Go Inside any files that can be run :

    • src/main.rs
    • src/bin/*
    • examples/*
    • any file declare as [[bin]] on Cargo.toml

e.g.

[[bin]] 
path = "src/example.rs"
name ="example"

Note: the file you wanna run must have a fn main block

  1. Press <kbd>CMD</kbd>+<kbd>R</kbd>

Run


Cargo Build

  1. Go to Any build.rs file that hasfn main block

  2. Press <kbd>CMD</kbd>+<kbd>R</kbd> on Cursor

Build


Cargo Test or Cargo Nextest (if installed) for specific test

  1. Go to any file with test block supports anykind of test macro e.g. #[test] or #[tokio::test]

  2. Place your cursor inside the test block you wanna run test

  3. Press <kbd>CMD</kbd>+<kbd>R</kbd>

Note: If Cargo Nextest is installed it would use that as default test runner instead of cargo test

Test

Debug Test

  1. Add a breakpoint to any test block

  2. Place your cursor inside the test block that have that breakpoint

  3. Press <kbd>CMD</kbd>+<kbd>R</kbd>

Run

Fallback Runner (using rust-analyzer) for running all test

  1. Place your cursor somewhere inside of a mod test block

  2. Press <kbd>CMD</kbd>+<kbd>R</kbd>

fallback

Fallback Runner (using rust-analyzer) for running doc-test

  1. Place your cursor somewhere inside a doc test block

  2. Press <kbd>CMD</kbd>+<kbd>R</kbd>

fallback

Adding Command Arguments

  1. Press <kbd>CMD</kbd>+<kbd>SHIFT</kbd>+<kbd>R</kbd>

  2. Choose context from any of the following options:

    • run
    • build
    • test
    • bench
    • env
  3. Type those parameters you wanna add to override the default

e.g. choose: env

  1. Type on the user input the args you wanna pass as override argument

e.g.

RUSTFLAGS="-Awarnings"

Note: .cargo_runner.toml would be created per create , you can have multiple .cargo_runner.toml on workspace

Important: You may wanna add this to .gitignore file

Removing Command Arguments

  1. Press <kbd>CMD</kbd>+<kbd>SHIFT</kbd>+<kbd>R</kbd>

  2. Choose context from any of the following options:

    • run
    • build
    • test
    • bench
    • env
  3. Press Enter (dont type anything)

This would remove the parameters RUSTFLAGS="-Awarnings" on .cargo_runner.toml file


Advanced Features

<details> <summary> Custom Build Scripts with Makefile.</summary>

Create a Makefile on Rust project, you can have multiple Makefile if your working with Cargo Workspace The choice is yours

Makefile

below is example makefile , you can add to you project to test

# Makefile for a Rust project using cargo-leptos and cargo-nextest

# Default target
.PHONY: all
all: build

# Build target
.PHONY: build
build:
	cargo build --package REPLACE_WITH_YOUR_PACKAGE_NAME

.PHONY: run
run:
	cargo run --package REPLACE_WITH_YOUR_PACKAGE_NAME --bin REPLACE_WITH_YOUR_BIN_NAME

# Test target
.PHONY: test
test:
	cargo test

# Clean up
.PHONY: clean
clean:
	cargo clean
</details>

License

Changelog


By providing a comprehensive and user-friendly tool, Cargo Runner aims to significantly enhance the productivity and efficiency of Rust developers.