Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workaround for changing sysroot paths #5586

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions crates/ra_project_model/src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,24 @@ impl Sysroot {
let src = get_or_install_rust_src(cargo_toml)?;
let mut sysroot = Sysroot { crates: Arena::default() };
for name in SYSROOT_CRATES.trim().lines() {
// FIXME: remove this path when 1.47 comes out
// https://github.com/rust-lang/rust/pull/73265
let root = src.join(format!("lib{}", name)).join("lib.rs");
if root.exists() {
sysroot.crates.alloc(SysrootCrateData {
name: name.into(),
root,
deps: Vec::new(),
});
} else {
let root = src.join(name).join("src/lib.rs");
if root.exists() {
sysroot.crates.alloc(SysrootCrateData {
name: name.into(),
root,
deps: Vec::new(),
});
}
}
}
if let Some(std) = sysroot.std() {
Expand Down Expand Up @@ -94,23 +105,38 @@ fn get_or_install_rust_src(cargo_toml: &AbsPath) -> Result<AbsPathBuf> {
rustc.current_dir(current_dir).args(&["--print", "sysroot"]);
let stdout = utf8_stdout(rustc)?;
let sysroot_path = AbsPath::assert(Path::new(stdout.trim()));
let src_path = sysroot_path.join("lib/rustlib/src/rust/src");

if !src_path.exists() {
let mut src = get_rust_src(sysroot_path);
if src.is_none() {
let mut rustup = Command::new(ra_toolchain::rustup());
rustup.current_dir(current_dir).args(&["component", "add", "rust-src"]);
utf8_stdout(rustup)?;
src = get_rust_src(sysroot_path);
}
if !src_path.exists() {
bail!(
match src {
Some(r) => Ok(r),
None => bail!(
"can't load standard library from sysroot\n\
{}\n\
(discovered via `rustc --print sysroot`)\n\
try running `rustup component add rust-src` or set `RUST_SRC_PATH`",
src_path.display(),
)
sysroot_path.display(),
),
}
}

fn get_rust_src(sysroot_path: &AbsPath) -> Option<AbsPathBuf> {
// try the new path first since the old one still exists
let mut src_path = sysroot_path.join("lib/rustlib/src/rust/library");
if !src_path.exists() {
// FIXME: remove this path when 1.47 comes out
// https://github.com/rust-lang/rust/pull/73265
src_path = sysroot_path.join("lib/rustlib/src/rust/src");
}
if src_path.exists() {
Some(src_path)
} else {
None
}
Ok(src_path)
}

impl SysrootCrateData {
Expand Down