-
Notifications
You must be signed in to change notification settings - Fork 2
Description
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.