diff --git a/crates/ra_cfg/src/lib.rs b/crates/ra_cfg/src/lib.rs index 57feabcb27..f9c73ece14 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 464c3b2e3e..4b50b9b697 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 b0fe093335..b962279496 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, }