cargo-run
A powerful, fast, and developer-friendly CLI tool for managing project scripts in Rust
Thinknpm scripts,make, orjust— but built specifically for the Rust ecosystem with modern CLI best practices.
Why cargo-run?
Stop writing one-off shell scripts. cargo-run provides a unified, type-safe way to manage all your project automation:
- ✅ Zero runtime dependencies — Single binary, fast startup
- ✅ Cross-platform — Works on Windows, macOS, and Linux
- ✅ Modern CLI UX — Shell completions, dry-run mode, helpful errors
- ✅ Powerful features — Script chaining, environment variables, toolchain support
- ✅ CI/CD ready — Validation command catches errors early
- ✅ Rust-native — Built with Rust, for Rust projects
Quick Comparison
| Feature | cargo-run |
make |
just |
npm scripts |
|---|---|---|---|---|
| Zero dependencies | ✅ | ✅ | ✅ | ❌ (Node.js) |
| Shell completions | ✅ | ⚠️ | ✅ | ✅ |
| Dry-run mode | ✅ | ❌ | ✅ | ❌ |
| Validation | ✅ | ❌ | ⚠️ | ❌ |
| Toolchain support | ✅ | ❌ | ❌ | ❌ |
| Environment precedence | ✅ | ⚠️ | ⚠️ | ✅ |
📦 Installation
After installation, you'll have multiple ways to invoke the tool:
cargo script— Recommended: Use as a Cargo subcommand (e.g.,cargo script run build)cargo-script— Direct binary invocationcgs— Short alias (used in examples below for brevity)
Note: When installed via cargo install, the cargo-script binary is automatically available in your PATH, enabling cargo script subcommand usage.
⚡ Quick Start
-
Initialize a
Scripts.tomlfile:# Using Cargo subcommand (recommended) # Or using direct binary -
Run a script:
# Using Cargo subcommand # Or using direct binary -
Preview what would run (dry-run):
-
Validate your configuration:
-
Show all available scripts:
That's it! You're ready to go. 🎉
💡 Tip: Using
cargo scriptintegrates seamlessly with Cargo's ecosystem and provides a familiar interface for Rust developers.
📚 Features
Core Features
- Script Execution — Run scripts defined in
Scripts.toml - Script Chaining — Compose complex workflows with
include - Environment Variables — Global, script-specific, and command-line overrides
- Multiple Interpreters — bash, zsh, PowerShell, cmd, or custom
- Toolchain Support — Rust toolchains via rustup, Python versions
- Requirements Checking — Validate tool versions before execution
Developer Experience
- Shell Completions — Tab completion for bash, zsh, fish, and PowerShell
- Dry-Run Mode — Preview execution without side effects
- Helpful Errors — Actionable error messages with suggestions
- Validation — Catch configuration errors early
- Performance Metrics — Track script execution times
📖 Usage Guide
Initialize Scripts.toml
Create a new Scripts.toml file with sensible defaults:
# Using Cargo subcommand (recommended)
# Or using direct binary
This creates a Scripts.toml file with:
[]
[]
= "cargo run"
= { = "cargo build", = { = "info" } }
= "cargo build --release"
= { = "cargo test", = { = "warn" } }
= "cargo doc --no-deps --open"
Run Scripts
# Using Cargo subcommand (recommended)
# Simple script
# With environment variable override
# Preview execution (dry-run)
Script Configuration
Simple Script
[]
= "cargo build"
Script with Metadata
[]
= {
command = "cargo build",
= "Build the project in release mode",
= { = "info" }
}
Script with Interpreter
[]
= {
interpreter = "bash",
= "./scripts/deploy.sh",
= "Deploy to production"
}
Script Chaining (Includes)
[]
= "cargo clean"
= "cargo doc --no-deps"
= "cargo publish --dry-run"
= "cargo package --list"
= {
include = ["prepublish_clean", "prepublish_doc", "prepublish_dry", "prepublish_check"],
= "Run all prepublish checks"
}
Script with Requirements
[]
= {
command = "./deploy.sh",
= ["docker >= 19.03", "kubectl >= 1.18"],
= "stable",
= "Deploy application"
}
CI/CD-like Format
[]
= "build"
= "cargo build"
= "Build the project"
[]
= "test"
= "cargo test"
= ["rustup >= 1.70"]
= "stable"
Environment Variables
Global Environment Variables
[]
= "1"
= "info"
Script-Specific Environment Variables
[]
= {
command = "cargo test",
= { = "debug" }
}
Command-Line Overrides
# Using Cargo subcommand
# Or using direct binary
Precedence Order:
- Command-line overrides (
--env) - Script-specific (
envin script) - Global (
[global_env])
Show All Scripts
# Using Cargo subcommand (recommended)
# Or using direct binary
Output:
📋 Available Scripts:
• build - Build the project
• test - Run tests
• release - Build release version
• prepublish - Run all prepublish checks
Dry-Run Mode
Preview what would be executed without actually running it:
# Using Cargo subcommand (recommended)
# Or using direct binary
Output:
DRY-RUN MODE: Preview of what would be executed
================================================================================
📋 Would run script: [ prepublish ]
Description: Run all prepublish checks
Would run include scripts:
📋 Would run script: [ prepublish_clean ]
Command: cargo clean
📋 Would run script: [ prepublish_doc ]
Command: cargo doc --no-deps
📋 Would run script: [ prepublish_dry ]
Command: cargo publish --dry-run
📋 Would run script: [ prepublish_check ]
Command: cargo package --list
No commands were actually executed.
Shell Completions
Enable tab completion for a better developer experience:
Bash:
# Using Cargo subcommand (recommended)
# Or system-wide:
|
# Or using direct binary
Zsh:
# Using Cargo subcommand (recommended)
# Or using direct binary
# Add to ~/.zshrc:
fpath=(/.zsh/completions )
&&
Fish:
# Using Cargo subcommand (recommended)
# Or using direct binary
PowerShell:
# Using Cargo subcommand (recommended)
cargo script completions power-shell > $PROFILE
# Or using direct binary
cgs completions power-shell > completions.ps1
. .\completions.ps1
After installation, restart your shell and enjoy tab completion! 🎉
Validation
Catch configuration errors before they cause problems:
# Using Cargo subcommand (recommended)
# Or using direct binary
What it checks:
- ✅ TOML syntax validity
- ✅ Script references in
includearrays - ✅ Tool requirements (checks if tools are installed)
- ✅ Toolchain requirements (checks if Rust/Python toolchains are installed)
Example output:
✓ All validations passed!
With errors:
❌ Validation Errors:
1. Script 'release': Script 'release' references non-existent script 'build'
2. Script 'deploy': Required tool 'docker' is not installed or not in PATH
✗ Found 2 error(s)
CI/CD Integration:
# .github/workflows/ci.yml
- name: Validate Scripts.toml
run: cargo script validate
Error Messages
cargo-run provides helpful, actionable error messages:
Script Not Found:
Invalid TOML:
Missing Tool:
Use Cases
Development Workflow
[]
= "cargo run"
= "cargo test"
= { = "cargo watch -x test", = ["cargo-watch"] }
= "cargo clippy -- -D warnings"
= "cargo fmt --check"
= { = ["fmt", "lint", "test"], = "Run all checks" }
CI/CD Pipeline
[]
= {
include = ["check", "test", "build"],
= "Run CI pipeline"
}
[]
= "cargo clippy -- -D warnings"
[]
= "cargo test --all-features"
[]
= "cargo build --release"
Multi-Language Projects
[]
= "cargo build"
= {
command = "python setup.py build",
= ["python >= 3.8"],
= "python:3.8"
}
= { = ["build-rust", "build-python"] }
Deployment Scripts
[]
= {
command = "./scripts/deploy.sh staging",
= ["docker >= 19.03", "kubectl >= 1.18"],
= { = "staging" }
}
= {
command = "./scripts/deploy.sh production",
= ["docker >= 19.03", "kubectl >= 1.18"],
= { = "production" }
}
🔧 Advanced Configuration
Custom Scripts Path
Use a different Scripts.toml file:
# Using Cargo subcommand
# Or using direct binary
Performance Metrics
Script execution times are automatically tracked and displayed:
Scripts Performance
--------------------------------------------------------------------------------
✔️ Script: prepublish_clean 🕒 Running time: 1.23s
✔️ Script: prepublish_doc 🕒 Running time: 3.45s
✔️ Script: prepublish_dry 🕒 Running time: 2.10s
🕒 Total running time: 6.78s
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
This project is licensed under the MIT License.
🙏 Acknowledgments
- Inspired by
npm scripts,make, andjust - Built with clap for excellent CLI experience
- Uses colored for beautiful terminal output
Made with ❤️ for the Rust community