Skip to content
Back to skills

Rust Cargo Feature Unification

ASecurity

Use when a Rust workspace builds but a package fails on its own, a dependency feature appears unexpectedly, or CI needs reliable Cargo feature checks.

  • 50,717 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 2, 2026
ai-agentsrustgoshellgitapidocumentation

Works with

  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 2, 2026

npx -y skills add sickn33/agentic-awesome-skills --skill rust-cargo-feature-unification --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rust Cargo Feature Unification?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rust Cargo Feature Unification
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sickn33-rust-cargo-feature-unification/badge)](https://www.skillsdirectory.com/skills/sickn33-rust-cargo-feature-unification)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: rust-cargo-feature-unification
description: "Use when a Rust workspace builds but a package fails on its own, a dependency feature appears unexpectedly, or CI needs reliable Cargo feature checks."
category: development
risk: critical
source: self
source_type: self
date_added: "2026-12-01"
author: ShianMike
tags: [rust, cargo, cargo-features, workspace, dependency-resolution, ci]
---

# Rust Cargo Feature Unification

## When to Use

- `cargo check --workspace` succeeds while checking one workspace package fails on a feature-gated import.
- A release build enables default features even though a dependency declaration uses `default-features = false`.
- CI needs to verify a package, target, or feature selection that is built independently for shipping.

## Prerequisites

- Record `cargo --version`, `rustc --version`, the workspace resolver, and the exact package, target, and feature flags used when shipping.
- Inspect the workspace manifest, the failing package's manifest, and the dependency's feature declarations for the locked version.
- Use the documented fixture in a scratch directory. It uses only local Cargo packages.

## 1. Compare the combined and independent builds

1. Reproduce the passing workspace command and the failing package command as separate invocations. Match the release target and feature flags when those differ from the host defaults.
2. Find which selected package asks for the dependency feature. Cargo combines feature requests on shared normal dependencies when building multiple workspace packages in one invocation. Resolver 2 separates some target, build, and dev contexts while shared normal dependency features can still unify.
3. Compare the inverse feature tree in both build scopes. If more than one dependency version matches, use a version-qualified package spec.

```powershell
cargo tree --workspace -e features -i wire-codec
cargo tree -p worker -e features -i wire-codec
cargo check --workspace --locked
cargo check -p worker --locked
```

## 2. Declare the requirement where the API is used

1. When a package always calls a feature-gated dependency API, request that feature on that package's dependency declaration. Keep `workspace.dependencies` settings aligned with requirements shared by every inheriting package.
2. When the caller's capability is optional, forward its named feature to the dependency feature and gate the call sites. Test both with and without that capability.
3. Interpret `default-features = false` as a choice on that dependency declaration. A different selected edge can still request the default feature. Follow the feature tree before changing dependency versions or resolver settings.

## 3. Verify the combinations CI actually ships

1. Check each independently shipped package in a separate invocation. A workspace command, a multi-package command, or `--all-features` can enable features absent from a standalone build.
2. Check a production build separately from tests when dev-dependencies could enable a missing feature. Add an explicit `--no-default-features` check for a configuration users can actually run.
3. For automation, inspect `--message-format=json` compiler diagnostics and `compiler-artifact` features. Use `Cargo.lock` to pin versions and verify active build features with the selected invocation.

## Example

Run the [three-package workspace fixture](references/workspace-masks-missing-feature.md). It verifies that a sibling's feature request masks a missing declaration and that the corrected worker checks and runs on its own.

## Limitations

- The fixture targets normal dependencies in one workspace on the host. It does not exercise target-specific dependencies, build scripts, multiple dependency versions, or cross-compilation.
- `cargo check` verifies compilation without a final executable link. Use the actual build or run command to verify shipping artifacts.

## Safety and Side Effects

- Cargo checks write target files and can update `Cargo.lock` unless the command uses `--locked`. The fixture creates its lockfile and build output in a fresh temporary workspace and runs offline.
- Manifest and CI changes alter the resolved or active feature set. Review build flags and verify every affected shipping command.

## Related Skills and Documentation

- For project layout and manifests, see [Systems Programming Rust Project](https://github.com/sickn33/agentic-awesome-skills/blob/main/skills/systems-programming-rust-project/SKILL.md).
- For Rust development workflows, see [Rust Pro](https://github.com/sickn33/agentic-awesome-skills/blob/main/skills/rust-pro/SKILL.md).
- The Cargo Book documents [feature unification](https://doc.rust-lang.org/cargo/reference/features.html#feature-unification), [resolver behavior](https://doc.rust-lang.org/cargo/reference/resolver.html#features), and [build JSON messages](https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages).

Files in this skill

  • SKILL.md4.8 KB
  • references/workspace-masks-missing-feature.md4.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.