From a538e0fbe815a4543f3b547d7a20469bebc2e3ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Thu, 30 Jul 2020 15:04:41 +0300 Subject: Add workaround for changing sysroot paths --- crates/ra_project_model/src/sysroot.rs | 42 +++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'crates/ra_project_model/src/sysroot.rs') diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 8a92acea5..9e23b5805 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs @@ -54,6 +54,8 @@ 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 { @@ -61,6 +63,15 @@ impl Sysroot { 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() { @@ -94,23 +105,38 @@ fn get_or_install_rust_src(cargo_toml: &AbsPath) -> Result { 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 { + // 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 { -- cgit v1.2.3 From afd02461bcb9bccd9372352dc9115209753fee4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Thu, 30 Jul 2020 17:17:59 +0300 Subject: Update sysroot crates --- crates/ra_project_model/src/sysroot.rs | 48 ++++++++++++---------------------- 1 file changed, 17 insertions(+), 31 deletions(-) (limited to 'crates/ra_project_model/src/sysroot.rs') diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 9e23b5805..a10ade375 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs @@ -146,42 +146,28 @@ impl SysrootCrateData { } const SYSROOT_CRATES: &str = " -std -core alloc -collections -libc -proc_macro -rustc_unicode -std_unicode -test -alloc_jemalloc -alloc_system -compiler_builtins -getopts -panic_unwind +core panic_abort -rand +panic_unwind +proc_macro +profiler_builtins +rtstartup +std +stdarch term -unwind -build_helper -rustc_asan -rustc_lsan -rustc_msan -rustc_tsan -syntax"; +test +unwind"; const STD_DEPS: &str = " alloc -alloc_jemalloc -alloc_system core panic_abort -rand -compiler_builtins -unwind -rustc_asan -rustc_lsan -rustc_msan -rustc_tsan -build_helper"; +panic_unwind +profiler_builtins +rtstartup +proc_macro +stdarch +term +test +unwind"; -- cgit v1.2.3