full-stack-skills/rust-skills

rust-cargo-build

Configure, operate, diagnose, and automate Cargo for Rust packages and workspaces.

ソースを見る
リポジトリの原文

見出し、例、コード、表、リンク、参照画像を含む原文を表示しています。

Rust Cargo Build System

Use Cargo as a versioned package manager, build orchestrator, and automation interface. Base decisions on the project's actual Cargo version, MSRV, workspace root, targets, and release model. Use the official Cargo Book as the authority; keep this skill focused on task selection, execution, and validation.

Preflight

Run the smallest relevant subset:

bash
rustc --version --verbose
cargo --version
cargo locate-project --workspace
cargo metadata --no-deps --format-version 1

Determine:

  • whether the root manifest is a package or virtual workspace;
  • the declared edition, rust-version, resolver, and lockfile policy;
  • selected packages, targets, features, profiles, and target triples;
  • dependency sources, registry configuration, and offline constraints;
  • whether the requested behavior is stable on the installed Cargo version.

Route to the Right Reference

Read only the reference needed for the current task:

TaskReference
Find the authoritative Cargo Guide, Reference, command, or changelog pageOfficial Documentation Map
Select a Cargo command and understand its side effectsCargo Command Map
Start, build, run, test, document, or add CI to a packageCargo Guide Workflow
Configure package metadata and lib/bin/example/test/bench targetsManifest and Targets
Configure dependency sources, features, overrides, or resolversDependencies, Features, and Resolvers
Configure members and inherited workspace fieldsWorkspaces
Configure .cargo/config.toml, environment variables, aliases, network, or target settingsConfiguration and Environment
Tune dev/release/custom profilesProfiles
Generate code, compile native dependencies, or emit Cargo instructions from build.rsBuild Scripts
Diagnose rebuilds, duplicate compilation, cache layout, timings, or future incompatibilitiesBuild Cache and Diagnostics
Configure a linker, runner, or non-host targetCross-compilation
Configure registries, source replacement, vendoring, credentials, or authenticationRegistries and Authentication
Inspect package contents, publish, manage owners, or yank a versionPackaging and Publishing
Build scripts and tooling around stable Cargo JSON or package IDsMetadata and Automation
Evaluate cargo-features, -Z, or other nightly-only behaviorUnstable Cargo Features

Core Workflow

  1. Locate the root — Confirm the workspace root and effective manifest before editing.
  2. Declare compatibility — Record edition, MSRV, supported targets, stable/nightly policy, and feature contract.
  3. Inspect effective state — Use cargo metadata, cargo tree, and the effective configuration rather than inferring from one manifest.
  4. Make the smallest change — Prefer conventional targets, additive features, workspace inheritance, and stable Cargo behavior.
  5. Exercise the requested matrix — Select packages, targets, features, profiles, and target triples explicitly.
  6. Diagnose before optimizing — Use timings, dependency edges, verbose output, and rebuild evidence before changing profiles or caches.
  7. Verify artifacts and side effects — Inspect generated files, package contents, lockfile changes, registry targets, and credentials handling.

Decision Rules

Manifest, MSRV, and Resolver

  • Do not equate an edition with MSRV; declare package.rust-version and test that toolchain.
  • Treat the resolver as workspace-wide. Explicitly set it in virtual workspaces.
  • Verify resolver defaults and version-gated fields against the installed Cargo documentation or changelog.
  • Keep explicit target tables only when Cargo's conventional paths are insufficient.

Cargo.lock and Reproducibility

  • When in doubt, commit Cargo.lock; the current Cargo Guide recommends version control by default.
  • Decide exceptions from the repository's release, CI, and dependency-verification policy, not from a blanket “applications yes, libraries no” rule.
  • Use --locked when a committed lockfile must not change.
  • Use --frozen only when both lockfile mutation and network access must be prohibited.
  • Review lockfile diffs; do not delete the lockfile or run broad updates merely to bypass CI failures.

Dependencies and Features

  • Treat features as additive and validate unification with cargo tree -e features.
  • Use target-specific dependencies for platform selection; do not put cfg(feature = "...") in target dependency tables.
  • Pin Git dependencies to a revision when reproducibility requires them.
  • Use [patch], source replacement, and vendoring only for their documented purposes; do not treat them as interchangeable.

Configuration and Environment

  • Distinguish manifest configuration from hierarchical Cargo configuration.
  • Verify .cargo/config.toml discovery from the command's working directory.
  • Keep secrets out of committed configuration and command history.
  • Separate host settings for build scripts and proc macros from target settings used for final artifacts.

Build Scripts

  • Write generated artifacts only to OUT_DIR.
  • Emit precise cargo::rerun-if-changed and cargo::rerun-if-env-changed instructions.
  • Keep outputs reproducible and avoid network access during builds.
  • Treat native link directives and links metadata as public integration contracts.

Profiles, Cache, and Diagnostics

  • Measure the workflow being optimized: check, incremental development, tests, CI, release linking, runtime, or binary size.
  • Keep profile definitions at the workspace root.
  • Treat the build-directory layout as Cargo-internal unless the Reference documents an output location.
  • Prefer cargo build --timings, cargo tree -d, and future-incompatibility reports over speculative cache deletion.

