mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +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> {
|
pub struct Arena<ID: ArenaId, T> {
|
||||||
data: Vec<T>,
|
data: Vec<T>,
|
||||||
_ty: PhantomData<ID>,
|
_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_export]
|
||||||
macro_rules! impl_arena_id {
|
macro_rules! impl_arena_id {
|
||||||
($name:ident) => {
|
($name:ident) => {
|
||||||
|
|
|
@ -4,13 +4,24 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use ra_syntax::SmolStr;
|
use ra_syntax::SmolStr;
|
||||||
use rustc_hash::FxHashMap;
|
use ra_arena::{Arena, RawId, impl_arena_id};
|
||||||
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Sysroot {
|
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 {
|
impl Sysroot {
|
||||||
|
@ -26,53 +37,73 @@ impl Sysroot {
|
||||||
let sysroot_path = Path::new(stdout.trim());
|
let sysroot_path = Path::new(stdout.trim());
|
||||||
let src = sysroot_path.join("lib/rustlib/src/rust/src");
|
let src = sysroot_path.join("lib/rustlib/src/rust/src");
|
||||||
|
|
||||||
let crates: &[(&str, &[&str])] = &[
|
let mut sysroot = Sysroot {
|
||||||
(
|
crates: Arena::default(),
|
||||||
"std",
|
};
|
||||||
&[
|
for name in SYSROOT_CRATES.trim().lines() {
|
||||||
"alloc_jemalloc",
|
let path = src.join(format!("lib{}", name)).join("lib.rs");
|
||||||
"alloc_system",
|
if path.exists() {
|
||||||
"panic_abort",
|
sysroot.crates.alloc(SysrootCrateData {
|
||||||
"rand",
|
name: name.into(),
|
||||||
"compiler_builtins",
|
path,
|
||||||
"unwind",
|
deps: Vec::new(),
|
||||||
"rustc_asan",
|
});
|
||||||
"rustc_lsan",
|
}
|
||||||
"rustc_msan",
|
}
|
||||||
"rustc_tsan",
|
if let Some(std) = sysroot.by_name("std") {
|
||||||
"build_helper",
|
for dep in STD_DEPS.trim().lines() {
|
||||||
],
|
if let Some(dep) = sysroot.by_name(dep) {
|
||||||
),
|
sysroot.crates[std].deps.push(dep)
|
||||||
("core", &[]),
|
}
|
||||||
("alloc", &[]),
|
}
|
||||||
("collections", &[]),
|
}
|
||||||
("libc", &[]),
|
Ok(sysroot)
|
||||||
("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", &[]),
|
|
||||||
];
|
|
||||||
|
|
||||||
Ok(Sysroot {
|
fn by_name(&self, name: &str) -> Option<SysrootCrate> {
|
||||||
crates: FxHashMap::default(),
|
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…
Add table
Add a link
Reference in a new issue