mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
use arena for sysroot
This commit is contained in:
parent
66fba88534
commit
8852408bfb
2 changed files with 90 additions and 50 deletions
|
@ -35,12 +35,21 @@ impl fmt::Display for RawId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct Arena<ID: ArenaId, T> {
|
||||
data: Vec<T>,
|
||||
_ty: PhantomData<ID>,
|
||||
}
|
||||
|
||||
impl<ID: ArenaId, T: fmt::Debug> fmt::Debug for Arena<ID, T> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt.debug_struct("Arena")
|
||||
.field("len", &self.len())
|
||||
.field("data", &self.data)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_arena_id {
|
||||
($name:ident) => {
|
||||
|
|
|
@ -4,13 +4,24 @@ use std::{
|
|||
};
|
||||
|
||||
use ra_syntax::SmolStr;
|
||||
use rustc_hash::FxHashMap;
|
||||
use ra_arena::{Arena, RawId, impl_arena_id};
|
||||
|
||||
use crate::Result;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Sysroot {
|
||||
crates: FxHashMap<SmolStr, PathBuf>,
|
||||
crates: Arena<SysrootCrate, SysrootCrateData>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct SysrootCrate(RawId);
|
||||
impl_arena_id!(SysrootCrate);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct SysrootCrateData {
|
||||
name: SmolStr,
|
||||
path: PathBuf,
|
||||
deps: Vec<SysrootCrate>,
|
||||
}
|
||||
|
||||
impl Sysroot {
|
||||
|
@ -26,53 +37,73 @@ impl Sysroot {
|
|||
let sysroot_path = Path::new(stdout.trim());
|
||||
let src = sysroot_path.join("lib/rustlib/src/rust/src");
|
||||
|
||||
let crates: &[(&str, &[&str])] = &[
|
||||
(
|
||||
"std",
|
||||
&[
|
||||
"alloc_jemalloc",
|
||||
"alloc_system",
|
||||
"panic_abort",
|
||||
"rand",
|
||||
"compiler_builtins",
|
||||
"unwind",
|
||||
"rustc_asan",
|
||||
"rustc_lsan",
|
||||
"rustc_msan",
|
||||
"rustc_tsan",
|
||||
"build_helper",
|
||||
],
|
||||
),
|
||||
("core", &[]),
|
||||
("alloc", &[]),
|
||||
("collections", &[]),
|
||||
("libc", &[]),
|
||||
("panic_unwind", &[]),
|
||||
("proc_macro", &[]),
|
||||
("rustc_unicode", &[]),
|
||||
("std_unicode", &[]),
|
||||
("test", &[]),
|
||||
// Feature gated
|
||||
("alloc_jemalloc", &[]),
|
||||
("alloc_system", &[]),
|
||||
("compiler_builtins", &[]),
|
||||
("getopts", &[]),
|
||||
("panic_unwind", &[]),
|
||||
("panic_abort", &[]),
|
||||
("rand", &[]),
|
||||
("term", &[]),
|
||||
("unwind", &[]),
|
||||
// Dependencies
|
||||
("build_helper", &[]),
|
||||
("rustc_asan", &[]),
|
||||
("rustc_lsan", &[]),
|
||||
("rustc_msan", &[]),
|
||||
("rustc_tsan", &[]),
|
||||
("syntax", &[]),
|
||||
];
|
||||
let mut sysroot = Sysroot {
|
||||
crates: Arena::default(),
|
||||
};
|
||||
for name in SYSROOT_CRATES.trim().lines() {
|
||||
let path = src.join(format!("lib{}", name)).join("lib.rs");
|
||||
if path.exists() {
|
||||
sysroot.crates.alloc(SysrootCrateData {
|
||||
name: name.into(),
|
||||
path,
|
||||
deps: Vec::new(),
|
||||
});
|
||||
}
|
||||
}
|
||||
if let Some(std) = sysroot.by_name("std") {
|
||||
for dep in STD_DEPS.trim().lines() {
|
||||
if let Some(dep) = sysroot.by_name(dep) {
|
||||
sysroot.crates[std].deps.push(dep)
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(sysroot)
|
||||
}
|
||||
|
||||
Ok(Sysroot {
|
||||
crates: FxHashMap::default(),
|
||||
})
|
||||
fn by_name(&self, name: &str) -> Option<SysrootCrate> {
|
||||
self.crates
|
||||
.iter()
|
||||
.find(|(_id, data)| data.name == name)
|
||||
.map(|(id, _data)| id)
|
||||
}
|
||||
}
|
||||
|
||||
const SYSROOT_CRATES: &str = "
|
||||
std
|
||||
core
|
||||
alloc
|
||||
collections
|
||||
libc
|
||||
panic_unwind
|
||||
proc_macro
|
||||
rustc_unicode
|
||||
std_unicode
|
||||
test
|
||||
alloc_jemalloc
|
||||
alloc_system
|
||||
compiler_builtins
|
||||
getopts
|
||||
panic_unwind
|
||||
panic_abort
|
||||
rand
|
||||
term
|
||||
unwind
|
||||
build_helper
|
||||
rustc_asan
|
||||
rustc_lsan
|
||||
rustc_msan
|
||||
rustc_tsan
|
||||
syntax";
|
||||
|
||||
const STD_DEPS: &str = "
|
||||
alloc_jemalloc
|
||||
alloc_system
|
||||
panic_abort
|
||||
rand
|
||||
compiler_builtins
|
||||
unwind
|
||||
rustc_asan
|
||||
rustc_lsan
|
||||
rustc_msan
|
||||
rustc_tsan
|
||||
build_helper";
|
||||
|
|
Loading…
Reference in a new issue