|
1 | 1 | //! Code for building the graph used by `cargo tree`. |
2 | 2 |
|
3 | 3 | use super::TreeOptions; |
4 | | -use crate::core::compiler::{CompileKind, RustcTargetData}; |
| 4 | +use crate::core::compiler::{CompileKind, CompileTarget, RustcTargetData}; |
5 | 5 | use crate::core::dependency::DepKind; |
6 | 6 | use crate::core::resolver::Resolve; |
7 | 7 | use crate::core::resolver::features::{CliFeatures, FeaturesFor, ResolvedFeatures}; |
@@ -486,25 +486,24 @@ fn add_pkg( |
486 | 486 | let dep_pkg = graph.package_map[&dep_id]; |
487 | 487 |
|
488 | 488 | for dep in deps { |
489 | | - let dep_features_for = match dep |
490 | | - .artifact() |
491 | | - .and_then(|artifact| artifact.target()) |
492 | | - .and_then(|target| target.to_resolved_compile_target(requested_kind)) |
493 | | - { |
494 | | - // Dependency has a `{ …, target = <triple> }` |
495 | | - Some(target) => FeaturesFor::ArtifactDep(target), |
496 | | - // Get the information of the dependent crate from `features_for`. |
497 | | - // If a dependent crate is |
498 | | - // |
499 | | - // * specified as an artifact dep with a `target`, or |
500 | | - // * a host dep, |
501 | | - // |
502 | | - // its transitive deps, including build-deps, need to be built on that target. |
503 | | - None if features_for != FeaturesFor::default() => features_for, |
504 | | - // Dependent crate is a normal dep, then back to old rules: |
505 | | - // |
506 | | - // * normal deps, dev-deps -> inherited target |
507 | | - // * build-deps -> host |
| 489 | + // Keep this in sync with `FeatureResolver::deps`: `cargo tree` |
| 490 | + // looks up already-resolved features, so it must use the same key. |
| 491 | + let dep_features_for = match dep.artifact().and_then(|artifact| artifact.target()) { |
| 492 | + // `target = "target"` with a host requested kind is keyed as |
| 493 | + // `ArtifactDep(<host triple>)`, not `HostDep`. |
| 494 | + Some(artifact_target) => { |
| 495 | + match artifact_target.to_resolved_compile_kind(requested_kind) { |
| 496 | + CompileKind::Target(target) => FeaturesFor::ArtifactDep(target), |
| 497 | + CompileKind::Host => { |
| 498 | + let host = CompileTarget::new( |
| 499 | + &target_data.rustc.host, |
| 500 | + target_data.gctx.cli_unstable().json_target_spec, |
| 501 | + ) |
| 502 | + .expect("host target triple is always valid"); |
| 503 | + FeaturesFor::ArtifactDep(host) |
| 504 | + } |
| 505 | + } |
| 506 | + } |
508 | 507 | None => { |
509 | 508 | if dep.is_build() || dep_pkg.proc_macro() { |
510 | 509 | FeaturesFor::HostDep |
|
0 commit comments