mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00

fix: deduplicate dependencies by artifact target ### What does this PR try to resolve? In cases when a compile target is specified for a bindep and the crate depending on it, cargo fails to deduplicate the crate dependencies and attempts to build the dependent crate only once with non-deterministic feature set, which breaks e.g. https://github.com/rvolosatovs/musl-bindep-feature-bug Fix the issue by including the optional artifact compile target in the `Unit` in order to avoid wrongfully deduplicating the dependent crates Fixes https://github.com/rust-lang/cargo/issues/11463 Fixes https://github.com/rust-lang/cargo/issues/10837 Fixes https://github.com/rust-lang/cargo/issues/10525 Note, that this issue is already accounted for by `cargo`, but in different context a similar situation can occur while building the build script, which: 1. may be built for different target than the actual package target 2. may contain dependencies with different feature sets than the same dependencies in the dependency graph of the package itself That's why this PR is simply reusing the existing functionality for deduplication ### How should we test and review this PR? Build https://github.com/rvolosatovs/musl-bindep-feature-bug ### Additional information This is based on analysis by `@weihanglo` in https://github.com/rust-lang/cargo/issues/10837#issuecomment-1339365374 I experimented with adding the whole `UnitFor` to the internal unit struct, but that seems unnecessary. It would probably be nicer to refactor `IsArtifact` and instead turn it into a 3-variant enum with a possible compile target, but I decided against that to minimize the diff. Perhaps it's worth a follow-up?