From ac3ec18f4b25bd254437a232bc835629162e1380 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 21 Jan 2021 19:12:19 +0800 Subject: Added defined_features in PackageData --- crates/project_model/src/cargo_workspace.rs | 11 +++++++---- crates/project_model/src/workspace.rs | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs index c0ed37fc1..a09e1a9ff 100644 --- a/crates/project_model/src/cargo_workspace.rs +++ b/crates/project_model/src/cargo_workspace.rs @@ -99,8 +99,10 @@ pub struct PackageData { pub dependencies: Vec, /// Rust edition for this package pub edition: Edition, - /// List of features to activate - pub features: Vec, + /// Features provided by the crate, mapped to the features required by that feature. + pub features: FxHashMap>, + /// List of features enabled on this package + pub active_features: Vec, /// List of config flags defined by this package's build script pub cfgs: Vec, /// List of cargo-related environment variables with their value @@ -281,7 +283,8 @@ impl CargoWorkspace { 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 @@ impl CargoWorkspace { 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); diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index 8e0481ae9..073c48af7 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs @@ -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()); -- cgit v1.2.3