Skip to content

Commit 5844dd0

Browse files
bors[bot]lnicola
andauthored
Merge #5586
5586: Add workaround for changing sysroot paths r=jonas-schievink a=lnicola Fixes #5577 Co-authored-by: Laurențiu Nicola <[email protected]>
2 parents 51b18ee + a538e0f commit 5844dd0

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

crates/ra_project_model/src/sysroot.rs

+34-8
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,24 @@ impl Sysroot {
5454
let src = get_or_install_rust_src(cargo_toml)?;
5555
let mut sysroot = Sysroot { crates: Arena::default() };
5656
for name in SYSROOT_CRATES.trim().lines() {
57+
// FIXME: remove this path when 1.47 comes out
58+
// https://github.com/rust-lang/rust/pull/73265
5759
let root = src.join(format!("lib{}", name)).join("lib.rs");
5860
if root.exists() {
5961
sysroot.crates.alloc(SysrootCrateData {
6062
name: name.into(),
6163
root,
6264
deps: Vec::new(),
6365
});
66+
} else {
67+
let root = src.join(name).join("src/lib.rs");
68+
if root.exists() {
69+
sysroot.crates.alloc(SysrootCrateData {
70+
name: name.into(),
71+
root,
72+
deps: Vec::new(),
73+
});
74+
}
6475
}
6576
}
6677
if let Some(std) = sysroot.std() {
@@ -94,23 +105,38 @@ fn get_or_install_rust_src(cargo_toml: &AbsPath) -> Result<AbsPathBuf> {
94105
rustc.current_dir(current_dir).args(&["--print", "sysroot"]);
95106
let stdout = utf8_stdout(rustc)?;
96107
let sysroot_path = AbsPath::assert(Path::new(stdout.trim()));
97-
let src_path = sysroot_path.join("lib/rustlib/src/rust/src");
98-
99-
if !src_path.exists() {
108+
let mut src = get_rust_src(sysroot_path);
109+
if src.is_none() {
100110
let mut rustup = Command::new(ra_toolchain::rustup());
101111
rustup.current_dir(current_dir).args(&["component", "add", "rust-src"]);
102112
utf8_stdout(rustup)?;
113+
src = get_rust_src(sysroot_path);
103114
}
104-
if !src_path.exists() {
105-
bail!(
115+
match src {
116+
Some(r) => Ok(r),
117+
None => bail!(
106118
"can't load standard library from sysroot\n\
107119
{}\n\
108120
(discovered via `rustc --print sysroot`)\n\
109121
try running `rustup component add rust-src` or set `RUST_SRC_PATH`",
110-
src_path.display(),
111-
)
122+
sysroot_path.display(),
123+
),
124+
}
125+
}
126+
127+
fn get_rust_src(sysroot_path: &AbsPath) -> Option<AbsPathBuf> {
128+
// try the new path first since the old one still exists
129+
let mut src_path = sysroot_path.join("lib/rustlib/src/rust/library");
130+
if !src_path.exists() {
131+
// FIXME: remove this path when 1.47 comes out
132+
// https://github.com/rust-lang/rust/pull/73265
133+
src_path = sysroot_path.join("lib/rustlib/src/rust/src");
134+
}
135+
if src_path.exists() {
136+
Some(src_path)
137+
} else {
138+
None
112139
}
113-
Ok(src_path)
114140
}
115141

116142
impl SysrootCrateData {

0 commit comments

Comments
 (0)