← LeaderboardThe Skill Leaderboard
rust-cargo-feature-unification
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.
Try your first task
A source-grounded starter task has not been verified for this skill yet.
SKILL.md
name: rust-cargo-feature-unificationdescription: "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: developmentrisk: criticalsource: selfsource_type: selfdate_added: "2026-12-01"author: ShianMiketags: [rust, cargo, cargo-features, workspace, dependency-resolution, ci]Rust Cargo Feature Unification
When to Use
cargo check --workspacesucceeds 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
- 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.
- 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.
- Compare the inverse feature tree in both build scopes. If more than one dependency version matches, use a version-qualified package spec.
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
- When a package always calls a feature-gated dependency API, request that feature on that package's dependency declaration. Keep
workspace.dependenciessettings aligned with requirements shared by every inheriting package. - 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.
- Interpret
default-features = falseas 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
- Check each independently shipped package in a separate invocation. A workspace command, a multi-package command, or
--all-featurescan enable features absent from a standalone build. - Check a production build separately from tests when dev-dependencies could enable a missing feature. Add an explicit
--no-default-featurescheck for a configuration users can actually run. - For automation, inspect
--message-format=jsoncompiler diagnostics andcompiler-artifactfeatures. UseCargo.lockto pin versions and verify active build features with the selected invocation.
Example
Run the three-package workspace fixture. 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 checkverifies 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.lockunless 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.
- For Rust development workflows, see Rust Pro.
- The Cargo Book documents feature unification, resolver behavior, and build JSON messages.