Registries and Publishing

  • Distinguish registries, source replacement, directory sources, and vendoring.
  • Resolve credential providers and registry identity before login or publish operations.
  • Run cargo package --list and package verification before publishing.
  • Require explicit authorization before login, owner changes, publishing, yanking, or modifying credentials.

Stable and Nightly

  • Prefer stable Cargo behavior.
  • Before recommending nightly, identify the exact unstable feature, invocation form, tracking issue, fallback, and removal condition.
  • Never present cargo-features, -Z, or [unstable] configuration as stable.
  • Re-check the changelog because unstable interfaces can stabilize, change, or disappear.

Validation

Adapt the matrix instead of running unsupported combinations blindly:

bash
cargo metadata --format-version 1
cargo fmt --all --check
cargo check --workspace --all-targets --all-features
cargo test --workspace --all-targets --all-features
cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo package --list

Append --locked to supported Cargo commands when the repository commits or requires a lockfile. If the workspace intentionally excludes some features or targets, define an explicit matrix and record why.

Boundaries

  • Crate selection, advisories, licenses, bans, and supply-chain policy → rust-dependencies
  • Workspace and crate topology → rust-workspace
  • Test architecture, fixtures, property tests, and coverage → rust-testing
  • rustdoc content and documentation architecture → rust-documentation
  • rustfmt, Clippy policy, and edition migration → rust-style-clippy
  • Runtime performance and allocation behavior → rust-performance
  • API compatibility and version-bump decisions → rust-semver
  • Embedded target runtime and hardware integration → rust-embedded

Cargo command mechanics may remain here even when the higher-level decision belongs to another skill.

Completion Criteria

  • Identify the effective workspace, Cargo version, MSRV, target, feature, and profile context.
  • Link the relevant official Cargo page for version-sensitive behavior.
  • Separate stable behavior from nightly experiments.
  • Validate the effective dependency graph and configuration.
  • Preserve reproducibility and credential safety.
  • Confirm artifact, package, or registry side effects before declaring success.

Data Privacy

This skill does not collect, store, or transmit user data. Treat registry tokens, Git credentials, environment variables, generated artifacts, and package contents as potentially sensitive.

同じリポジトリから

関連する Skills

すべての Skills
full-stack-skills
コミュニティ

rust-api-design

Design Rust library APIs that follow the Rust API Guidelines — naming (C-CASE, C-CONV, C-GETTER), interop traits (C-COMMON-TRAITS, C-CONVERT, C-ITER, C-SERDE), predictability (C-INTUITIVE, C-CONST), flexibility (C-GENERIC, C-NEWTYPE, C-EXT), type safety (C-BOOL, C-NONZERO, C-WRAPPER, C-STR), dependability (C-PANIC, C-UNWRAP), debuggability (C-DEBUG), and future-proofing (C-SEALED, C-STRUCT-FIELD, C-NON-EXHAUSTIVE). Use when users design a public crate API, choose between generics/concrete/newtype, decide trait bounds, hide implementation, avoid breakage, or ask "what is idiomatic Rust API design"; hand semver and publish workflow to rust-semver, lint config to rust-style-clippy, and in-crate layout to rust-module-layout.

導入数
1
GitHub Stars
5
更新日
9月19日
full-stack-skills
コミュニティ

rust-by-example

Show Rust patterns through short compilable examples — type conversions (From/Into/TryFrom/as/Deref), flow control (if let/while let/match/loop), functions and closures (Fn/FnMut/FnOnce, captures), modules (mod/use/pub/super/self), generics and traits (bounds/associated types/trait objects), error handling (?/Result/thiserror/anyhow), attributes (derive/cfg/inline/allow), unsafe (raw pointers/unions/ABI), procedural macros (derive/attribute/function-like), and inline asm. Use when users ask "how do I write X in Rust", need a concrete pattern with copy-pasteable code, or are migrating from Java/Python/Go/C++ and want the Rust equivalent; hand architecture decisions to rust-api-design/rust-workspace, std API selection to rust-stdlib, and async runtime to rust-concurrency.

導入数
1
GitHub Stars
5
更新日
9月19日
full-stack-skills
コミュニティ

rust-cli

Design, implement, test, and release production Rust command-line applications, including command contracts, subcommands, configuration precedence, stdin/stdout/stderr, exit codes, file safety, daemon IPC, terminal handling, packaging, and process-level tests. Use when users ask for a Rust CLI, command parser, clap integration, Unix-style pipelines, daemon clients, PTY/TUI behavior, shell completion, or CLI release engineering.

導入数
1
GitHub Stars
5
更新日
9月19日
full-stack-skills
コミュニティ

rust-code-review

Review Rust changes for correctness, memory and thread safety, error semantics, unnecessary allocation or cloning, lock scope, API compatibility, test gaps, documentation, and dependency risk, applying the Rust API Guidelines checklist (C-PANIC, C-UNWRAP, C-TRANSMUTE, C-BOOL, C-NEWTYPE, C-COMMON-TRAITS, C-CONVERT, C-SEALED, C-NON-EXHAUSTIVE). Use when reviewing Rust diffs, pull requests, libraries, unsafe boundaries, or production incidents; report actionable findings by severity before summaries, route automated formatting or lint policy to rust-style-clippy, and route API shape decisions (trait sealing, error taxonomy, newtype design, builder patterns) to rust-api-design.

導入数
1
GitHub Stars
5
更新日
9月19日