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