Skip to content

Commit ad201bc

Browse files
committed
Fix unit_generator links in architecture docs, move resolve_all_features to cargo_compile top-level module
1 parent 2a26aef commit ad201bc

File tree

3 files changed

+46
-47
lines changed

3 files changed

+46
-47
lines changed

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ use crate::core::compiler::{BuildConfig, BuildContext, Compilation, Context};
4141
use crate::core::compiler::{CompileKind, CompileMode, CompileTarget, RustcTargetData, Unit};
4242
use crate::core::compiler::{DefaultExecutor, Executor, UnitInterner};
4343
use crate::core::profiles::Profiles;
44-
use crate::core::resolver::features::CliFeatures;
45-
use crate::core::resolver::HasDevUnits;
46-
use crate::core::{SourceId, TargetKind, Workspace};
44+
use crate::core::resolver::features::{self, CliFeatures, FeaturesFor};
45+
use crate::core::resolver::{HasDevUnits, Resolve};
46+
use crate::core::{PackageId, PackageSet, SourceId, TargetKind, Workspace};
4747
use crate::drop_println;
4848
use crate::ops;
4949
use crate::ops::resolve::WorkspaceResolve;
@@ -55,7 +55,6 @@ mod compile_filter;
5555
pub use compile_filter::{CompileFilter, FilterRule, LibRule};
5656

5757
mod unit_generator;
58-
pub use unit_generator::resolve_all_features;
5958
use unit_generator::UnitGenerator;
6059

6160
mod packages;
@@ -817,3 +816,41 @@ fn override_rustc_crate_types(
817816

818817
Ok(())
819818
}
819+
820+
/// Gets all of the features enabled for a package, plus its dependencies'
821+
/// features.
822+
///
823+
/// Dependencies are added as `dep_name/feat_name` because `required-features`
824+
/// wants to support that syntax.
825+
pub fn resolve_all_features(
826+
resolve_with_overrides: &Resolve,
827+
resolved_features: &features::ResolvedFeatures,
828+
package_set: &PackageSet<'_>,
829+
package_id: PackageId,
830+
) -> HashSet<String> {
831+
let mut features: HashSet<String> = resolved_features
832+
.activated_features(package_id, FeaturesFor::NormalOrDev)
833+
.iter()
834+
.map(|s| s.to_string())
835+
.collect();
836+
837+
// Include features enabled for use by dependencies so targets can also use them with the
838+
// required-features field when deciding whether to be built or skipped.
839+
for (dep_id, deps) in resolve_with_overrides.deps(package_id) {
840+
let is_proc_macro = package_set
841+
.get_one(dep_id)
842+
.expect("packages downloaded")
843+
.proc_macro();
844+
for dep in deps {
845+
let features_for = FeaturesFor::from_for_host(is_proc_macro || dep.is_build());
846+
for feature in resolved_features
847+
.activated_features_unverified(dep_id, features_for)
848+
.unwrap_or_default()
849+
{
850+
features.insert(format!("{}/{}", dep.name_in_toml(), feature));
851+
}
852+
}
853+
}
854+
855+
features
856+
}

src/cargo/ops/cargo_compile/unit_generator.rs

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::core::profiles::{Profiles, UnitFor};
1010
use crate::core::resolver::features::{self, FeaturesFor};
1111
use crate::core::resolver::{HasDevUnits, Resolve};
1212
use crate::core::{FeatureValue, Package, PackageSet, Summary, Target};
13-
use crate::core::{PackageId, TargetKind, Workspace};
13+
use crate::core::{TargetKind, Workspace};
1414
use crate::util::restricted_names::is_glob_pattern;
1515
use crate::util::{closest_msg, CargoResult};
1616

@@ -619,7 +619,7 @@ impl<'a> UnitGenerator<'a, '_> {
619619
self.validate_required_features(target.name(), rf, pkg.summary())?;
620620

621621
let features = features_map.entry(pkg).or_insert_with(|| {
622-
resolve_all_features(
622+
super::resolve_all_features(
623623
self.resolve,
624624
self.resolved_features,
625625
self.package_set,
@@ -664,41 +664,3 @@ impl<'a> UnitGenerator<'a, '_> {
664664
self.proposals_to_units(proposals)
665665
}
666666
}
667-
668-
/// Gets all of the features enabled for a package, plus its dependencies'
669-
/// features.
670-
///
671-
/// Dependencies are added as `dep_name/feat_name` because `required-features`
672-
/// wants to support that syntax.
673-
pub fn resolve_all_features(
674-
resolve_with_overrides: &Resolve,
675-
resolved_features: &features::ResolvedFeatures,
676-
package_set: &PackageSet<'_>,
677-
package_id: PackageId,
678-
) -> HashSet<String> {
679-
let mut features: HashSet<String> = resolved_features
680-
.activated_features(package_id, FeaturesFor::NormalOrDev)
681-
.iter()
682-
.map(|s| s.to_string())
683-
.collect();
684-
685-
// Include features enabled for use by dependencies so targets can also use them with the
686-
// required-features field when deciding whether to be built or skipped.
687-
for (dep_id, deps) in resolve_with_overrides.deps(package_id) {
688-
let is_proc_macro = package_set
689-
.get_one(dep_id)
690-
.expect("packages downloaded")
691-
.proc_macro();
692-
for dep in deps {
693-
let features_for = FeaturesFor::from_for_host(is_proc_macro || dep.is_build());
694-
for feature in resolved_features
695-
.activated_features_unverified(dep_id, features_for)
696-
.unwrap_or_default()
697-
{
698-
features.insert(format!("{}/{}", dep.name_in_toml(), feature));
699-
}
700-
}
701-
}
702-
703-
features
704-
}

src/doc/contrib/src/architecture/compilation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module. The compilation can be conceptually broken into these steps:
99

1010
1. Perform dependency resolution (see [the resolution chapter]).
1111
2. Generate the root `Unit`s, the things the user requested to compile on the
12-
command-line. This is done in [`generate_units`].
12+
command-line. This is done in the [`unit_generator`] module.
1313
3. Starting from the root `Unit`s, generate the [`UnitGraph`] by walking the
1414
dependency graph from the resolver. The `UnitGraph` contains all of the
1515
`Unit` structs, and information about the dependency relationships between
@@ -26,8 +26,8 @@ module. The compilation can be conceptually broken into these steps:
2626
can be used for various things, such as running tests after the compilation
2727
has finished.
2828

29-
[`cargo_compile`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/ops/cargo_compile.rs
30-
[`generate_targets`]: https://github.com/rust-lang/cargo/blob/e4b65bdc80f2a293447f2f6a808fa7c84bf9a357/src/cargo/ops/cargo_compile.rs#L725-L739
29+
[`cargo_compile`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/ops/cargo_compile/mod.rs
30+
[`unit_generator`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/ops/cargo_compile/unit_generator.rs
3131
[`UnitGraph`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/unit_graph.rs
3232
[the resolution chapter]: packages.md
3333
[`Unit`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/unit.rs

0 commit comments

Comments
 (0)