Skip to content

Cargo doesn't allow cyclic features #3796

@retep998

Description

@retep998

If a crate has two features foo and bar which depend on each other, Cargo will error.

[features]
foo = ["bar"]
bar = ["foo"]
error: Cyclic feature dependency: feature `foo` depends on itself

However, I ended up needing this in winapi. In order to allow people to compile only the bits they need to save time, winapi has a feature for each header. Since headers depend on each other, the features in turn had to depend on each other to ensure that winapi would compile correctly. Unfortunately sometimes those headers would have cyclic dependencies on each other, causing Cargo to complain. There were several workarounds I tried such as having a feature that is common to a set of headers which depend on each other, but I eventually settled on doing feature dependency resolution myself via a build script. https://github.com/retep998/winapi-rs/blob/dev/build.rs#L175-L191

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-featuresArea: features — conditional compilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions