Skip to content

Commit

Permalink
Add logic for testing implicit binary dependency features.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongmao86 committed Mar 27, 2020
1 parent f1d46e3 commit 8b17895
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
36 changes: 24 additions & 12 deletions src/cargo/core/compiler/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::core::profiles::{Profile, UnitFor};
use crate::core::resolver::features::{FeaturesFor, ResolvedFeatures};
use crate::core::resolver::Resolve;
use crate::core::{InternedString, Package, PackageId, Target};
use crate::ops::resolve_all_features;
use crate::CargoResult;
use log::trace;
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -309,13 +310,20 @@ fn compute_deps<'a, 'cfg>(
.targets()
.iter()
.filter(|t| {
let no_required_features = Vec::new();

t.is_bin() &&
// Skip binaries with required features that have not been selected.
t.required_features().unwrap_or(&no_required_features).iter().all(|f| {
unit.features.contains(&InternedString::new(f.as_str()))
})
// Skip binaries with required features that have not been selected.
match t.required_features() {
Some(rf) if t.is_bin() => {
let features = resolve_all_features(
state.resolve(),
state.features(),
bcx.packages,
id,
);
rf.iter().all(|f| features.contains(f))
}
None if t.is_bin() => true,
_ => false,
}
})
.map(|t| {
new_unit_dep(
Expand Down Expand Up @@ -692,16 +700,20 @@ impl<'a, 'cfg> State<'a, 'cfg> {
}
}

fn features(&self) -> &'a ResolvedFeatures {
if self.is_std {
self.std_features.unwrap()
} else {
self.usr_features
}
}

fn activated_features(
&self,
pkg_id: PackageId,
features_for: FeaturesFor,
) -> Vec<InternedString> {
let features = if self.is_std {
self.std_features.unwrap()
} else {
self.usr_features
};
let features = self.features();
features.activated_features(pkg_id, features_for)
}

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ fn generate_targets<'a>(
///
/// Dependencies are added as `dep_name/feat_name` because `required-features`
/// wants to support that syntax.
fn resolve_all_features(
pub fn resolve_all_features(
resolve_with_overrides: &Resolve,
resolved_features: &features::ResolvedFeatures,
package_set: &PackageSet<'_>,
Expand Down
4 changes: 3 additions & 1 deletion src/cargo/ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub use self::cargo_clean::{clean, CleanOptions};
pub use self::cargo_compile::{compile, compile_with_exec, compile_ws, CompileOptions};
pub use self::cargo_compile::{
compile, compile_with_exec, compile_ws, resolve_all_features, CompileOptions,
};
pub use self::cargo_compile::{CompileFilter, FilterRule, LibRule, Packages};
pub use self::cargo_doc::{doc, DocOptions};
pub use self::cargo_fetch::{fetch, FetchOptions};
Expand Down

0 comments on commit 8b17895

Please sign in to comment.