mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Add optional target to crates in json project, lookup default cfgs per target when generating cfg list
This commit is contained in:
parent
c815d5b496
commit
db99f2dd7e
3 changed files with 23 additions and 1 deletions
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -246,6 +246,7 @@ impl ProjectWorkspace {
|
|||
let mut crate_graph = CrateGraph::default();
|
||||
match self {
|
||||
ProjectWorkspace::Json { project } => {
|
||||
let mut target_cfg_map = FxHashMap::<Option<&str>, 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(),
|
||||
),
|
||||
|
|
|
@ -31,6 +31,7 @@ pub struct Crate {
|
|||
pub(crate) edition: Edition,
|
||||
pub(crate) deps: Vec<Dependency>,
|
||||
pub(crate) cfg: CfgOptions,
|
||||
pub(crate) target: Option<String>,
|
||||
pub(crate) out_dir: Option<AbsPathBuf>,
|
||||
pub(crate) proc_macro_dylib_path: Option<AbsPathBuf>,
|
||||
}
|
||||
|
@ -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<DepData>,
|
||||
#[serde(default)]
|
||||
cfg: FxHashSet<String>,
|
||||
target: Option<String>,
|
||||
out_dir: Option<PathBuf>,
|
||||
proc_macro_dylib_path: Option<PathBuf>,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue