Skip to content

Merge dependency features into root crate (hakari-style behavior) #8

@brndnmtthws

Description

@brndnmtthws

A key feature of cargo-hakari is its ability to merge feature flags into the dependencies of the hack/root crate. This significantly reduces redundant recompilation in large workspaces.

In standard Cargo behavior, if two workspace crates (e.g. A and B) both depend on the same crate but enable different feature sets, Cargo will build that dependency multiple times. This also leads to frequent recompilation when switching targets.

A common workaround is to enable the full, merged feature set at the workspace root and declare the dependency there, then have inner crates depend on it via:

dep = { workspace = true }

This works well in practice for most cases and dramatically improves compile times. There are known edge cases (e.g. mutually exclusive features), so an escape hatch or override mechanism is still necessary, but the general approach is effective.

It would be valuable if cargo-rail supported a similar feature-merging mechanism, either automatically or via configuration, to consolidate dependency features at the root crate and avoid redundant builds.

The cargo-hakari documentation explains the motivation and behavior clearly:
https://docs.rs/cargo-hakari/latest/cargo_hakari/about/

As a workaround, I created my own python linter that can fix this, but cargo-rail is not really a replacement for hakari without this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions