]> git.proxmox.com Git - cargo.git/blob - src/cargo/core/compiler/unit_dependencies.rs
Move string interning to util
[cargo.git] / src / cargo / core / compiler / unit_dependencies.rs
1 //! Constructs the dependency graph for compilation.
2 //!
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.
10 //!
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.
17
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::{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;
30 use log::trace;
31 use std::collections::{HashMap, HashSet};
32
33 /// Collection of stuff used while creating the `UnitGraph`.
34 struct State<'a, 'cfg> {
35 ws: &'a Workspace<'cfg>,
36 config: &'cfg Config,
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
44 /// library.
45 is_std: bool,
46 global_mode: CompileMode,
47 target_data: &'a RustcTargetData,
48 profiles: &'a Profiles,
49 interner: &'a UnitInterner,
50 }
51
52 pub fn build_unit_dependencies<'a, 'cfg>(
53 ws: &'a Workspace<'cfg>,
54 package_set: &'a PackageSet<'cfg>,
55 resolve: &'a Resolve,
56 features: &'a ResolvedFeatures,
57 std_resolve: Option<&'a (Resolve, ResolvedFeatures)>,
58 roots: &[Unit],
59 std_roots: &HashMap<CompileKind, Vec<Unit>>,
60 global_mode: CompileMode,
61 target_data: &'a RustcTargetData,
62 profiles: &'a Profiles,
63 interner: &'a UnitInterner,
64 ) -> CargoResult<UnitGraph> {
65 let (std_resolve, std_features) = match std_resolve {
66 Some((r, f)) => (Some(r), Some(f)),
67 None => (None, None),
68 };
69 let mut state = State {
70 ws,
71 config: ws.config(),
72 unit_dependencies: HashMap::new(),
73 package_set,
74 usr_resolve: resolve,
75 usr_features: features,
76 std_resolve,
77 std_features,
78 is_std: false,
79 global_mode,
80 target_data,
81 profiles,
82 interner,
83 };
84
85 let std_unit_deps = calc_deps_of_std(&mut state, std_roots)?;
86
87 deps_of_roots(roots, &mut state)?;
88 super::links::validate_links(state.resolve(), &state.unit_dependencies)?;
89 // Hopefully there aren't any links conflicts with the standard library?
90
91 if let Some(std_unit_deps) = std_unit_deps {
92 attach_std_deps(&mut state, std_roots, std_unit_deps);
93 }
94
95 connect_run_custom_build_deps(&mut state.unit_dependencies);
96
97 // Dependencies are used in tons of places throughout the backend, many of
98 // which affect the determinism of the build itself. As a result be sure
99 // that dependency lists are always sorted to ensure we've always got a
100 // deterministic output.
101 for list in state.unit_dependencies.values_mut() {
102 list.sort();
103 }
104 trace!("ALL UNIT DEPENDENCIES {:#?}", state.unit_dependencies);
105
106 Ok(state.unit_dependencies)
107 }
108
109 /// Compute all the dependencies for the standard library.
110 fn calc_deps_of_std(
111 mut state: &mut State<'_, '_>,
112 std_roots: &HashMap<CompileKind, Vec<Unit>>,
113 ) -> CargoResult<Option<UnitGraph>> {
114 if std_roots.is_empty() {
115 return Ok(None);
116 }
117 // Compute dependencies for the standard library.
118 state.is_std = true;
119 for roots in std_roots.values() {
120 deps_of_roots(roots, &mut state)?;
121 }
122 state.is_std = false;
123 Ok(Some(std::mem::take(&mut state.unit_dependencies)))
124 }
125
126 /// Add the standard library units to the `unit_dependencies`.
127 fn attach_std_deps(
128 state: &mut State<'_, '_>,
129 std_roots: &HashMap<CompileKind, Vec<Unit>>,
130 std_unit_deps: UnitGraph,
131 ) {
132 // Attach the standard library as a dependency of every target unit.
133 for (unit, deps) in state.unit_dependencies.iter_mut() {
134 if !unit.kind.is_host() && !unit.mode.is_run_custom_build() {
135 deps.extend(std_roots[&unit.kind].iter().map(|unit| UnitDep {
136 unit: unit.clone(),
137 unit_for: UnitFor::new_normal(),
138 extern_crate_name: unit.pkg.name(),
139 // TODO: Does this `public` make sense?
140 public: true,
141 noprelude: true,
142 }));
143 }
144 }
145 // And also include the dependencies of the standard library itself.
146 for (unit, deps) in std_unit_deps.into_iter() {
147 if let Some(other_unit) = state.unit_dependencies.insert(unit, deps) {
148 panic!("std unit collision with existing unit: {:?}", other_unit);
149 }
150 }
151 }
152
153 /// Compute all the dependencies of the given root units.
154 /// The result is stored in state.unit_dependencies.
155 fn deps_of_roots(roots: &[Unit], mut state: &mut State<'_, '_>) -> CargoResult<()> {
156 for unit in roots.iter() {
157 // Dependencies of tests/benches should not have `panic` set.
158 // We check the global test mode to see if we are running in `cargo
159 // test` in which case we ensure all dependencies have `panic`
160 // cleared, and avoid building the lib thrice (once with `panic`, once
161 // without, once for `--test`). In particular, the lib included for
162 // Doc tests and examples are `Build` mode here.
163 let unit_for = if unit.mode.is_any_test() || state.global_mode.is_rustc_test() {
164 UnitFor::new_test(state.config)
165 } else if unit.target.is_custom_build() {
166 // This normally doesn't happen, except `clean` aggressively
167 // generates all units.
168 UnitFor::new_host(false)
169 } else if unit.target.proc_macro() {
170 UnitFor::new_host(true)
171 } else if unit.target.for_host() {
172 // Plugin should never have panic set.
173 UnitFor::new_compiler()
174 } else {
175 UnitFor::new_normal()
176 };
177 deps_of(unit, &mut state, unit_for)?;
178 }
179
180 Ok(())
181 }
182
183 /// Compute the dependencies of a single unit.
184 fn deps_of(unit: &Unit, state: &mut State<'_, '_>, unit_for: UnitFor) -> CargoResult<()> {
185 // Currently the `unit_dependencies` map does not include `unit_for`. This should
186 // be safe for now. `TestDependency` only exists to clear the `panic`
187 // flag, and you'll never ask for a `unit` with `panic` set as a
188 // `TestDependency`. `CustomBuild` should also be fine since if the
189 // requested unit's settings are the same as `Any`, `CustomBuild` can't
190 // affect anything else in the hierarchy.
191 if !state.unit_dependencies.contains_key(unit) {
192 let unit_deps = compute_deps(unit, state, unit_for)?;
193 state
194 .unit_dependencies
195 .insert(unit.clone(), unit_deps.clone());
196 for unit_dep in unit_deps {
197 deps_of(&unit_dep.unit, state, unit_dep.unit_for)?;
198 }
199 }
200 Ok(())
201 }
202
203 /// For a package, returns all targets that are registered as dependencies
204 /// for that package.
205 /// This returns a `Vec` of `(Unit, UnitFor)` pairs. The `UnitFor`
206 /// is the profile type that should be used for dependencies of the unit.
207 fn compute_deps(
208 unit: &Unit,
209 state: &mut State<'_, '_>,
210 unit_for: UnitFor,
211 ) -> CargoResult<Vec<UnitDep>> {
212 if unit.mode.is_run_custom_build() {
213 return compute_deps_custom_build(unit, unit_for, state);
214 } else if unit.mode.is_doc() {
215 // Note: this does not include doc test.
216 return compute_deps_doc(unit, state);
217 }
218
219 let id = unit.pkg.package_id();
220 let filtered_deps = state.resolve().deps(id).filter(|&(_id, deps)| {
221 assert!(!deps.is_empty());
222 deps.iter().any(|dep| {
223 // If this target is a build command, then we only want build
224 // dependencies, otherwise we want everything *other than* build
225 // dependencies.
226 if unit.target.is_custom_build() != dep.is_build() {
227 return false;
228 }
229
230 // If this dependency is **not** a transitive dependency, then it
231 // only applies to test/example targets.
232 if !dep.is_transitive()
233 && !unit.target.is_test()
234 && !unit.target.is_example()
235 && !unit.mode.is_any_test()
236 {
237 return false;
238 }
239
240 // If this dependency is only available for certain platforms,
241 // make sure we're only enabling it for that platform.
242 if !state.target_data.dep_platform_activated(dep, unit.kind) {
243 return false;
244 }
245
246 // If this is an optional dependency, and the new feature resolver
247 // did not enable it, don't include it.
248 if dep.is_optional() {
249 let features_for = unit_for.map_to_features_for();
250
251 let feats = state.activated_features(id, features_for);
252 if !feats.contains(&dep.name_in_toml()) {
253 return false;
254 }
255 }
256
257 // If we've gotten past all that, then this dependency is
258 // actually used!
259 true
260 })
261 });
262 // Separate line to avoid rustfmt indentation. Must collect due to `state` capture.
263 let filtered_deps: Vec<_> = filtered_deps.collect();
264
265 let mut ret = Vec::new();
266 for (id, _) in filtered_deps {
267 let pkg = state.get(id);
268 let lib = match pkg.targets().iter().find(|t| t.is_lib()) {
269 Some(t) => t,
270 None => continue,
271 };
272 let mode = check_or_build_mode(unit.mode, lib);
273 let dep_unit_for = unit_for
274 .with_for_host(lib.for_host())
275 // If it is a custom build script, then it *only* has build dependencies.
276 .with_host_features(unit.target.is_custom_build() || lib.proc_macro());
277
278 if state.config.cli_unstable().dual_proc_macros && lib.proc_macro() && !unit.kind.is_host()
279 {
280 let unit_dep = new_unit_dep(state, unit, pkg, lib, dep_unit_for, unit.kind, mode)?;
281 ret.push(unit_dep);
282 let unit_dep =
283 new_unit_dep(state, unit, pkg, lib, dep_unit_for, CompileKind::Host, mode)?;
284 ret.push(unit_dep);
285 } else {
286 let unit_dep = new_unit_dep(
287 state,
288 unit,
289 pkg,
290 lib,
291 dep_unit_for,
292 unit.kind.for_target(lib),
293 mode,
294 )?;
295 ret.push(unit_dep);
296 }
297 }
298
299 // If this target is a build script, then what we've collected so far is
300 // all we need. If this isn't a build script, then it depends on the
301 // build script if there is one.
302 if unit.target.is_custom_build() {
303 return Ok(ret);
304 }
305 ret.extend(dep_build_script(unit, unit_for, state)?);
306
307 // If this target is a binary, test, example, etc, then it depends on
308 // the library of the same package. The call to `resolve.deps` above
309 // didn't include `pkg` in the return values, so we need to special case
310 // it here and see if we need to push `(pkg, pkg_lib_target)`.
311 if unit.target.is_lib() && unit.mode != CompileMode::Doctest {
312 return Ok(ret);
313 }
314 ret.extend(maybe_lib(unit, state, unit_for)?);
315
316 // If any integration tests/benches are being run, make sure that
317 // binaries are built as well.
318 if !unit.mode.is_check()
319 && unit.mode.is_any_test()
320 && (unit.target.is_test() || unit.target.is_bench())
321 {
322 ret.extend(
323 unit.pkg
324 .targets()
325 .iter()
326 .filter(|t| {
327 // Skip binaries with required features that have not been selected.
328 match t.required_features() {
329 Some(rf) if t.is_bin() => {
330 let features = resolve_all_features(
331 state.resolve(),
332 state.features(),
333 state.package_set,
334 id,
335 );
336 rf.iter().all(|f| features.contains(f))
337 }
338 None if t.is_bin() => true,
339 _ => false,
340 }
341 })
342 .map(|t| {
343 new_unit_dep(
344 state,
345 unit,
346 &unit.pkg,
347 t,
348 UnitFor::new_normal(),
349 unit.kind.for_target(t),
350 CompileMode::Build,
351 )
352 })
353 .collect::<CargoResult<Vec<UnitDep>>>()?,
354 );
355 }
356
357 Ok(ret)
358 }
359
360 /// Returns the dependencies needed to run a build script.
361 ///
362 /// The `unit` provided must represent an execution of a build script, and
363 /// the returned set of units must all be run before `unit` is run.
364 fn compute_deps_custom_build(
365 unit: &Unit,
366 unit_for: UnitFor,
367 state: &mut State<'_, '_>,
368 ) -> CargoResult<Vec<UnitDep>> {
369 if let Some(links) = unit.pkg.manifest().links() {
370 if state
371 .target_data
372 .script_override(links, unit.kind)
373 .is_some()
374 {
375 // Overridden build scripts don't have any dependencies.
376 return Ok(Vec::new());
377 }
378 }
379 // All dependencies of this unit should use profiles for custom builds.
380 // If this is a build script of a proc macro, make sure it uses host
381 // features.
382 let script_unit_for = UnitFor::new_host(unit_for.is_for_host_features());
383 // When not overridden, then the dependencies to run a build script are:
384 //
385 // 1. Compiling the build script itself.
386 // 2. For each immediate dependency of our package which has a `links`
387 // key, the execution of that build script.
388 //
389 // We don't have a great way of handling (2) here right now so this is
390 // deferred until after the graph of all unit dependencies has been
391 // constructed.
392 let unit_dep = new_unit_dep(
393 state,
394 unit,
395 &unit.pkg,
396 &unit.target,
397 script_unit_for,
398 // Build scripts always compiled for the host.
399 CompileKind::Host,
400 CompileMode::Build,
401 )?;
402 Ok(vec![unit_dep])
403 }
404
405 /// Returns the dependencies necessary to document a package.
406 fn compute_deps_doc(unit: &Unit, state: &mut State<'_, '_>) -> CargoResult<Vec<UnitDep>> {
407 let target_data = state.target_data;
408 let deps = state
409 .resolve()
410 .deps(unit.pkg.package_id())
411 .filter(|&(_id, deps)| {
412 deps.iter().any(|dep| match dep.kind() {
413 DepKind::Normal => target_data.dep_platform_activated(dep, unit.kind),
414 _ => false,
415 })
416 });
417
418 // To document a library, we depend on dependencies actually being
419 // built. If we're documenting *all* libraries, then we also depend on
420 // the documentation of the library being built.
421 let mut ret = Vec::new();
422 for (id, _deps) in deps {
423 let dep = state.get(id);
424 let lib = match dep.targets().iter().find(|t| t.is_lib()) {
425 Some(lib) => lib,
426 None => continue,
427 };
428 // Rustdoc only needs rmeta files for regular dependencies.
429 // However, for plugins/proc macros, deps should be built like normal.
430 let mode = check_or_build_mode(unit.mode, lib);
431 let dep_unit_for = UnitFor::new_normal()
432 .with_for_host(lib.for_host())
433 .with_host_features(lib.proc_macro());
434 let lib_unit_dep = new_unit_dep(
435 state,
436 unit,
437 dep,
438 lib,
439 dep_unit_for,
440 unit.kind.for_target(lib),
441 mode,
442 )?;
443 ret.push(lib_unit_dep);
444 if let CompileMode::Doc { deps: true } = unit.mode {
445 // Document this lib as well.
446 let doc_unit_dep = new_unit_dep(
447 state,
448 unit,
449 dep,
450 lib,
451 dep_unit_for,
452 unit.kind.for_target(lib),
453 unit.mode,
454 )?;
455 ret.push(doc_unit_dep);
456 }
457 }
458
459 // Be sure to build/run the build script for documented libraries.
460 ret.extend(dep_build_script(unit, UnitFor::new_normal(), state)?);
461
462 // If we document a binary/example, we need the library available.
463 if unit.target.is_bin() || unit.target.is_example() {
464 ret.extend(maybe_lib(unit, state, UnitFor::new_normal())?);
465 }
466 Ok(ret)
467 }
468
469 fn maybe_lib(
470 unit: &Unit,
471 state: &mut State<'_, '_>,
472 unit_for: UnitFor,
473 ) -> CargoResult<Option<UnitDep>> {
474 unit.pkg
475 .targets()
476 .iter()
477 .find(|t| t.is_linkable())
478 .map(|t| {
479 let mode = check_or_build_mode(unit.mode, t);
480 new_unit_dep(
481 state,
482 unit,
483 &unit.pkg,
484 t,
485 unit_for,
486 unit.kind.for_target(t),
487 mode,
488 )
489 })
490 .transpose()
491 }
492
493 /// If a build script is scheduled to be run for the package specified by
494 /// `unit`, this function will return the unit to run that build script.
495 ///
496 /// Overriding a build script simply means that the running of the build
497 /// script itself doesn't have any dependencies, so even in that case a unit
498 /// of work is still returned. `None` is only returned if the package has no
499 /// build script.
500 fn dep_build_script(
501 unit: &Unit,
502 unit_for: UnitFor,
503 state: &State<'_, '_>,
504 ) -> CargoResult<Option<UnitDep>> {
505 unit.pkg
506 .targets()
507 .iter()
508 .find(|t| t.is_custom_build())
509 .map(|t| {
510 // The profile stored in the Unit is the profile for the thing
511 // the custom build script is running for.
512 let profile = state.profiles.get_profile_run_custom_build(&unit.profile);
513 // UnitFor::new_host is used because we want the `host` flag set
514 // for all of our build dependencies (so they all get
515 // build-override profiles), including compiling the build.rs
516 // script itself.
517 //
518 // If `is_for_host_features` here is `false`, that means we are a
519 // build.rs script for a normal dependency and we want to set the
520 // CARGO_FEATURE_* environment variables to the features as a
521 // normal dep.
522 //
523 // If `is_for_host_features` here is `true`, that means that this
524 // package is being used as a build dependency or proc-macro, and
525 // so we only want to set CARGO_FEATURE_* variables for the host
526 // side of the graph.
527 //
528 // Keep in mind that the RunCustomBuild unit and the Compile
529 // build.rs unit use the same features. This is because some
530 // people use `cfg!` and `#[cfg]` expressions to check for enabled
531 // features instead of just checking `CARGO_FEATURE_*` at runtime.
532 // In the case with `-Zfeatures=host_dep`, and a shared
533 // dependency has different features enabled for normal vs. build,
534 // then the build.rs script will get compiled twice. I believe it
535 // is not feasible to only build it once because it would break a
536 // large number of scripts (they would think they have the wrong
537 // set of features enabled).
538 let script_unit_for = UnitFor::new_host(unit_for.is_for_host_features());
539 new_unit_dep_with_profile(
540 state,
541 unit,
542 &unit.pkg,
543 t,
544 script_unit_for,
545 unit.kind,
546 CompileMode::RunCustomBuild,
547 profile,
548 )
549 })
550 .transpose()
551 }
552
553 /// Choose the correct mode for dependencies.
554 fn check_or_build_mode(mode: CompileMode, target: &Target) -> CompileMode {
555 match mode {
556 CompileMode::Check { .. } | CompileMode::Doc { .. } => {
557 if target.for_host() {
558 // Plugin and proc macro targets should be compiled like
559 // normal.
560 CompileMode::Build
561 } else {
562 // Regular dependencies should not be checked with --test.
563 // Regular dependencies of doc targets should emit rmeta only.
564 CompileMode::Check { test: false }
565 }
566 }
567 _ => CompileMode::Build,
568 }
569 }
570
571 /// Create a new Unit for a dependency from `parent` to `pkg` and `target`.
572 fn new_unit_dep(
573 state: &State<'_, '_>,
574 parent: &Unit,
575 pkg: &Package,
576 target: &Target,
577 unit_for: UnitFor,
578 kind: CompileKind,
579 mode: CompileMode,
580 ) -> CargoResult<UnitDep> {
581 let is_local = pkg.package_id().source_id().is_path() && !state.is_std;
582 let profile = state.profiles.get_profile(
583 pkg.package_id(),
584 state.ws.is_member(pkg),
585 is_local,
586 unit_for,
587 mode,
588 );
589 new_unit_dep_with_profile(state, parent, pkg, target, unit_for, kind, mode, profile)
590 }
591
592 fn new_unit_dep_with_profile(
593 state: &State<'_, '_>,
594 parent: &Unit,
595 pkg: &Package,
596 target: &Target,
597 unit_for: UnitFor,
598 kind: CompileKind,
599 mode: CompileMode,
600 profile: Profile,
601 ) -> CargoResult<UnitDep> {
602 // TODO: consider making extern_crate_name return InternedString?
603 let extern_crate_name = InternedString::new(&state.resolve().extern_crate_name(
604 parent.pkg.package_id(),
605 pkg.package_id(),
606 target,
607 )?);
608 let public = state
609 .resolve()
610 .is_public_dep(parent.pkg.package_id(), pkg.package_id());
611 let features_for = unit_for.map_to_features_for();
612 let features = state.activated_features(pkg.package_id(), features_for);
613 let unit = state
614 .interner
615 .intern(pkg, target, profile, kind, mode, features, state.is_std);
616 Ok(UnitDep {
617 unit,
618 unit_for,
619 extern_crate_name,
620 public,
621 noprelude: false,
622 })
623 }
624
625 /// Fill in missing dependencies for units of the `RunCustomBuild`
626 ///
627 /// As mentioned above in `compute_deps_custom_build` each build script
628 /// execution has two dependencies. The first is compiling the build script
629 /// itself (already added) and the second is that all crates the package of the
630 /// build script depends on with `links` keys, their build script execution. (a
631 /// bit confusing eh?)
632 ///
633 /// Here we take the entire `deps` map and add more dependencies from execution
634 /// of one build script to execution of another build script.
635 fn connect_run_custom_build_deps(unit_dependencies: &mut UnitGraph) {
636 let mut new_deps = Vec::new();
637
638 {
639 // First up build a reverse dependency map. This is a mapping of all
640 // `RunCustomBuild` known steps to the unit which depends on them. For
641 // example a library might depend on a build script, so this map will
642 // have the build script as the key and the library would be in the
643 // value's set.
644 let mut reverse_deps_map = HashMap::new();
645 for (unit, deps) in unit_dependencies.iter() {
646 for dep in deps {
647 if dep.unit.mode == CompileMode::RunCustomBuild {
648 reverse_deps_map
649 .entry(dep.unit.clone())
650 .or_insert_with(HashSet::new)
651 .insert(unit);
652 }
653 }
654 }
655
656 // Next, we take a look at all build scripts executions listed in the
657 // dependency map. Our job here is to take everything that depends on
658 // this build script (from our reverse map above) and look at the other
659 // package dependencies of these parents.
660 //
661 // If we depend on a linkable target and the build script mentions
662 // `links`, then we depend on that package's build script! Here we use
663 // `dep_build_script` to manufacture an appropriate build script unit to
664 // depend on.
665 for unit in unit_dependencies
666 .keys()
667 .filter(|k| k.mode == CompileMode::RunCustomBuild)
668 {
669 // This is the lib that runs this custom build.
670 let reverse_deps = match reverse_deps_map.get(unit) {
671 Some(set) => set,
672 None => continue,
673 };
674
675 let to_add = reverse_deps
676 .iter()
677 // Get all deps for lib.
678 .flat_map(|reverse_dep| unit_dependencies[reverse_dep].iter())
679 // Only deps with `links`.
680 .filter(|other| {
681 other.unit.pkg != unit.pkg
682 && other.unit.target.is_linkable()
683 && other.unit.pkg.manifest().links().is_some()
684 })
685 // Get the RunCustomBuild for other lib.
686 .filter_map(|other| {
687 unit_dependencies[&other.unit]
688 .iter()
689 .find(|other_dep| other_dep.unit.mode == CompileMode::RunCustomBuild)
690 .cloned()
691 })
692 .collect::<HashSet<_>>();
693
694 if !to_add.is_empty() {
695 // (RunCustomBuild, set(other RunCustomBuild))
696 new_deps.push((unit.clone(), to_add));
697 }
698 }
699 }
700
701 // And finally, add in all the missing dependencies!
702 for (unit, new_deps) in new_deps {
703 unit_dependencies.get_mut(&unit).unwrap().extend(new_deps);
704 }
705 }
706
707 impl<'a, 'cfg> State<'a, 'cfg> {
708 fn resolve(&self) -> &'a Resolve {
709 if self.is_std {
710 self.std_resolve.unwrap()
711 } else {
712 self.usr_resolve
713 }
714 }
715
716 fn features(&self) -> &'a ResolvedFeatures {
717 if self.is_std {
718 self.std_features.unwrap()
719 } else {
720 self.usr_features
721 }
722 }
723
724 fn activated_features(
725 &self,
726 pkg_id: PackageId,
727 features_for: FeaturesFor,
728 ) -> Vec<InternedString> {
729 let features = self.features();
730 features.activated_features(pkg_id, features_for)
731 }
732
733 fn get(&self, id: PackageId) -> &'a Package {
734 self.package_set
735 .get_one(id)
736 .unwrap_or_else(|_| panic!("expected {} to be downloaded", id))
737 }
738 }