Implement opt-in (and opt-out) rustc_private
This commit is contained in:
parent
cd60c4f76c
commit
1076d21fc0
@ -9,6 +9,8 @@
|
||||
use la_arena::{Arena, Idx};
|
||||
use paths::{AbsPath, AbsPathBuf};
|
||||
use rustc_hash::FxHashMap;
|
||||
use serde::Deserialize;
|
||||
use serde_json::from_value;
|
||||
|
||||
use crate::build_data::BuildDataConfig;
|
||||
use crate::utf8_stdout;
|
||||
@ -104,6 +106,13 @@ pub struct PackageData {
|
||||
pub active_features: Vec<String>,
|
||||
// String representation of package id
|
||||
pub id: String,
|
||||
// The contents of [package.metadata.rust-analyzer]
|
||||
pub metadata: RustAnalyzerPackageMetaData,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default, Debug, Clone, Eq, PartialEq)]
|
||||
pub struct RustAnalyzerPackageMetaData {
|
||||
pub rustc_private: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
@ -161,6 +170,13 @@ pub fn root(&self) -> &AbsPath {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
// Deserialise helper for the cargo metadata
|
||||
struct PackageMetadata {
|
||||
#[serde(rename = "rust-analyzer")]
|
||||
rust_analyzer: Option<RustAnalyzerPackageMetaData>,
|
||||
}
|
||||
|
||||
impl CargoWorkspace {
|
||||
pub fn from_cargo_metadata(
|
||||
cargo_toml: &AbsPath,
|
||||
@ -244,8 +260,10 @@ pub fn from_cargo_metadata(
|
||||
|
||||
meta.packages.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
for meta_pkg in &meta.packages {
|
||||
let cargo_metadata::Package { id, edition, name, manifest_path, version, .. } =
|
||||
meta_pkg;
|
||||
let cargo_metadata::Package {
|
||||
id, edition, name, manifest_path, version, metadata, ..
|
||||
} = meta_pkg;
|
||||
let meta = from_value::<PackageMetadata>(metadata.clone()).unwrap_or_default();
|
||||
let is_member = ws_members.contains(&id);
|
||||
let edition = edition
|
||||
.parse::<Edition>()
|
||||
@ -262,6 +280,7 @@ pub fn from_cargo_metadata(
|
||||
dependencies: Vec::new(),
|
||||
features: meta_pkg.features.clone().into_iter().collect(),
|
||||
active_features: Vec::new(),
|
||||
metadata: meta.rust_analyzer.unwrap_or_default(),
|
||||
});
|
||||
let pkg_data = &mut packages[pkg];
|
||||
pkg_by_id.insert(id, pkg);
|
||||
|
@ -499,7 +499,11 @@ fn cargo_to_crate_graph(
|
||||
|
||||
if let Some(&to) = pkg_to_lib_crate.get(&dep) {
|
||||
for pkg in cargo.packages() {
|
||||
if !cargo[pkg].is_member {
|
||||
let package = &cargo[pkg];
|
||||
if matches!(
|
||||
(package.is_member, package.metadata.rustc_private),
|
||||
(true, Some(false)) | (false, Some(false)) | (false, None)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
for &from in pkg_crates.get(&pkg).into_iter().flatten() {
|
||||
|
Loading…
Reference in New Issue
Block a user