Add unit-graph JSON output. by ehuss · Pull Request #7977 · rust-lang/cargo (original) (raw)

This adds a --unit-graph flag that will emit a JSON object of Cargo's internal build graph. See unstable.md for more details.

The primary motivator is to provide an accurate picture of which features are set. With the new feature resolver it is not possible to properly represent the features in the cargo metadata structure, because features are no longer unified. Also, features selected depend on the command, and exactly which packages are being built. To handle that in cargo metadata, it would need to add a "mode" flag, and a superset of flags for all build commands (test, check, build, etc.). To me that seemed like a difficult path to take.

This may also be helpful for making visualizations of the true dependencies. cargo metadata doesn't show the intra-package dependencies like build scripts or test units, and walking the cargo metadata graph correctly isn't always obvious.

This initial concept exposes almost all of the fields. That may be a little too much, but I imagine we could always trim it before stabilizing. This structure also has a high risk of being unstable, since it has a good chance of changing form in the future. I figure that can be addressed with documentation emphasizing that it may change and we may not always provide backwards-compatibility (though we will try if it is not too much burden).

This could also potentially be extended in the future to include things like artifact paths, or "freshness", if we'd like to.