Loading...
Loading...
Use when bootstrapping a new Rust monorepo workspace from commit 1 — when the project has more than one binary crate (e.g. an API server and a background worker), when shared types must be consumed by two or more members without duplicating code, or when a single-crate layout would force one binary to carry another's compile-time dependencies. Triggers — a team wants shared wire contracts between a backend service and a worker process; a shared infrastructure primitive crate must stay independent of both consumers; the Cargo.toml at the repository root has no `[workspace]` section yet. Not applicable for single-crate projects (see rust-project-setup).
npx skill4agent add forge-it/agent-skills rust-workspace-setupCargo.tomlusecore/worker/crates/uv workspacesuv.toml[workspace]membersmy-project/ ← workspace root (no src/, no bin/)
├── Cargo.toml ← [workspace] manifest only
├── rust-toolchain.toml ← toolchain pin (see rust-project-setup)
├── rustfmt.toml ← shared formatter config
├── core/ ← API/backend binary crate
│ └── Cargo.toml
├── worker/ ← async background-worker binary crate
│ └── Cargo.toml
└── crates/ ← shared library crates
├── task-contracts/ ← wire types shared by core ↔ worker
│ └── Cargo.toml
├── connectors-runtime/ ← probe/connectivity logic shared by core ↔ worker
│ └── Cargo.toml
└── kubernetes-primitives/ ← pure k8s manifest primitives (no service logic)
└── Cargo.tomlsrc/[lib][[bin]][workspace.dependencies]Cargo.toml# Workspace manifest. The root carries no source code — members live in
# core/, worker/, and crates/.
[workspace]
resolver = "2"
members = [
"core",
"worker",
"crates/task-contracts",
"crates/connectors-runtime",
"crates/kubernetes-primitives",
]
# ---------------------------------------------------------------------------
# Shared lint table — members opt in via `[lints] workspace = true`.
# ---------------------------------------------------------------------------
[workspace.lints.rust]
unsafe_code = "deny"
[workspace.lints.clippy]
all = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
# Adjust suppressions to your project's honest needs — do not silence
# diagnostics wholesale to keep the clippy section small.
missing_errors_doc = "allow"
missing_panics_doc = "allow"
type_complexity = "allow"
# ---------------------------------------------------------------------------
# Shared build profiles — Cargo silently ignores member-level profile tables.
# Move them here from member Cargo.toml files when adding workspace support.
# ---------------------------------------------------------------------------
[profile.release]
lto = true
codegen-units = 1
panic = "abort"
strip = true
[profile.dev]
debug = true
# ---------------------------------------------------------------------------
# Shared dependency versions — members reference these as
# `serde = { workspace = true }` or `serde = { workspace = true, features = ["derive"] }`.
# Declare only versions that are shared across two or more members.
# ---------------------------------------------------------------------------
[workspace.dependencies]
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
uuid = { version = "1", features = ["v7", "serde"] }
chrono = { version = "0.4", features = ["serde"] }
tracing = "0.1"
# Internal crates — declared here so members can reference them without
# repeating the path.
task-contracts = { path = "crates/task-contracts" }
connectors-runtime = { path = "crates/connectors-runtime" }
kubernetes-primitives = { path = "crates/kubernetes-primitives" }resolver = "2"stdno_std[profile.*]Cargo.tomlrust-toolchain.tomlcargo check[toolchain]
channel = "1.87.0"
components = ["rustfmt", "clippy"]rust-project-setuprustfmt.tomledition = "2024"
style_edition = "2024"Cargo.toml# crates/task-contracts/Cargo.toml
[package]
name = "task-contracts"
version = "0.1.0"
edition = "2024"
publish = false
description = "Shared wire contracts between the API backend and the worker: message DTOs and any shared enumerations."
[dependencies]
serde = { workspace = true }
serde_json = { workspace = true }
uuid = { workspace = true }
chrono = { workspace = true }
[lints]
workspace = truecore/worker/sqlxaxumkube# core/Cargo.toml
[package]
name = "my-project-core"
version = "0.1.0"
edition = "2024"
publish = false
description = "HTTP API and background scheduler for my-project."
[dependencies]
tokio = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
uuid = { workspace = true }
tracing = { workspace = true }
# Internal shared crates
task-contracts = { workspace = true }
connectors-runtime = { workspace = true }
kubernetes-primitives = { workspace = true }
# Backend-specific dependencies (not shared — declared locally)
axum = "0.8"
sqlx = { version = "0.8", features = ["runtime-tokio", "postgres", "uuid", "chrono", "migrate"] }
[features]
default = []
# Gate infrastructure-fixture tests in CI (no external cluster available).
ci = []
[lints]
workspace = true# worker/Cargo.toml
[package]
name = "my-project-worker"
version = "0.1.0"
edition = "2024"
publish = false
description = "Async background-task worker for my-project."
[dependencies]
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal", "sync", "time"] }
tracing = { workspace = true }
serde_json = { workspace = true }
# Internal shared crates — the worker never depends on core/.
task-contracts = { workspace = true }
connectors-runtime = { workspace = true }
[lints]
workspace = truecore/crates/crates/crates/crates/crates/[lints]
workspace = trueworkspace = true# 1. Take the version and all declared workspace features as-is:
serde = { workspace = true }
# 2. Take the version but add extra features on top:
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }[workspace.dependencies]features = ["full"]tokio# Check all members in one pass:
cargo check --workspace
# Run the full test suite across all members:
cargo test --workspace
# Lint all members:
cargo clippy --workspace -- -D warnings
# Format check:
cargo fmt --check--workspacecargo test --workspacecargo update[workspace.dependencies]core = { path = "../core" }[profile.*]crates/crates/core/features = ["full"][workspace.dependencies]| Task | Command |
|---|---|
| Check all members | |
| Test all members | |
| Lint all members | |
| Format all members | |
| Format check (CI) | |
| Build release | |
| Add a new member | Add path to |
| Add a shared dep | Add to |
cargo-makejustjustfile-setuprust-architecture-test-setuptests/structure/SourceTreeCARGO_MANIFEST_DIRjust checkcargo check --workspacetask-contracts