1 //! Constructs the dependency graph for compilation.
3 //! Rust code is typically organized as a set of Cargo packages. The
4 //! dependencies between the packages themselves are stored in the
5 //! `Resolve` struct. However, we can't use that information as is for
6 //! compilation! A package typically contains several targets, or crates,
7 //! and these targets has inter-dependencies. For example, you need to
8 //! compile the `lib` target before the `bin` one, and you need to compile
9 //! `build.rs` before either of those.
11 //! So, we need to lower the `Resolve`, which specifies dependencies between
12 //! *packages*, to a graph of dependencies between their *targets*, and this
13 //! is exactly what this module is doing! Well, almost exactly: another
14 //! complication is that we might want to compile the same target several times
15 //! (for example, with and without tests), so we actually build a dependency
16 //! graph of `Unit`s, which capture these properties.
18 use crate::core
::compiler
::unit_graph
::{UnitDep, UnitGraph}
;
19 use crate::core
::compiler
::UnitInterner
;
20 use crate::core
::compiler
::{CompileKind, CompileMode, RustcTargetData, Unit}
;
21 use crate::core
::dependency
::DepKind
;
22 use crate::core
::profiles
::{Profile, Profiles, UnitFor}
;
23 use crate::core
::resolver
::features
::{FeaturesFor, ResolvedFeatures}
;
24 use crate::core
::resolver
::Resolve
;
25 use crate::core
::{Dependency, Package, PackageId, PackageSet, Target, Workspace}
;
26 use crate::ops
::resolve_all_features
;
27 use crate::util
::interning
::InternedString
;
28 use crate::util
::Config
;
29 use crate::CargoResult
;
31 use std
::collections
::{HashMap, HashSet}
;
33 /// Collection of stuff used while creating the `UnitGraph`.
34 struct State
<'a
, 'cfg
> {
35 ws
: &'a Workspace
<'cfg
>,
37 unit_dependencies
: UnitGraph
,
38 package_set
: &'a PackageSet
<'cfg
>,
39 usr_resolve
: &'a Resolve
,
40 usr_features
: &'a ResolvedFeatures
,
41 std_resolve
: Option
<&'a Resolve
>,
42 std_features
: Option
<&'a ResolvedFeatures
>,
43 /// This flag is `true` while generating the dependencies for the standard
46 global_mode
: CompileMode
,
47 target_data
: &'a RustcTargetData
<'cfg
>,
48 profiles
: &'a Profiles
,
49 interner
: &'a UnitInterner
,
50 scrape_units
: &'a
[Unit
],
52 /// A set of edges in `unit_dependencies` where (a, b) means that the
53 /// dependency from a to b was added purely because it was a dev-dependency.
54 /// This is used during `connect_run_custom_build_deps`.
55 dev_dependency_edges
: HashSet
<(Unit
, Unit
)>,
58 pub fn build_unit_dependencies
<'a
, 'cfg
>(
59 ws
: &'a Workspace
<'cfg
>,
60 package_set
: &'a PackageSet
<'cfg
>,
62 features
: &'a ResolvedFeatures
,
63 std_resolve
: Option
<&'
a (Resolve
, ResolvedFeatures
)>,
65 scrape_units
: &[Unit
],
66 std_roots
: &HashMap
<CompileKind
, Vec
<Unit
>>,
67 global_mode
: CompileMode
,
68 target_data
: &'a RustcTargetData
<'cfg
>,
69 profiles
: &'a Profiles
,
70 interner
: &'a UnitInterner
,
71 ) -> CargoResult
<UnitGraph
> {
73 // If -Zbuild-std, don't attach units if there is nothing to build.
74 // Otherwise, other parts of the code may be confused by seeing units
75 // in the dep graph without a root.
76 return Ok(HashMap
::new());
78 let (std_resolve
, std_features
) = match std_resolve
{
79 Some((r
, f
)) => (Some(r
), Some(f
)),
82 let mut state
= State
{
85 unit_dependencies
: HashMap
::new(),
88 usr_features
: features
,
97 dev_dependency_edges
: HashSet
::new(),
100 let std_unit_deps
= calc_deps_of_std(&mut state
, std_roots
)?
;
102 deps_of_roots(roots
, &mut state
)?
;
103 super::links
::validate_links(state
.resolve(), &state
.unit_dependencies
)?
;
104 // Hopefully there aren't any links conflicts with the standard library?
106 if let Some(std_unit_deps
) = std_unit_deps
{
107 attach_std_deps(&mut state
, std_roots
, std_unit_deps
);
110 connect_run_custom_build_deps(&mut state
);
112 // Dependencies are used in tons of places throughout the backend, many of
113 // which affect the determinism of the build itself. As a result be sure
114 // that dependency lists are always sorted to ensure we've always got a
115 // deterministic output.
116 for list
in state
.unit_dependencies
.values_mut() {
119 trace
!("ALL UNIT DEPENDENCIES {:#?}", state
.unit_dependencies
);
121 Ok(state
.unit_dependencies
)
124 /// Compute all the dependencies for the standard library.
126 mut state
: &mut State
<'_
, '_
>,
127 std_roots
: &HashMap
<CompileKind
, Vec
<Unit
>>,
128 ) -> CargoResult
<Option
<UnitGraph
>> {
129 if std_roots
.is_empty() {
132 // Compute dependencies for the standard library.
134 for roots
in std_roots
.values() {
135 deps_of_roots(roots
, state
)?
;
137 state
.is_std
= false;
138 Ok(Some(std
::mem
::take(&mut state
.unit_dependencies
)))
141 /// Add the standard library units to the `unit_dependencies`.
143 state
: &mut State
<'_
, '_
>,
144 std_roots
: &HashMap
<CompileKind
, Vec
<Unit
>>,
145 std_unit_deps
: UnitGraph
,
147 // Attach the standard library as a dependency of every target unit.
148 let mut found
= false;
149 for (unit
, deps
) in state
.unit_dependencies
.iter_mut() {
150 if !unit
.kind
.is_host() && !unit
.mode
.is_run_custom_build() {
151 deps
.extend(std_roots
[&unit
.kind
].iter().map(|unit
| UnitDep
{
153 unit_for
: UnitFor
::new_normal(),
154 extern_crate_name
: unit
.pkg
.name(),
155 // TODO: Does this `public` make sense?
162 // And also include the dependencies of the standard library itself. Don't
163 // include these if no units actually needed the standard library.
165 for (unit
, deps
) in std_unit_deps
.into_iter() {
166 if let Some(other_unit
) = state
.unit_dependencies
.insert(unit
, deps
) {
167 panic
!("std unit collision with existing unit: {:?}", other_unit
);
173 /// Compute all the dependencies of the given root units.
174 /// The result is stored in state.unit_dependencies.
175 fn deps_of_roots(roots
: &[Unit
], state
: &mut State
<'_
, '_
>) -> CargoResult
<()> {
176 for unit
in roots
.iter() {
177 // Dependencies of tests/benches should not have `panic` set.
178 // We check the global test mode to see if we are running in `cargo
179 // test` in which case we ensure all dependencies have `panic`
180 // cleared, and avoid building the lib thrice (once with `panic`, once
181 // without, once for `--test`). In particular, the lib included for
182 // Doc tests and examples are `Build` mode here.
183 let unit_for
= if unit
.mode
.is_any_test() || state
.global_mode
.is_rustc_test() {
184 if unit
.target
.proc_macro() {
185 // Special-case for proc-macros, which are forced to for-host
186 // since they need to link with the proc_macro crate.
187 UnitFor
::new_host_test(state
.config
)
189 UnitFor
::new_test(state
.config
)
191 } else if unit
.target
.is_custom_build() {
192 // This normally doesn't happen, except `clean` aggressively
193 // generates all units.
194 UnitFor
::new_host(false)
195 } else if unit
.target
.proc_macro() {
196 UnitFor
::new_host(true)
197 } else if unit
.target
.for_host() {
198 // Plugin should never have panic set.
199 UnitFor
::new_compiler()
201 UnitFor
::new_normal()
203 deps_of(unit
, state
, unit_for
)?
;
209 /// Compute the dependencies of a single unit.
210 fn deps_of(unit
: &Unit
, state
: &mut State
<'_
, '_
>, unit_for
: UnitFor
) -> CargoResult
<()> {
211 // Currently the `unit_dependencies` map does not include `unit_for`. This should
212 // be safe for now. `TestDependency` only exists to clear the `panic`
213 // flag, and you'll never ask for a `unit` with `panic` set as a
214 // `TestDependency`. `CustomBuild` should also be fine since if the
215 // requested unit's settings are the same as `Any`, `CustomBuild` can't
216 // affect anything else in the hierarchy.
217 if !state
.unit_dependencies
.contains_key(unit
) {
218 let unit_deps
= compute_deps(unit
, state
, unit_for
)?
;
221 .insert(unit
.clone(), unit_deps
.clone());
222 for unit_dep
in unit_deps
{
223 deps_of(&unit_dep
.unit
, state
, unit_dep
.unit_for
)?
;
229 /// For a package, returns all targets that are registered as dependencies
230 /// for that package.
231 /// This returns a `Vec` of `(Unit, UnitFor)` pairs. The `UnitFor`
232 /// is the profile type that should be used for dependencies of the unit.
235 state
: &mut State
<'_
, '_
>,
237 ) -> CargoResult
<Vec
<UnitDep
>> {
238 if unit
.mode
.is_run_custom_build() {
239 return compute_deps_custom_build(unit
, unit_for
, state
);
240 } else if unit
.mode
.is_doc() {
241 // Note: this does not include doc test.
242 return compute_deps_doc(unit
, state
, unit_for
);
245 let id
= unit
.pkg
.package_id();
246 let filtered_deps
= state
.deps(unit
, unit_for
, &|dep
| {
247 // If this target is a build command, then we only want build
248 // dependencies, otherwise we want everything *other than* build
250 if unit
.target
.is_custom_build() != dep
.is_build() {
254 // If this dependency is **not** a transitive dependency, then it
255 // only applies to test/example targets.
256 if !dep
.is_transitive()
257 && !unit
.target
.is_test()
258 && !unit
.target
.is_example()
259 && !unit
.mode
.is_doc_scrape()
260 && !unit
.mode
.is_any_test()
265 // If we've gotten past all that, then this dependency is
270 let mut ret
= Vec
::new();
271 let mut dev_deps
= Vec
::new();
272 for (id
, deps
) in filtered_deps
{
273 let pkg
= state
.get(id
);
274 let lib
= match pkg
.targets().iter().find(|t
| t
.is_lib()) {
278 let mode
= check_or_build_mode(unit
.mode
, lib
);
279 let dep_unit_for
= unit_for
.with_dependency(unit
, lib
);
281 let start
= ret
.len();
282 if state
.config
.cli_unstable().dual_proc_macros
&& lib
.proc_macro() && !unit
.kind
.is_host()
284 let unit_dep
= new_unit_dep(state
, unit
, pkg
, lib
, dep_unit_for
, unit
.kind
, mode
)?
;
287 new_unit_dep(state
, unit
, pkg
, lib
, dep_unit_for
, CompileKind
::Host
, mode
)?
;
290 let unit_dep
= new_unit_dep(
296 unit
.kind
.for_target(lib
),
302 // If the unit added was a dev-dependency unit, then record that in the
303 // dev-dependencies array. We'll add this to
304 // `state.dev_dependency_edges` at the end and process it later in
305 // `connect_run_custom_build_deps`.
306 if deps
.iter().all(|d
| !d
.is_transitive()) {
307 for dep
in ret
[start
..].iter() {
308 dev_deps
.push((unit
.clone(), dep
.unit
.clone()));
312 state
.dev_dependency_edges
.extend(dev_deps
);
314 // If this target is a build script, then what we've collected so far is
315 // all we need. If this isn't a build script, then it depends on the
316 // build script if there is one.
317 if unit
.target
.is_custom_build() {
320 ret
.extend(dep_build_script(unit
, unit_for
, state
)?
);
322 // If this target is a binary, test, example, etc, then it depends on
323 // the library of the same package. The call to `resolve.deps` above
324 // didn't include `pkg` in the return values, so we need to special case
325 // it here and see if we need to push `(pkg, pkg_lib_target)`.
326 if unit
.target
.is_lib() && unit
.mode
!= CompileMode
::Doctest
{
329 ret
.extend(maybe_lib(unit
, state
, unit_for
, None
)?
);
331 // If any integration tests/benches are being run, make sure that
332 // binaries are built as well.
333 if !unit
.mode
.is_check()
334 && unit
.mode
.is_any_test()
335 && (unit
.target
.is_test() || unit
.target
.is_bench())
342 // Skip binaries with required features that have not been selected.
343 match t
.required_features() {
344 Some(rf
) if t
.is_bin() => {
345 let features
= resolve_all_features(
351 rf
.iter().all(|f
| features
.contains(f
))
353 None
if t
.is_bin() => true,
363 UnitFor
::new_normal(),
364 unit
.kind
.for_target(t
),
368 .collect
::<CargoResult
<Vec
<UnitDep
>>>()?
,
375 /// Returns the dependencies needed to run a build script.
377 /// The `unit` provided must represent an execution of a build script, and
378 /// the returned set of units must all be run before `unit` is run.
379 fn compute_deps_custom_build(
382 state
: &mut State
<'_
, '_
>,
383 ) -> CargoResult
<Vec
<UnitDep
>> {
384 if let Some(links
) = unit
.pkg
.manifest().links() {
387 .script_override(links
, unit
.kind
)
390 // Overridden build scripts don't have any dependencies.
391 return Ok(Vec
::new());
394 // All dependencies of this unit should use profiles for custom builds.
395 // If this is a build script of a proc macro, make sure it uses host
397 let script_unit_for
= UnitFor
::new_host(unit_for
.is_for_host_features());
398 // When not overridden, then the dependencies to run a build script are:
400 // 1. Compiling the build script itself.
401 // 2. For each immediate dependency of our package which has a `links`
402 // key, the execution of that build script.
404 // We don't have a great way of handling (2) here right now so this is
405 // deferred until after the graph of all unit dependencies has been
407 let unit_dep
= new_unit_dep(
413 // Build scripts always compiled for the host.
420 /// Returns the dependencies necessary to document a package.
423 state
: &mut State
<'_
, '_
>,
425 ) -> CargoResult
<Vec
<UnitDep
>> {
426 let deps
= state
.deps(unit
, unit_for
, &|dep
| dep
.kind() == DepKind
::Normal
);
428 // To document a library, we depend on dependencies actually being
429 // built. If we're documenting *all* libraries, then we also depend on
430 // the documentation of the library being built.
431 let mut ret
= Vec
::new();
432 for (id
, _deps
) in deps
{
433 let dep
= state
.get(id
);
434 let lib
= match dep
.targets().iter().find(|t
| t
.is_lib()) {
438 // Rustdoc only needs rmeta files for regular dependencies.
439 // However, for plugins/proc macros, deps should be built like normal.
440 let mode
= check_or_build_mode(unit
.mode
, lib
);
441 let dep_unit_for
= unit_for
.with_dependency(unit
, lib
);
442 let lib_unit_dep
= new_unit_dep(
448 unit
.kind
.for_target(lib
),
451 ret
.push(lib_unit_dep
);
452 if let CompileMode
::Doc { deps: true }
= unit
.mode
{
453 // Document this lib as well.
454 let doc_unit_dep
= new_unit_dep(
460 unit
.kind
.for_target(lib
),
463 ret
.push(doc_unit_dep
);
467 // Be sure to build/run the build script for documented libraries.
468 ret
.extend(dep_build_script(unit
, unit_for
, state
)?
);
470 // If we document a binary/example, we need the library available.
471 if unit
.target
.is_bin() || unit
.target
.is_example() {
473 ret
.extend(maybe_lib(unit
, state
, unit_for
, None
)?
);
474 // and also the lib docs for intra-doc links
475 ret
.extend(maybe_lib(unit
, state
, unit_for
, Some(unit
.mode
))?
);
478 // Add all units being scraped for examples as a dependency of Doc units.
479 if state
.ws
.is_member(&unit
.pkg
) {
480 for scrape_unit
in state
.scrape_units
.iter() {
481 // This needs to match the FeaturesFor used in cargo_compile::generate_targets.
482 let unit_for
= UnitFor
::new_host(scrape_unit
.target
.proc_macro());
483 deps_of(scrape_unit
, state
, unit_for
)?
;
484 ret
.push(new_unit_dep(
501 state
: &mut State
<'_
, '_
>,
503 force_mode
: Option
<CompileMode
>,
504 ) -> CargoResult
<Option
<UnitDep
>> {
508 .find(|t
| t
.is_linkable())
510 let mode
= force_mode
.unwrap_or_else(|| check_or_build_mode(unit
.mode
, t
));
511 let dep_unit_for
= unit_for
.with_dependency(unit
, t
);
518 unit
.kind
.for_target(t
),
525 /// If a build script is scheduled to be run for the package specified by
526 /// `unit`, this function will return the unit to run that build script.
528 /// Overriding a build script simply means that the running of the build
529 /// script itself doesn't have any dependencies, so even in that case a unit
530 /// of work is still returned. `None` is only returned if the package has no
535 state
: &State
<'_
, '_
>,
536 ) -> CargoResult
<Option
<UnitDep
>> {
540 .find(|t
| t
.is_custom_build())
542 // The profile stored in the Unit is the profile for the thing
543 // the custom build script is running for.
544 let profile
= state
.profiles
.get_profile_run_custom_build(&unit
.profile
);
545 // UnitFor::new_host is used because we want the `host` flag set
546 // for all of our build dependencies (so they all get
547 // build-override profiles), including compiling the build.rs
550 // If `is_for_host_features` here is `false`, that means we are a
551 // build.rs script for a normal dependency and we want to set the
552 // CARGO_FEATURE_* environment variables to the features as a
555 // If `is_for_host_features` here is `true`, that means that this
556 // package is being used as a build dependency or proc-macro, and
557 // so we only want to set CARGO_FEATURE_* variables for the host
558 // side of the graph.
560 // Keep in mind that the RunCustomBuild unit and the Compile
561 // build.rs unit use the same features. This is because some
562 // people use `cfg!` and `#[cfg]` expressions to check for enabled
563 // features instead of just checking `CARGO_FEATURE_*` at runtime.
564 // In the case with the new feature resolver (decoupled host
565 // deps), and a shared dependency has different features enabled
566 // for normal vs. build, then the build.rs script will get
567 // compiled twice. I believe it is not feasible to only build it
568 // once because it would break a large number of scripts (they
569 // would think they have the wrong set of features enabled).
570 let script_unit_for
= UnitFor
::new_host(unit_for
.is_for_host_features());
571 new_unit_dep_with_profile(
578 CompileMode
::RunCustomBuild
,
585 /// Choose the correct mode for dependencies.
586 fn check_or_build_mode(mode
: CompileMode
, target
: &Target
) -> CompileMode
{
588 CompileMode
::Check { .. }
| CompileMode
::Doc { .. }
| CompileMode
::Docscrape
=> {
589 if target
.for_host() {
590 // Plugin and proc macro targets should be compiled like
594 // Regular dependencies should not be checked with --test.
595 // Regular dependencies of doc targets should emit rmeta only.
596 CompileMode
::Check { test: false }
599 _
=> CompileMode
::Build
,
603 /// Create a new Unit for a dependency from `parent` to `pkg` and `target`.
605 state
: &State
<'_
, '_
>,
612 ) -> CargoResult
<UnitDep
> {
613 let is_local
= pkg
.package_id().source_id().is_path() && !state
.is_std
;
614 let profile
= state
.profiles
.get_profile(
616 state
.ws
.is_member(pkg
),
622 new_unit_dep_with_profile(state
, parent
, pkg
, target
, unit_for
, kind
, mode
, profile
)
625 fn new_unit_dep_with_profile(
626 state
: &State
<'_
, '_
>,
634 ) -> CargoResult
<UnitDep
> {
635 // TODO: consider making extern_crate_name return InternedString?
636 let extern_crate_name
= InternedString
::new(&state
.resolve().extern_crate_name(
637 parent
.pkg
.package_id(),
643 .is_public_dep(parent
.pkg
.package_id(), pkg
.package_id());
644 let features_for
= unit_for
.map_to_features_for();
645 let features
= state
.activated_features(pkg
.package_id(), features_for
);
648 .intern(pkg
, target
, profile
, kind
, mode
, features
, state
.is_std
, 0);
658 /// Fill in missing dependencies for units of the `RunCustomBuild`
660 /// As mentioned above in `compute_deps_custom_build` each build script
661 /// execution has two dependencies. The first is compiling the build script
662 /// itself (already added) and the second is that all crates the package of the
663 /// build script depends on with `links` keys, their build script execution. (a
664 /// bit confusing eh?)
666 /// Here we take the entire `deps` map and add more dependencies from execution
667 /// of one build script to execution of another build script.
668 fn connect_run_custom_build_deps(state
: &mut State
<'_
, '_
>) {
669 let mut new_deps
= Vec
::new();
673 // First up build a reverse dependency map. This is a mapping of all
674 // `RunCustomBuild` known steps to the unit which depends on them. For
675 // example a library might depend on a build script, so this map will
676 // have the build script as the key and the library would be in the
678 let mut reverse_deps_map
= HashMap
::new();
679 for (unit
, deps
) in state
.unit_dependencies
.iter() {
681 if dep
.unit
.mode
== CompileMode
::RunCustomBuild
{
683 .entry(dep
.unit
.clone())
684 .or_insert_with(HashSet
::new
)
690 // Next, we take a look at all build scripts executions listed in the
691 // dependency map. Our job here is to take everything that depends on
692 // this build script (from our reverse map above) and look at the other
693 // package dependencies of these parents.
695 // If we depend on a linkable target and the build script mentions
696 // `links`, then we depend on that package's build script! Here we use
697 // `dep_build_script` to manufacture an appropriate build script unit to
702 .filter(|k
| k
.mode
== CompileMode
::RunCustomBuild
)
704 // This list of dependencies all depend on `unit`, an execution of
706 let reverse_deps
= match reverse_deps_map
.get(unit
) {
711 let to_add
= reverse_deps
713 // Get all sibling dependencies of `unit`
714 .flat_map(|reverse_dep
| {
715 state
.unit_dependencies
[reverse_dep
]
717 .map(move |a
| (reverse_dep
, a
))
719 // Only deps with `links`.
720 .filter(|(_parent
, other
)| {
721 other
.unit
.pkg
!= unit
.pkg
722 && other
.unit
.target
.is_linkable()
723 && other
.unit
.pkg
.manifest().links().is_some()
725 // Avoid cycles when using the doc --scrape-examples feature:
726 // Say a workspace has crates A and B where A has a build-dependency on B.
727 // The Doc units for A and B will have a dependency on the Docscrape for both A and B.
728 // So this would add a dependency from B-build to A-build, causing a cycle:
729 // B (build) -> A (build) -> B(build)
730 // See the test scrape_examples_avoid_build_script_cycle for a concrete example.
731 // To avoid this cycle, we filter out the B -> A (docscrape) dependency.
732 .filter(|(_parent
, other
)| !other
.unit
.mode
.is_doc_scrape())
733 // Skip dependencies induced via dev-dependencies since
734 // connections between `links` and build scripts only happens
735 // via normal dependencies. Otherwise since dev-dependencies can
736 // be cyclic we could have cyclic build-script executions.
737 .filter_map(move |(parent
, other
)| {
739 .dev_dependency_edges
740 .contains(&((*parent
).clone(), other
.unit
.clone()))
747 // Get the RunCustomBuild for other lib.
748 .filter_map(|other
| {
749 state
.unit_dependencies
[&other
.unit
]
751 .find(|other_dep
| other_dep
.unit
.mode
== CompileMode
::RunCustomBuild
)
754 .collect
::<HashSet
<_
>>();
756 if !to_add
.is_empty() {
757 // (RunCustomBuild, set(other RunCustomBuild))
758 new_deps
.push((unit
.clone(), to_add
));
763 // And finally, add in all the missing dependencies!
764 for (unit
, new_deps
) in new_deps
{
773 impl<'a
, 'cfg
> State
<'a
, 'cfg
> {
774 fn resolve(&self) -> &'a Resolve
{
776 self.std_resolve
.unwrap()
782 fn features(&self) -> &'a ResolvedFeatures
{
784 self.std_features
.unwrap()
790 fn activated_features(
793 features_for
: FeaturesFor
,
794 ) -> Vec
<InternedString
> {
795 let features
= self.features();
796 features
.activated_features(pkg_id
, features_for
)
802 features_for
: FeaturesFor
,
803 dep_name
: InternedString
,
806 .is_dep_activated(pkg_id
, features_for
, dep_name
)
809 fn get(&self, id
: PackageId
) -> &'a Package
{
812 .unwrap_or_else(|_
| panic
!("expected {} to be downloaded", id
))
815 /// Returns a filtered set of dependencies for the given unit.
820 filter
: &dyn Fn(&Dependency
) -> bool
,
821 ) -> Vec
<(PackageId
, &HashSet
<Dependency
>)> {
822 let pkg_id
= unit
.pkg
.package_id();
823 let kind
= unit
.kind
;
826 .filter(|&(_id
, deps
)| {
827 assert
!(!deps
.is_empty());
828 deps
.iter().any(|dep
| {
832 // If this dependency is only available for certain platforms,
833 // make sure we're only enabling it for that platform.
834 if !self.target_data
.dep_platform_activated(dep
, kind
) {
838 // If this is an optional dependency, and the new feature resolver
839 // did not enable it, don't include it.
840 if dep
.is_optional() {
841 let features_for
= unit_for
.map_to_features_for();
842 if !self.is_dep_activated(pkg_id
, features_for
, dep
.name_in_toml()) {