mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Make sysroot use RUST_SRC_PATH
if set
This commit is contained in:
parent
08e5d394df
commit
18c7a1ebe7
2 changed files with 22 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
|
env,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Command,
|
process::Command,
|
||||||
};
|
};
|
||||||
|
@ -33,21 +34,13 @@ impl Sysroot {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn discover(cargo_toml: &Path) -> Result<Sysroot> {
|
pub fn discover(cargo_toml: &Path) -> Result<Sysroot> {
|
||||||
let rustc_output = Command::new("rustc")
|
let src = try_find_src_path(cargo_toml)?;
|
||||||
.current_dir(cargo_toml.parent().unwrap())
|
|
||||||
.args(&["--print", "sysroot"])
|
|
||||||
.output()?;
|
|
||||||
if !rustc_output.status.success() {
|
|
||||||
Err("failed to locate sysroot")?
|
|
||||||
}
|
|
||||||
let stdout = String::from_utf8(rustc_output.stdout)?;
|
|
||||||
let sysroot_path = Path::new(stdout.trim());
|
|
||||||
let src = sysroot_path.join("lib/rustlib/src/rust/src");
|
|
||||||
if !src.exists() {
|
if !src.exists() {
|
||||||
Err(format!(
|
Err(format!(
|
||||||
"can't load standard library from sysroot\n\
|
"can't load standard library from sysroot\n\
|
||||||
{:?}\n\
|
{:?}\n\
|
||||||
try running `rustup component add rust-src`",
|
try running `rustup component add rust-src` or set `RUST_SRC_PATH`",
|
||||||
src,
|
src,
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
|
@ -83,6 +76,23 @@ impl Sysroot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn try_find_src_path(cargo_toml: &Path) -> Result<PathBuf> {
|
||||||
|
if let Ok(path) = env::var("RUST_SRC_PATH") {
|
||||||
|
return Ok(path.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let rustc_output = Command::new("rustc")
|
||||||
|
.current_dir(cargo_toml.parent().unwrap())
|
||||||
|
.args(&["--print", "sysroot"])
|
||||||
|
.output()?;
|
||||||
|
if !rustc_output.status.success() {
|
||||||
|
Err("failed to locate sysroot")?;
|
||||||
|
}
|
||||||
|
let stdout = String::from_utf8(rustc_output.stdout)?;
|
||||||
|
let sysroot_path = Path::new(stdout.trim());
|
||||||
|
Ok(sysroot_path.join("lib/rustlib/src/rust/src"))
|
||||||
|
}
|
||||||
|
|
||||||
impl SysrootCrate {
|
impl SysrootCrate {
|
||||||
pub fn name(self, sysroot: &Sysroot) -> &str {
|
pub fn name(self, sysroot: &Sysroot) -> &str {
|
||||||
&sysroot.crates[self].name
|
&sysroot.crates[self].name
|
||||||
|
|
|
@ -78,6 +78,7 @@ See https://github.com/microsoft/vscode/issues/72308[microsoft/vscode#72308] for
|
||||||
(e.g: `--features="shumway,pdf"` will run as `cargo watch -x "check --features="shumway,pdf""` )
|
(e.g: `--features="shumway,pdf"` will run as `cargo watch -x "check --features="shumway,pdf""` )
|
||||||
* `rust-analyzer.trace.server`: enables internal logging
|
* `rust-analyzer.trace.server`: enables internal logging
|
||||||
* `rust-analyzer.trace.cargo-watch`: enables cargo-watch logging
|
* `rust-analyzer.trace.cargo-watch`: enables cargo-watch logging
|
||||||
|
* `RUST_SRC_PATH`: environment variable that overwrites the sysroot
|
||||||
|
|
||||||
|
|
||||||
## Emacs
|
## Emacs
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue