From db99f2dd7e8e244b858926bbf1d2a49e25f44733 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Fri, 12 Jun 2020 13:08:51 -0400 Subject: Add optional target to crates in json project, lookup default cfgs per target when generating cfg list --- crates/ra_cfg/src/lib.rs | 10 ++++++++++ crates/ra_project_model/src/lib.rs | 11 ++++++++++- crates/ra_project_model/src/project_json.rs | 3 +++ 3 files changed, 23 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_cfg/src/lib.rs b/crates/ra_cfg/src/lib.rs index 57feabcb2..f9c73ece1 100644 --- a/crates/ra_cfg/src/lib.rs +++ b/crates/ra_cfg/src/lib.rs @@ -46,4 +46,14 @@ impl CfgOptions { pub fn insert_key_value(&mut self, key: SmolStr, value: SmolStr) { self.key_values.insert((key, value)); } + + pub fn append(&mut self, other: &CfgOptions) { + for atom in &other.atoms { + self.atoms.insert(atom.clone()); + } + + for (key, value) in &other.key_values { + self.key_values.insert((key.clone(), value.clone())); + } + } } diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 464c3b2e3..4b50b9b69 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -246,6 +246,7 @@ impl ProjectWorkspace { let mut crate_graph = CrateGraph::default(); match self { ProjectWorkspace::Json { project } => { + let mut target_cfg_map = FxHashMap::, CfgOptions>::default(); let crates: FxHashMap<_, _> = project .crates .iter() @@ -265,6 +266,14 @@ impl ProjectWorkspace { .proc_macro_dylib_path .clone() .map(|it| proc_macro_client.by_dylib_path(&it)); + + let target = krate.target.as_deref(); + let target_cfgs = target_cfg_map + .entry(target.clone()) + .or_insert_with(|| get_rustc_cfg_options(target.as_deref())); + let mut cfg_options = krate.cfg.clone(); + cfg_options.append(target_cfgs); + // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env Some(( CrateId(seq_index as u32), @@ -273,7 +282,7 @@ impl ProjectWorkspace { krate.edition, // FIXME json definitions can store the crate name None, - krate.cfg.clone(), + cfg_options, env, proc_macro.unwrap_or_default(), ), diff --git a/crates/ra_project_model/src/project_json.rs b/crates/ra_project_model/src/project_json.rs index b0fe09333..b96227949 100644 --- a/crates/ra_project_model/src/project_json.rs +++ b/crates/ra_project_model/src/project_json.rs @@ -31,6 +31,7 @@ pub struct Crate { pub(crate) edition: Edition, pub(crate) deps: Vec, pub(crate) cfg: CfgOptions, + pub(crate) target: Option, pub(crate) out_dir: Option, pub(crate) proc_macro_dylib_path: Option, } @@ -65,6 +66,7 @@ impl ProjectJson { } cfg }, + target: crate_data.target, out_dir: crate_data.out_dir.map(|it| base.join(it)), proc_macro_dylib_path: crate_data.proc_macro_dylib_path.map(|it| base.join(it)), }) @@ -86,6 +88,7 @@ struct CrateData { deps: Vec, #[serde(default)] cfg: FxHashSet, + target: Option, out_dir: Option, proc_macro_dylib_path: Option, } -- cgit v1.2.3 From 5b96d4103ea25a2dbb9811b082365ff77a89c94d Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Sat, 4 Jul 2020 13:50:27 -0400 Subject: Fallback to target in cfg if not specified in project json config --- crates/ra_project_model/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 4b50b9b69..5d1f871c4 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -267,7 +267,7 @@ impl ProjectWorkspace { .clone() .map(|it| proc_macro_client.by_dylib_path(&it)); - let target = krate.target.as_deref(); + let target = krate.target.as_deref().or(target); let target_cfgs = target_cfg_map .entry(target.clone()) .or_insert_with(|| get_rustc_cfg_options(target.as_deref())); -- cgit v1.2.3