Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/project-model/src/lib.rs')
-rw-r--r--crates/project-model/src/lib.rs58
1 files changed, 52 insertions, 6 deletions
diff --git a/crates/project-model/src/lib.rs b/crates/project-model/src/lib.rs
index 92bf6a08f8..4fa70508bb 100644
--- a/crates/project-model/src/lib.rs
+++ b/crates/project-model/src/lib.rs
@@ -15,9 +15,8 @@
//! procedural macros).
//! * Lowering of concrete model to a [`base_db::CrateGraph`]
-mod build_scripts;
+mod build_dependencies;
mod cargo_workspace;
-mod cfg;
mod env;
mod manifest_path;
pub mod project_json;
@@ -37,16 +36,15 @@ use std::{
};
use anyhow::{bail, format_err, Context};
-use paths::{AbsPath, AbsPathBuf};
+use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
use rustc_hash::FxHashSet;
pub use crate::{
- build_scripts::WorkspaceBuildScripts,
+ build_dependencies::WorkspaceBuildScripts,
cargo_workspace::{
CargoConfig, CargoFeatures, CargoWorkspace, Package, PackageData, PackageDependency,
RustLibSource, Target, TargetData, TargetKind,
},
- cfg::CfgOverrides,
manifest_path::ManifestPath,
project_json::{ProjectJson, ProjectJsonData},
sysroot::Sysroot,
@@ -68,6 +66,9 @@ impl ProjectManifest {
if path.file_name().unwrap_or_default() == "rust-project.json" {
return Ok(ProjectManifest::ProjectJson(path));
}
+ if path.file_name().unwrap_or_default() == ".rust-project.json" {
+ return Ok(ProjectManifest::ProjectJson(path));
+ }
if path.file_name().unwrap_or_default() == "Cargo.toml" {
return Ok(ProjectManifest::CargoToml(path));
}
@@ -94,6 +95,9 @@ impl ProjectManifest {
if let Some(project_json) = find_in_parent_dirs(path, "rust-project.json") {
return Ok(vec![ProjectManifest::ProjectJson(project_json)]);
}
+ if let Some(project_json) = find_in_parent_dirs(path, ".rust-project.json") {
+ return Ok(vec![ProjectManifest::ProjectJson(project_json)]);
+ }
return find_cargo_toml(path)
.map(|paths| paths.into_iter().map(ProjectManifest::CargoToml).collect());
@@ -132,8 +136,11 @@ impl ProjectManifest {
.filter_map(Result::ok)
.map(|it| it.path().join("Cargo.toml"))
.filter(|it| it.exists())
+ .map(Utf8PathBuf::from_path_buf)
+ .filter_map(Result::ok)
.map(AbsPathBuf::try_from)
- .filter_map(|it| it.ok()?.try_into().ok())
+ .filter_map(Result::ok)
+ .filter_map(|it| it.try_into().ok())
.collect()
}
}
@@ -192,3 +199,42 @@ pub enum InvocationLocation {
#[default]
Workspace,
}
+
+/// A set of cfg-overrides per crate.
+#[derive(Default, Debug, Clone, Eq, PartialEq)]
+pub struct CfgOverrides {
+ /// A global set of overrides matching all crates.
+ pub global: cfg::CfgDiff,
+ /// A set of overrides matching specific crates.
+ pub selective: rustc_hash::FxHashMap<String, cfg::CfgDiff>,
+}
+
+impl CfgOverrides {
+ pub fn len(&self) -> usize {
+ self.global.len() + self.selective.values().map(|it| it.len()).sum::<usize>()
+ }
+
+ pub fn apply(&self, cfg_options: &mut cfg::CfgOptions, name: &str) {
+ if !self.global.is_empty() {
+ cfg_options.apply_diff(self.global.clone());
+ };
+ if let Some(diff) = self.selective.get(name) {
+ cfg_options.apply_diff(diff.clone());
+ };
+ }
+}
+
+fn parse_cfg(s: &str) -> Result<cfg::CfgAtom, String> {
+ let res = match s.split_once('=') {
+ Some((key, value)) => {
+ if !(value.starts_with('"') && value.ends_with('"')) {
+ return Err(format!("Invalid cfg ({s:?}), value should be in quotes"));
+ }
+ let key = intern::Symbol::intern(key);
+ let value = intern::Symbol::intern(&value[1..value.len() - 1]);
+ cfg::CfgAtom::KeyValue { key, value }
+ }
+ None => cfg::CfgAtom::Flag(intern::Symbol::intern(s)),
+ };
+ Ok(res)
+}