diff options
-rw-r--r-- | crates/ra_project_model/src/sysroot.rs | 32 | ||||
-rw-r--r-- | docs/user/README.md | 1 |
2 files changed, 22 insertions, 11 deletions
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 2a7927f7e..0c27d4f4b 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | use std::{ | 1 | use std::{ |
2 | env, | ||
2 | path::{Path, PathBuf}, | 3 | path::{Path, PathBuf}, |
3 | process::Command, | 4 | process::Command, |
4 | }; | 5 | }; |
@@ -33,21 +34,13 @@ impl Sysroot { | |||
33 | } | 34 | } |
34 | 35 | ||
35 | pub fn discover(cargo_toml: &Path) -> Result<Sysroot> { | 36 | pub fn discover(cargo_toml: &Path) -> Result<Sysroot> { |
36 | let rustc_output = Command::new("rustc") | 37 | let src = try_find_src_path(cargo_toml)?; |
37 | .current_dir(cargo_toml.parent().unwrap()) | 38 | |
38 | .args(&["--print", "sysroot"]) | ||
39 | .output()?; | ||
40 | if !rustc_output.status.success() { | ||
41 | Err("failed to locate sysroot")? | ||
42 | } | ||
43 | let stdout = String::from_utf8(rustc_output.stdout)?; | ||
44 | let sysroot_path = Path::new(stdout.trim()); | ||
45 | let src = sysroot_path.join("lib/rustlib/src/rust/src"); | ||
46 | if !src.exists() { | 39 | if !src.exists() { |
47 | Err(format!( | 40 | Err(format!( |
48 | "can't load standard library from sysroot\n\ | 41 | "can't load standard library from sysroot\n\ |
49 | {:?}\n\ | 42 | {:?}\n\ |
50 | try running `rustup component add rust-src`", | 43 | try running `rustup component add rust-src` or set `RUST_SRC_PATH`", |
51 | src, | 44 | src, |
52 | ))?; | 45 | ))?; |
53 | } | 46 | } |
@@ -83,6 +76,23 @@ impl Sysroot { | |||
83 | } | 76 | } |
84 | } | 77 | } |
85 | 78 | ||
79 | fn try_find_src_path(cargo_toml: &Path) -> Result<PathBuf> { | ||
80 | if let Ok(path) = env::var("RUST_SRC_PATH") { | ||
81 | return Ok(path.into()); | ||
82 | } | ||
83 | |||
84 | let rustc_output = Command::new("rustc") | ||
85 | .current_dir(cargo_toml.parent().unwrap()) | ||
86 | .args(&["--print", "sysroot"]) | ||
87 | .output()?; | ||
88 | if !rustc_output.status.success() { | ||
89 | Err("failed to locate sysroot")?; | ||
90 | } | ||
91 | let stdout = String::from_utf8(rustc_output.stdout)?; | ||
92 | let sysroot_path = Path::new(stdout.trim()); | ||
93 | Ok(sysroot_path.join("lib/rustlib/src/rust/src")) | ||
94 | } | ||
95 | |||
86 | impl SysrootCrate { | 96 | impl SysrootCrate { |
87 | pub fn name(self, sysroot: &Sysroot) -> &str { | 97 | pub fn name(self, sysroot: &Sysroot) -> &str { |
88 | &sysroot.crates[self].name | 98 | &sysroot.crates[self].name |
diff --git a/docs/user/README.md b/docs/user/README.md index 7990d1d31..453e8e273 100644 --- a/docs/user/README.md +++ b/docs/user/README.md | |||
@@ -78,6 +78,7 @@ See https://github.com/microsoft/vscode/issues/72308[microsoft/vscode#72308] for | |||
78 | (e.g: `--features="shumway,pdf"` will run as `cargo watch -x "check --features="shumway,pdf""` ) | 78 | (e.g: `--features="shumway,pdf"` will run as `cargo watch -x "check --features="shumway,pdf""` ) |
79 | * `rust-analyzer.trace.server`: enables internal logging | 79 | * `rust-analyzer.trace.server`: enables internal logging |
80 | * `rust-analyzer.trace.cargo-watch`: enables cargo-watch logging | 80 | * `rust-analyzer.trace.cargo-watch`: enables cargo-watch logging |
81 | * `RUST_SRC_PATH`: environment variable that overwrites the sysroot | ||
81 | 82 | ||
82 | 83 | ||
83 | ## Emacs | 84 | ## Emacs |