Home / Market / rust cargo feature unification

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.

skill★ 508990 dlgithubCC-BY-4.0 content; MIT code; upstream exceptions applyInstall in CosmosUpstream Source

Documentation & Preview

--- 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

Prerequisites

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.
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. It verifies that a sibling's feature request masks a missing declaration and that the corrected worker checks and runs on its own.

Limitations

Safety and Side Effects

Related Skills and Documentation