mohitmishra786/low-level-dev-skills / skills/rust/cargo-workflows
cargo-workflows
VerifiedCargo workflow skill for Rust projects. Use when managing workspaces, feature flags, build scripts, cargo cache, incremental builds, dependency auditing, or CI configuration with Cargo. Activates on queries about cargo workspaces, Cargo.toml features, build.rs, cargo nextest, cargo deny, cargo check vs build, or Cargo.lock management.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 10.3 KB |
| references/workspace-patterns.md | markdown | 4.2 KB |
references/workspace-patterns.md
View on GitHub# Cargo Workspace Patterns Reference
## Workspace Dependency Management
### Centralizing versions
```toml
# Root Cargo.toml
[workspace.dependencies]
# Pin all workspace members to same versions
tokio = { version = "1.35", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
tracing = "0.1"
anyhow = "1.0"
thiserror = "1.0"
[workspace.package]
version = "0.1.0"
edition = "2024"
authors = ["team@example.com"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/org/repo"
```
```toml
# Member Cargo.toml
[package]
name = "myapp-core"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
[dependencies]
tokio.workspace = true # Inherit, including features
serde = { workspace = true, features = ["derive"] } # Can add features
```
## Feature Resolution (resolver = "2")
With `resolver = "2"` or later (`"3"` is the edition 2024 default):
```toml
[workspace]
resolver = "3"
```
- Build deps, dev-deps, and regular deps get independent feature resolution
- Prevents a dev-only dependency from enabling features in prod builds
- `target.cfg()` conditional features respected independently
- `"3"` (Rust 1.84+) also prefers dependency versions whose `rust-version` fits your MSRV
A virtual workspace (no root `[package]`) does not infer the resolver from member editions.
Without an explicit `resolver`, cargo warns and falls back to `"1"`.
## Virtual Manifest Pattern
A workspace without its own `[package]` — just orchestrates members:
```toml
# Root Cargo.toml (virtual manifest)
[workspace]
members = ["crates/*", "tools/*"]
resolver = "3" # required: virtual manifests default to "1"
[workspace.package]
version = "0.1.0"
edition = "2024"
[profile.release]
lto = "thin"
```
Useful for monorepos where the root is not a published crate.
## Path vs Registry Dependencies
```toml
[dependencies]
# Path (local development)
mylib = { path = "../mylib" }
# Registry (published)
mylib = { version = "1.0" }
# Git (unpublished / fork)
mylib = { git = "https://github.com/user/mylib", branch = "main" }
mylib = { git = "https://github.com/user/mylib", rev = "abc1234" }
# Override registry dep with local path (for development)
# In root Cargo.toml:
[patch.crates-io]
serde = { path = "../my-serde-fork" }
```
## Selective Build Commands
```bash
# Build only specific workspace member
cargo build -p myapp-core
cargo build -p myapp-cli --release
# Test specific member
cargo test -p myapp-core
# Test all members
cargo test --workspace
# Build all members
cargo build --workspace
# Exclude member
cargo build --workspace --exclude myapp-codegen
```
## Cargo.lock Management
```bash
# Libraries: Cargo.lock in .gitignore (let users choose versions)
# Applications: Cargo.lock in version control (reproducible builds)
# Generate deterministic lock file
cargo generate-lockfile
# Update single dep
cargo update -p tokio --precise 1.35.1
# Show what would change
cargo update --dry-run
```
## CI Configuration Patterns
### GitHub Actions matrix
```yaml
strategy:
matrix:
rust: [stable, beta, nightly]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- run: cargo check --workspace --all-features
- run: cargo test --workspace
- run: cargo clippy --workspace -- -D warnings
- run: cargo fmt --check
```
### MSRV (minimum supported Rust version)
```toml
[package]
rust-version = "1.85" # MSRV declaration (edition 2024 needs 1.85+)
[workspace.package]
rust-version = "1.85"
```
```bash
# Test against MSRV
rustup install 1.85
cargo +1.85 check --workspace
```
## Published Crate Checklist
```toml
[package]
name = "mycrate"
version = "1.0.0"
edition = "2024"
description = "Short description"
license = "MIT OR Apache-2.0"
repository = "https://github.com/..."
documentation = "https://docs.rs/mycrate"
readme = "README.md"
keywords = ["systems", "async"]
categories = ["network-programming"]
exclude = ["tests/fixtures/**", ".github/**"]
```
```bash
# Verify what will be published
cargo package --list
# Dry run publish
cargo publish --dry-run
# Publish to crates.io
cargo publish
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |