Skip to content

Commit 5c3ef9b

Browse files
committed
internal: Add unstable config for loading the sysroot sources via cargo metadata
1 parent 9d8889c commit 5c3ef9b

File tree

8 files changed

+386
-234
lines changed

8 files changed

+386
-234
lines changed

crates/base-db/src/input.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ impl CrateOrigin {
157157
pub fn is_lib(&self) -> bool {
158158
matches!(self, CrateOrigin::Library { .. })
159159
}
160+
161+
pub fn is_lang(&self) -> bool {
162+
matches!(self, CrateOrigin::Lang { .. })
163+
}
160164
}
161165

162166
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -174,7 +178,7 @@ impl From<&str> for LangCrateOrigin {
174178
match s {
175179
"alloc" => LangCrateOrigin::Alloc,
176180
"core" => LangCrateOrigin::Core,
177-
"proc-macro" => LangCrateOrigin::ProcMacro,
181+
"proc-macro" | "proc_macro" => LangCrateOrigin::ProcMacro,
178182
"std" => LangCrateOrigin::Std,
179183
"test" => LangCrateOrigin::Test,
180184
_ => LangCrateOrigin::Other,
@@ -522,12 +526,6 @@ impl CrateGraph {
522526
self.arena.iter().map(|(idx, _)| idx)
523527
}
524528

525-
// FIXME: used for `handle_hack_cargo_workspace`, should be removed later
526-
#[doc(hidden)]
527-
pub fn iter_mut(&mut self) -> impl Iterator<Item = (CrateId, &mut CrateData)> + '_ {
528-
self.arena.iter_mut()
529-
}
530-
531529
/// Returns an iterator over all transitive dependencies of the given crate,
532530
/// including the crate itself.
533531
pub fn transitive_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId> {
@@ -619,7 +617,12 @@ impl CrateGraph {
619617
/// This will deduplicate the crates of the graph where possible.
620618
/// Note that for deduplication to fully work, `self`'s crate dependencies must be sorted by crate id.
621619
/// If the crate dependencies were sorted, the resulting graph from this `extend` call will also have the crate dependencies sorted.
622-
pub fn extend(&mut self, mut other: CrateGraph, proc_macros: &mut ProcMacroPaths) {
620+
pub fn extend(
621+
&mut self,
622+
mut other: CrateGraph,
623+
proc_macros: &mut ProcMacroPaths,
624+
on_finished: impl FnOnce(&FxHashMap<CrateId, CrateId>),
625+
) {
623626
let topo = other.crates_in_topological_order();
624627
let mut id_map: FxHashMap<CrateId, CrateId> = FxHashMap::default();
625628
for topo in topo {
@@ -670,6 +673,8 @@ impl CrateGraph {
670673

671674
*proc_macros =
672675
mem::take(proc_macros).into_iter().map(|(id, macros)| (id_map[&id], macros)).collect();
676+
677+
on_finished(&id_map);
673678
}
674679

675680
fn find_path(

crates/project-model/src/cargo_workspace.rs

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ pub struct CargoConfig {
8282
pub target: Option<String>,
8383
/// Sysroot loading behavior
8484
pub sysroot: Option<RustLibSource>,
85+
/// Whether to invoke `cargo metadata` on the sysroot crate.
86+
pub sysroot_query_metadata: bool,
8587
pub sysroot_src: Option<AbsPathBuf>,
8688
/// rustc private crate source
8789
pub rustc_source: Option<RustLibSource>,

0 commit comments

Comments
 (0)