Require opt in to rustc_private
This gives the advantage that A future extension would be to check for `feature(rustc_private)` instead
This commit is contained in:
parent
71a254c1a1
commit
9246df669a
@ -112,7 +112,7 @@ pub struct PackageData {
|
|||||||
|
|
||||||
#[derive(Deserialize, Default, Debug, Clone, Eq, PartialEq)]
|
#[derive(Deserialize, Default, Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct RustAnalyzerPackageMetaData {
|
pub struct RustAnalyzerPackageMetaData {
|
||||||
pub rustc_private: Option<bool>,
|
pub rustc_private: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
|
@ -376,9 +376,10 @@ fn cargo_to_crate_graph(
|
|||||||
cfg_options.insert_atom("debug_assertions".into());
|
cfg_options.insert_atom("debug_assertions".into());
|
||||||
|
|
||||||
let mut pkg_crates = FxHashMap::default();
|
let mut pkg_crates = FxHashMap::default();
|
||||||
|
let mut has_private = false;
|
||||||
// Next, create crates for each package, target pair
|
// Next, create crates for each package, target pair
|
||||||
for pkg in cargo.packages() {
|
for pkg in cargo.packages() {
|
||||||
|
has_private |= cargo[pkg].metadata.rustc_private;
|
||||||
let mut lib_tgt = None;
|
let mut lib_tgt = None;
|
||||||
for &tgt in cargo[pkg].targets.iter() {
|
for &tgt in cargo[pkg].targets.iter() {
|
||||||
if let Some(file_id) = load(&cargo[tgt].root) {
|
if let Some(file_id) = load(&cargo[tgt].root) {
|
||||||
@ -441,11 +442,12 @@ fn cargo_to_crate_graph(
|
|||||||
|
|
||||||
let mut rustc_pkg_crates = FxHashMap::default();
|
let mut rustc_pkg_crates = FxHashMap::default();
|
||||||
|
|
||||||
|
if has_private {
|
||||||
// If the user provided a path to rustc sources, we add all the rustc_private crates
|
// If the user provided a path to rustc sources, we add all the rustc_private crates
|
||||||
// and create dependencies on them for the crates which opt-in to that
|
// and create dependencies on them for the crates which opt-in to that
|
||||||
if let Some(rustc_workspace) = rustc {
|
if let Some(rustc_workspace) = rustc {
|
||||||
// rustc-dev crates start from 'rustc_driver'
|
// rustc-dev crates start from 'rustc_driver'
|
||||||
// Therefore, we collect all crates which are transitive dependencies of rustc_driver
|
// We want to collect all crates which are transitive dependencies of rustc_driver
|
||||||
if let Some(root_pkg) = rustc_workspace
|
if let Some(root_pkg) = rustc_workspace
|
||||||
.packages()
|
.packages()
|
||||||
.find(|package| rustc_workspace[*package].name == "rustc_driver")
|
.find(|package| rustc_workspace[*package].name == "rustc_driver")
|
||||||
@ -453,6 +455,7 @@ fn cargo_to_crate_graph(
|
|||||||
let mut queue = VecDeque::new();
|
let mut queue = VecDeque::new();
|
||||||
queue.push_back(root_pkg);
|
queue.push_back(root_pkg);
|
||||||
while let Some(pkg) = queue.pop_front() {
|
while let Some(pkg) = queue.pop_front() {
|
||||||
|
// Don't duplicate packages
|
||||||
if rustc_pkg_crates.contains_key(&pkg) {
|
if rustc_pkg_crates.contains_key(&pkg) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -467,7 +470,8 @@ fn cargo_to_crate_graph(
|
|||||||
let crate_id = add_target_crate_root(
|
let crate_id = add_target_crate_root(
|
||||||
&mut crate_graph,
|
&mut crate_graph,
|
||||||
&rustc_workspace[pkg],
|
&rustc_workspace[pkg],
|
||||||
rustc_build_data_map.and_then(|it| it.get(&rustc_workspace[pkg].id)),
|
rustc_build_data_map
|
||||||
|
.and_then(|it| it.get(&rustc_workspace[pkg].id)),
|
||||||
&cfg_options,
|
&cfg_options,
|
||||||
proc_macro_loader,
|
proc_macro_loader,
|
||||||
file_id,
|
file_id,
|
||||||
@ -502,10 +506,7 @@ 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() {
|
||||||
let package = &cargo[pkg];
|
let package = &cargo[pkg];
|
||||||
if matches!(
|
if !package.metadata.rustc_private {
|
||||||
(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() {
|
||||||
@ -522,8 +523,7 @@ fn cargo_to_crate_graph(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
eprintln!("No cargo workspace");
|
|
||||||
}
|
}
|
||||||
crate_graph
|
crate_graph
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user