aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/project_model/sysroot.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/project_model/sysroot.rs')
-rw-r--r--crates/ra_lsp_server/src/project_model/sysroot.rs78
1 files changed, 78 insertions, 0 deletions
diff --git a/crates/ra_lsp_server/src/project_model/sysroot.rs b/crates/ra_lsp_server/src/project_model/sysroot.rs
index e69de29bb..ae72c9c17 100644
--- a/crates/ra_lsp_server/src/project_model/sysroot.rs
+++ b/crates/ra_lsp_server/src/project_model/sysroot.rs
@@ -0,0 +1,78 @@
1use std::{
2 path::{Path, PathBuf},
3 process::Command,
4};
5
6use ra_syntax::SmolStr;
7use rustc_hash::FxHashMap;
8
9use crate::Result;
10
11#[derive(Debug, Clone)]
12pub struct Sysroot {
13 crates: FxHashMap<SmolStr, PathBuf>,
14}
15
16impl Sysroot {
17 pub(crate) fn discover(cargo_toml: &Path) -> Result<Sysroot> {
18 let rustc_output = Command::new("rustc")
19 .current_dir(cargo_toml.parent().unwrap())
20 .args(&["--print", "sysroot"])
21 .output()?;
22 if !rustc_output.status.success() {
23 failure::bail!("failed to locate sysroot")
24 }
25 let stdout = String::from_utf8(rustc_output.stdout)?;
26 let sysroot_path = Path::new(stdout.trim());
27 let src = sysroot_path.join("lib/rustlib/src/rust/src");
28
29 let crates: &[(&str, &[&str])] = &[
30 (
31 "std",
32 &[
33 "alloc_jemalloc",
34 "alloc_system",
35 "panic_abort",
36 "rand",
37 "compiler_builtins",
38 "unwind",
39 "rustc_asan",
40 "rustc_lsan",
41 "rustc_msan",
42 "rustc_tsan",
43 "build_helper",
44 ],
45 ),
46 ("core", &[]),
47 ("alloc", &[]),
48 ("collections", &[]),
49 ("libc", &[]),
50 ("panic_unwind", &[]),
51 ("proc_macro", &[]),
52 ("rustc_unicode", &[]),
53 ("std_unicode", &[]),
54 ("test", &[]),
55 // Feature gated
56 ("alloc_jemalloc", &[]),
57 ("alloc_system", &[]),
58 ("compiler_builtins", &[]),
59 ("getopts", &[]),
60 ("panic_unwind", &[]),
61 ("panic_abort", &[]),
62 ("rand", &[]),
63 ("term", &[]),
64 ("unwind", &[]),
65 // Dependencies
66 ("build_helper", &[]),
67 ("rustc_asan", &[]),
68 ("rustc_lsan", &[]),
69 ("rustc_msan", &[]),
70 ("rustc_tsan", &[]),
71 ("syntax", &[]),
72 ];
73
74 Ok(Sysroot {
75 crates: FxHashMap::default(),
76 })
77 }
78}