Skip to content

Commit 3f06823

Browse files
committed
Add some comments to help clarify some features stuff from review.
1 parent a2135fe commit 3f06823

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,15 @@ fn compute_deps<'a, 'cfg>(
287287
};
288288
let mode = check_or_build_mode(unit.mode, lib);
289289
let dep_kind = if unit.target.is_custom_build() {
290+
// Custom build scripts can *only* have build-dependencies.
290291
DepKind::Build
291292
} else if deps.iter().any(|dep| !dep.is_transitive()) {
293+
// A dependency can be listed in both [dependencies] and
294+
// [dev-dependencies], so this checks if any of the deps are
295+
// listed in dev-dependencies. Note that `filtered_deps` has
296+
// already removed dev-dependencies if it is not a
297+
// test/bench/example, so it is not necessary to check `unit`
298+
// here.
292299
DepKind::Development
293300
} else {
294301
DepKind::Normal

src/cargo/core/resolver/features.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ use crate::util::{CargoResult, Config};
2525
use std::collections::{BTreeSet, HashMap, HashSet};
2626
use std::rc::Rc;
2727

28+
/// Map of activated features for a PackageId/DepKind/CompileKind.
29+
///
30+
/// `DepKind` is needed, as the same package can be built multiple times with
31+
/// different features. For example, with `decouple_build_deps`, a dependency
32+
/// can be built once as a build dependency (for example with a 'std'
33+
/// feature), and once as a normal dependency (without that 'std' feature).
34+
///
35+
/// `CompileKind` is used currently not needed.
2836
type ActivateMap = HashMap<(PackageId, DepKind, CompileKind), BTreeSet<InternedString>>;
2937

3038
/// Set of all activated features for all packages in the resolve graph.

src/cargo/ops/cargo_compile.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,9 @@ fn generate_targets<'a>(
746746
bcx.profiles
747747
.get_profile(pkg.package_id(), ws.is_member(pkg), unit_for, target_mode);
748748

749+
// Root units are not a dependency of anything, so they are always
750+
// DepKind::Normal. Their features are driven by the command-line
751+
// arguments.
749752
let features = Vec::from(resolved_features.activated_features(
750753
pkg.package_id(),
751754
DepKind::Normal,
@@ -934,6 +937,11 @@ fn generate_targets<'a>(
934937
Ok(units.into_iter().collect())
935938
}
936939

940+
/// Gets all of the features enabled for a package, plus its dependencies'
941+
/// features.
942+
///
943+
/// Dependencies are added as `dep_name/feat_name` because `required-features`
944+
/// wants to support that syntax.
937945
fn resolve_all_features(
938946
resolve_with_overrides: &Resolve,
939947
resolved_features: &features::ResolvedFeatures,

0 commit comments

Comments
 (0)