Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Cargo Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-cargo-knowledge-patch-nevaberry-plugins)
---
name: cargo-knowledge-patch
description: Cargo
version: "1.97.0"
license: MIT
metadata:
author: Nevaberry
---
# Cargo Knowledge Patch
Load this skill when updating Cargo commands, manifests, or configuration;
working with workspaces, packages, and registries; or using Cargo's build
scripts, diagnostics, and structured tooling.
Use the topic references for complete guidance and release-specific behavior.
## Reference index
| Reference | Topics |
| --- | --- |
| [Build configuration and artifacts](references/build-configuration-and-artifacts.md) | Configuration merging and includes, compiler flags, targets, build directories, caches, profiles, warnings |
| [Commands, workspaces, and dependencies](references/commands-workspaces-and-dependencies.md) | Manifest selection, automatic fixes, features, trees, lockfiles, cleaning, tests, installation, completion |
| [Nightly and structured tooling](references/nightly-and-structured-tooling.md) | Removed options, timings, build analysis, documentation, metadata, SBOMs, lints, unstable builds, terminal output, library APIs |
| [Packaging, publishing, and registries](references/packaging-publishing-and-registries.md) | Workspace publication, archive contents, VCS checks, vendoring, credentials, Git, SSH, HTTP, registry index and API contracts |
| [Scripts, build scripts, and environment](references/scripts-build-scripts-and-environment.md) | Build script inputs and metadata, compiler environment, test paths, embedded manifests, script editions and directories |
## Removed options and deprecations
- Replace the removed unstable `--out-dir` with `--artifact-dir` to copy
final build artifacts to a chosen directory.
- Cargo removed `--timings=<FMT>`. Use `cargo build --timings` for an HTML
report of the current build, or nightly `-Zbuild-analysis` logs for
machine-readable timing data.
- Nightly Cargo removed `cargo build --build-plan`.
- The removed `--lockfile-path` CLI option is replaced by
`resolver.lockfile-path` in Cargo configuration. This setting works on
stable Cargo 1.97; drop `-Zlockfile-path` when using it.
- `cargo publish --token` is soft-deprecated. Use a registry credential
provider, such as `cargo:token` with `CARGO_REGISTRY_TOKEN` for crates.io.
- Cargo warns about `edition` in target tables such as `[[bin]]`.
Set it under `[package]`.
- Cargo warns when `install.root` is relative without a trailing slash.
This form currently resolves against the working directory and is slated
to become config-relative.
```console
cargo +nightly build -Zunstable-options --artifact-dir dist
```
With `-Zpublic-dependency`, `--edges public` replaces `--depth public`:
```console
cargo +nightly -Zpublic-dependency tree --edges public
```
## Configuration merging and includes
Higher-priority configuration replaces the entire program path and argument
list for `registry.credential-provider`, `registries.*.credential-provider`,
`target.*.runner`, `host.runner`, `credential-alias.*`, and `doc.browser`.
For config lists replaced as a unit, `--config` takes precedence over
environment variables; nested lists of this kind also replace as a unit.
The top-level `include` key works on stable Cargo. Drop `-Zconfig-include`.
Use an array instead of the removed single-string shorthand. Include paths
must be literal, end in `.toml`, and resolve relative to the including file.
Nested includes are recursive; later array entries win, then the including
file's own settings merge last.
```toml
include = ["common.toml"]
```
Cargo 1.97 resolves relative `[env]` paths against the file defining the value
when configuration is merged through `include`, and normalizes `..` in included
configuration paths. Config-relative paths in `--config <path>` files instead
resolve from the directory two levels above the file.
Set `CARGO_HOME`, `RUSTUP_HOME`, and `RUSTUP_TOOLCHAIN` in the invoking
environment; Cargo rejects them in its `[env]` table.
## Build outputs, cache cleanup, and warnings
`build.build-dir` works on stable Cargo. Its internal layout may change
between releases. `{workspace-root}` expands to the workspace root;
`{cargo-cache-home}` expands to `CARGO_HOME`.
```toml
[build]
build-dir = "{cargo-cache-home}/build/{workspace-path-hash}"
```
Cargo 1.100 uses a new intermediate layout by default, grouping files by build
step with the build-configuration hash in the parent directory name. Scripts
and tests reading build-directory files directly may need path updates.
Global cache cleanup removes network downloads after three months without
access and locally obtained files after one month without access. Cleanup is
skipped with `--offline` or `--frozen`. Only Cargo 1.78 and newer record the
accesses used for cleanup; set `cache.auto-clean-frequency` to `"never"` to keep
entries accessed only by older versions from expiring.
`build.warnings` works on stable Cargo 1.97 and defaults to `warn`.
Use `CARGO_BUILD_WARNINGS` to set the policy for a single invocation.
```console
CARGO_BUILD_WARNINGS=deny cargo check
```
## Workspace commands and dependency selection
Use `-m` as shorthand for `--manifest-path`. Combining `--workspace` with
`--package` errors if a named package is missing.
`cargo fix` and `cargo clippy --fix` select the same default targets as
`cargo check`; use `--all-targets` to fix all targets. `--edition` and
`--edition-idioms` still imply `--all-targets`. `cargo fix --allow-dirty`
also permits staged changes.
```console
cargo tree --depth workspace
cargo clean --workspace
cargo build --target host-tuple
```
These commands respectively show dependencies that are workspace members,
remove artifacts for workspace members only, and select the host target triple.
`cargo clean --target-dir` requires an existing selected directory to look like
a Cargo target directory; a nonexistent selected directory is a successful
no-op. Cleaning also honors `build.target`.
Cargo 1.100 enables `cargo::unused_dependencies` at `warn` on stable,
configurable in `[lints.cargo]`. Warnings require a build covering every target
that could use the dependency. `cargo check --bin foo` can miss unused
`[dependencies]` in a multi-binary package; `[dev-dependencies]` are skipped.
## Packaging, publishing, and registry selection
Cargo can publish multiple workspace members, including members that depend
on one another. Uploads are separate, so a server error can leave some
members published.
```console
cargo publish --workspace
cargo publish -p foo -p bar
```
`cargo package` always includes `Cargo.lock`, including for library packages.
`cargo package --exclude-lockfile` skips verification of an existing lockfile.
Use `cargo package` to keep the `.crate` archive as a final artifact;
`cargo publish` treats it as an intermediate artifact.
`cargo info` prefers a matching local package when no registry is specified.
Pass `--registry crates-io` to inspect the crates.io entry explicitly.
A dependency can use Git locally and a named registry in its published
manifest; include a version requirement for that registry dependency.
Cargo 1.100 can defer recently published versions using
`registry.global-min-publish-age`. The cooldown applies only to versions whose
index entries contain `pubtime`. `cargo install` bypasses it for both the
installed crate and its dependencies. Override it for a precise update:
```console
CARGO_RESOLVER_INCOMPATIBLE_PUBLISH_AGE=allow cargo update clap --precise 4.6.9
```
The selected version stays in `Cargo.lock` until an update re-resolves it.
## Lockfile compatibility and relocation
Cargo 1.78 can read lockfile v4; Cargo 1.83 makes it the default for creation
and updates. For a pre-1.78 toolchain, set `package.rust-version` to the actual
MSRV so Cargo can select a compatible format for new lockfiles.
`resolver.lockfile-path` must end with `Cargo.lock` and can keep the lockfile
outside a read-only source tree. With nightly `-Zlockfile-path`, `cargo install`
honored the setting in Cargo 1.95 but ignores it in Cargo 1.96.
## Build scripts, tests, and compiler environment
Cargo sets `CARGO_CFG_FEATURE` for `build.rs` with the package's activated
features. It sets `CARGO_CFG_DEBUG_ASSERTIONS` when the package profile enables
debug assertions. `cargo::rerun-if-env-changed=VAR` also reacts to changes
through Cargo's `[env]` table.
Integration tests can read `CARGO_BIN_EXE_<name>` at runtime using
`std::env::var_os`. Integration tests and benchmarks can use
`env!("CARGO_TARGET_TMPDIR")` for their scratch directory.
Compiler flags after `cargo rustc --` override conflicting `RUSTFLAGS`:
```console
RUSTFLAGS='-Copt-level=1' cargo rustc --lib -- -Copt-level=2
```
This compiles the library at optimization level 2. External subcommands receive
the calling executable path in `CARGO`, which can retain symlink components.
## Nightly scripts and structured tooling
With `-Zscript`, `cargo add` and `cargo remove` edit an embedded manifest
when the script is passed as `--manifest-path`. Scripts ignore surrounding
workspaces; configuration discovery starts from the script's directory.
Unreleased nightly writes an explicit edition whenever Cargo mutates the
embedded manifest, including dependency edits.
Nightly `-Zbuild-analysis` records timings and rebuild reasons across invocations.
It writes timing records as JSON Lines under `~/.cargo/log/`, one log per invocation. Use
`cargo report sessions`, `cargo report rebuilds`, and `cargo report timings`
to query sessions, inspect rebuild reasons, and replay HTML timing reports.
Unreleased nightly accepts JSON output directly from `cargo doc`:
```console
cargo +nightly doc -Zunstable-options --output-format=json
```