Cargo Best Practices
Reproducible, fast, well-organized Cargo workflows keep Rust teams shipping without dependency surprises or slow feedback loops.
Busca en todas las páginas de la documentación
Reproducible, fast, well-organized Cargo workflows keep Rust teams shipping without dependency surprises or slow feedback loops.
Cargo.toml, build.rs, profiles).Cargo.lock; libraries document lock policy. Reproducible CI and deploys for services.[workspace.dependencies].crates/ layout for growing monorepos. Clear boundaries between API, domain, and CLI.edition = "2024" and rust-version consistently. MSRV documented in README and CI.target/ and artifacts out of git. Use .gitignore and Docker layer caching instead.[workspace.dependencies] once. Members use workspace = true to avoid drift.default-features when trimming compile time. Opt in explicitly per crate.cargo audit (or cargo deny) on a schedule. Security advisories caught early.cargo tree -d after major upgrades. Duplicate majors inflate build time.rev. Floating branches break reproducibility.--no-default-features and --all-features in CI. Optional code paths do not rot.lto = "thin" and tuned codegen-units. Measure before fat LTO in CI.cargo build --features ... lines.release-fast) for local perf iteration. Do not weaken production profile.build.rs lists rerun-if-changed for all inputs. No stale codegen after proto/config edits.cargo check / clippy in watch loops over full build. Faster developer feedback.cargo-nextest for large workspaces. Better parallelism and CI reporting.cargo expand when debugging proc macros. Pair with Debugging Macros.target/ in CI. sccache or GitHub Actions cache for Rust projects.cargo publish --dry-run before every release. Tarball contents and metadata validated.license field. MIT OR Apache-2.0 dual license is standard.all-features when safe. package.metadata.docs.rs configured.cargo fmt --check, cargo clippy --workspace -- -D warnings, cargo test --workspace, optional cargo audit.
Virtual workspace is fine; set default-members for cargo run ergonomics.
Split hot crates, reduce features, use linker mold, and cache dependencies in CI.
Yes at workspace root for applications; libraries published to crates.io often omit member locks except the workspace root policy you document.
Only for codegen, native linking, or cfg discovery. Do not use it for tasks better handled by xtask or CI scripts.
rust-version in manifest plus cargo +1.97.0 check job in CI matrix.
cargo vendor for air-gapped or policy-constrained environments; adds maintenance overhead.
Dedicated upgrade PR with changelog review, cargo test --workspace, and possible API shim crate.
[patch.crates-io] for temporary forks only; remove when upstream releases fix.
README with cargo run, feature flags, and env vars; link to .cargo/config.toml if non-default.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Revisado por Chris St. John·Última actualización: 16 jul 2026