EmbarkStudios / krates

📦 Creates graphs of crates from cargo metadata 🦀
Apache License 2.0
58 stars 18 forks source link

Fix bug with features and optional dependencies #45

Closed Jake-Shadle closed 2 years ago

Jake-Shadle commented 2 years ago

This fixes a bug where the fix for #41 was...not correct, and would erroneously prune out optional dependencies if the feature that brought them in did not exactly match their name, which was somehow a case I didn't run across testing.

This can be seen in, for example, wasmtime.

[dependencies]
wasmtime-cranelift = { workspace = true, optional = true }
rayon = { version = "1.0", optional = true }

[features]
cranelift = ["dep:wasmtime-cranelift"]
parallel-compilation = ["dep:rayon"]

The bug was that since both wasmtime-cranelift and rayon were marked as optional, the code would attempt to locate wasmtime-cranelift in the features and fail, so now it properly looks to see if the any of the enabled features have subfeatures that enable the exact package id, getting rid of the broken name comparison.

This also adds Krate::direct_dependencies for the same reason as having direct_dependents