7368: Clarify enabled features and defined features in PackageData r=matklad a=edwin0cheng



Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
This commit is contained in:
bors[bot] 2021-01-21 11:30:38 +00:00 committed by GitHub
commit 64a92e2328
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -99,8 +99,10 @@ pub struct PackageData {
pub dependencies: Vec<PackageDependency>,
/// Rust edition for this package
pub edition: Edition,
/// List of features to activate
pub features: Vec<String>,
/// Features provided by the crate, mapped to the features required by that feature.
pub features: FxHashMap<String, Vec<String>>,
/// List of features enabled on this package
pub active_features: Vec<String>,
/// List of config flags defined by this package's build script
pub cfgs: Vec<CfgFlag>,
/// List of cargo-related environment variables with their value
@ -281,7 +283,8 @@ pub fn from_cargo_metadata(
is_member,
edition,
dependencies: Vec::new(),
features: Vec::new(),
features: meta_pkg.features.into_iter().collect(),
active_features: Vec::new(),
cfgs: cfgs.get(&id).cloned().unwrap_or_default(),
envs: envs.get(&id).cloned().unwrap_or_default(),
out_dir: out_dir_by_id.get(&id).cloned(),
@ -328,7 +331,7 @@ pub fn from_cargo_metadata(
let dep = PackageDependency { name: dep_node.name, pkg };
packages[source].dependencies.push(dep);
}
packages[source].features.extend(node.features);
packages[source].active_features.extend(node.features);
}
let workspace_root = AbsPathBuf::assert(meta.workspace_root);

View File

@ -481,7 +481,7 @@ fn add_target_crate_root(
let edition = pkg.edition;
let cfg_options = {
let mut opts = cfg_options.clone();
for feature in pkg.features.iter() {
for feature in pkg.active_features.iter() {
opts.insert_key_value("feature".into(), feature.into());
}
opts.extend(pkg.cfgs.iter().cloned());