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

rust-analyzer failed to load workspace #4172

Closed
Redoubts opened this issue Apr 27, 2020 · 66 comments
Closed

rust-analyzer failed to load workspace #4172

Redoubts opened this issue Apr 27, 2020 · 66 comments

Comments

@Redoubts
Copy link

I installed rust with brew on MacOS, and I'm noticing this error on a hello world project with VS Code:

rust-analyzer failed to load workspace: 
    Failed to find sysroot for Cargo.toml file ./rust_new/Cargo.toml. 
    Is rust-src installed?: rustup component add rust-src failed

I didn't install with rustup, and I figured I wouldn't need to. This suggests I must, but why? Does this suggest I need the complier source to use your package in my editor?

@lnicola
Copy link
Member

lnicola commented Apr 27, 2020

rust-src is the standard library, not compiler source code. rust-analyzer needs it to know what the standard library types are.

@Redoubts
Copy link
Author

Isn't that rust-std? Rust's homepage describes rust-src as the Rust source code.

https://github.com/rust-lang/rustup#can-rustup-download-the-rust-source-code

@bjorn3
Copy link
Member

bjorn3 commented Apr 27, 2020

rust-src is the source code of the standard library. rust-std is the compiled version of the standard library.

@zdcthomas
Copy link

Hey,
I just upgraded to the newest rust-analyzer version, and I've just started having the same issue.

  • I'm using nvim with coc-rust-analyzer
  • I've run rustup update
  • Ive run rustup comonent add rust-src
    the only thing left that I can think of doing is setting RUST_SRC_PATH but I'm not sure what to set that to/why I only now have to set it.

@bjorn3
Copy link
Member

bjorn3 commented Apr 27, 2020

What is the output of ls $(rustc --print sysroot)/lib/rustlib/src/rust/src? For me it is:

build_helper  libcore         libpanic_unwind  libprofiler_builtins  librustc_asan  librustc_msan  libstd     libterm  libunwind  tools
liballoc      libpanic_abort  libproc_macro    librustc              librustc_lsan  librustc_tsan  libsyntax  libtest  stdarch

@zdcthomas
Copy link

it seems like I only have the path up to lib/rustlib I don't have src/rust/src, should I reinstall stuff? What I have in rustlib is

components                              manifest-rustc
etc                                     rust-installer-version
manifest-rust-docs                      x86_64-apple-darwin
manifest-rust-std-x86_64-apple-darwin

@zdcthomas
Copy link

Quick update, I uninstalled all of the rust toolchain, and then reinstalled and the issue has gone away

@matklad
Copy link
Member

matklad commented Apr 29, 2020

Closing the issue, as it seems to be the problem with local toolchain installation. it would be awesome if we could diagnose and warn about this on our side, but I doubt we can provide info more useful then the existing error message.

@matklad matklad closed this as completed Apr 29, 2020
@woelper
Copy link

woelper commented Sep 6, 2020

I have the same issue with nightly-x86_64-unknown-linux-gnu (1.48.0-nightly) on ubintu linux and vs code. I have completely uninstalled rust and reinstalled, but I get

rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /mnt/md2/woelper/dircpy/Cargo.toml.
Is rust-src installed?:
can't load standard library from sysroot /home/woelper/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src (discovered via `rustc --print sysroot`)
try running `rustup component add rust-src` or set `RUST_SRC_PATH`

running rustup component add rust-src yields info: component 'rust-src' is up to date.

it looks like I am missing the src folder: ls /home/woelper/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust shows just Cargo.lock library.

$(rustc --print sysroot) points to /home/woelper/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu, which does exist.

I should add that this is a VS code remote session, maybe this complicates things?

@bjorn3
Copy link
Member

bjorn3 commented Sep 6, 2020

Try rustup component add rust-src --toolchain nightly.

@woelper
Copy link

woelper commented Sep 6, 2020

rustup component add rust-src --toolchain nightly

Thanks for your reply, this produces the following result:

rustup component add rust-src --toolchain nightly
info: component 'rust-src' is up to date

@woelper
Copy link

woelper commented Sep 8, 2020

I am able to reproduce this with Mac OS 10.15.6 and 1.48.0-nightly as well:

rust-analyzer failed to load workspace:
Failed to find sysroot for Cargo.toml file /Users/woelper/catapult-imgui/Cargo.toml. Is rust-src installed?
Caused by: can't load standard library from sysroot /Users/woelper/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src (discovered via `rustc --print sysroot`) try running `rustup component add rust-src` or set `RUST_SRC_PATH`

I also ran rustup component add rust-src --toolchain nightly, which caused info: component 'rust-src' is up to date

@jondot
Copy link

jondot commented Sep 11, 2020

rust-src changed the path layout, which is the source of the problem.

September:

image

August:
image

@jondot
Copy link

jondot commented Sep 11, 2020

Lastly, this should be fixed if you take recent version from master:
6b8bc13#diff-30888fefce138d15c65ceb40b37b7ad2R146

@lnicola
Copy link
Member

lnicola commented Sep 12, 2020

This should have been fixed in #5586.

@jondot
Copy link

jondot commented Sep 12, 2020

Thanks @lnicola I feel that maybe the official extension isn't picking up that change yet, which causes the breakage, even though everything should work by now. That's why I build and install from source.

@granddaifuku
Copy link

I still have the same issue with MacOS 10.15.6, 1.48.0-nightly even I build and install from source.

There's only Cargo.lock, library
Here's what I got.

$ cd $(rustc --print sysroot)/lib/rustlib/src/rust
$ ls
Cargo.lock	library
$ rustup component add rust-src --toolchain nightly
info: component 'rust-src' is up to date

@jondot
Copy link

jondot commented Sep 13, 2020

I believe at this stage its just a matter of verifying that you actually use rust-analyzer from source (first uninstall from your VSCode, then install)

@granddaifuku
Copy link

My rust environment is not working, so I decided to uninstall and reinstall entire rust system.
However I still struggling with this issue.

Emacs version 27.1(9.0)

Here's what I did.

~ % curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 
~ % rustup install nightly
~ %  rustup default nightly
~ % git clone https://github.com/rust-analyzer/rust-analyzer.git && cd rust-analyzer
rust-analyzer % cargo xtask install --server
~ % rustup component add rust-src

Emacs lsp says

LSP :: Connected to [rust-analyzer:94373 status:starting]. [2 times]
LSP :: rust-analyzer:94373 initialized successfully
LSP :: rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /Users/yufuku/Develop/Rust/hello/Cargo.toml. Is rust-src installed?: could not find libcore in sysroot path `/Users/yufuku/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src`
LSP :: Error from the Language Server: Rust Analyzer is still loading... (Unknown error) [4 times]
$(rustc --print sysroot)/lib/rustlib/src/rust  % ls
Cargo.lock	library

There's no src directory.

@rsignavong
Copy link

rsignavong commented Sep 16, 2020

It's not working for me too.
The latest release 0d03fe6 is trying to load libcore from rust-src/src from rustc stable version but it doesn't read the rust-src/library folder in rustcnightly version

@avocade
Copy link

avocade commented Oct 8, 2020

Just running rustup component add rust-src worked fine for me with latest macOS catalina.

@luiswirth
Copy link

luiswirth commented Oct 9, 2020

I'm having the same problem too on Arch Linux. Maybe the rust-src path changes ever so often?

I think the path for me is $(rustc --print sysroot)/lib/rustlib/src/rust/library/std/src or is this something else?

@lnicola
Copy link
Member

lnicola commented Oct 9, 2020

@LU15W1R7H the path changed only once (recently), and while rust-analyzer supports both locations, for that to work you must unset RUST_SRC_PATH. See the discussion in #6178.

@stardiviner
Copy link

stardiviner commented Oct 30, 2020

I got same problem on Arch Linux.

Here is the error log in Emacs buffer *rust-analyzer::stderr*:

[ERROR rust_analyzer::reload] failed to load workspace: Failed to find sysroot for Cargo.toml file /home/stardiviner/Documents/learning/Rust/hello/Cargo.toml. Is rust-src installed?: could not find libcore in sysroot path `/home/stardiviner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src`

I create a test project using command cargo new hello-world.

Did uninstall & reinstall nightly toolchain, and here is the output of command:

$ ls $(rustc --print sysroot)/lib/rustlib/src/rust/src

llvm-project

And I execute command:

$ rustup update && rustup component add rust-src

info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: latest update on 2020-10-30, rust version 1.49.0-nightly (6bdae9edd 2020-10-29)
info: skipping nightly which is missing installed components 'rls-preview', 'rustfmt-preview'
info: syncing channel updates for 'nightly-2020-10-29-x86_64-unknown-linux-gnu'
info: latest update on 2020-10-29, rust version 1.49.0-nightly (31ee872db 2020-10-28)
info: skipping nightly which is missing installed components 'rls-preview', 'rustfmt-preview'
info: syncing channel updates for 'nightly-2020-10-28-x86_64-unknown-linux-gnu'
info: latest update on 2020-10-28, rust version 1.49.0-nightly (07e968b64 2020-10-27)
info: skipping nightly which is missing installed components 'rls-preview', 'rustfmt-preview'
info: syncing channel updates for 'nightly-2020-10-27-x86_64-unknown-linux-gnu'
info: latest update on 2020-10-27, rust version 1.49.0-nightly (fd542592f 2020-10-26)
info: skipping nightly which is missing installed components 'rls-preview', 'rustfmt-preview'
info: syncing channel updates for 'nightly-2020-10-26-x86_64-unknown-linux-gnu'
info: latest update on 2020-10-26, rust version 1.49.0-nightly (4760b8fb8 2020-10-25)
info: skipping nightly which is missing installed components 'rls-preview', 'rustfmt-preview'
info: syncing channel updates for 'nightly-2020-10-25-x86_64-unknown-linux-gnu'

  nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)

info: cleaning up downloads & tmp directories
info: component 'rust-src' is up to date

I have following setting in ~/.zshrc:

export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"

@lnicola
Copy link
Member

lnicola commented Oct 30, 2020

@stardiviner try to unset RUST_SRC_PATH and check what which rust-analyzer prints.

@stardiviner
Copy link

stardiviner commented Oct 30, 2020

@lnicola After unset RUST_SRC_PATH, The command which rust-analyzer points to /usr/bin/rust-analyzer.
It seems from my Arch Linux installed package rust-analyzer.

@lnicola
Copy link
Member

lnicola commented Oct 30, 2020

That's strange, recent versions print a "RUST_SRC_PATH might be incorrect, try unsetting it" message if the variable is set.

Anyway, is it working now? I think RUST_SRC_PATH should point to the sysroot, not to the source code directory, but it generally works without the variable.

@stardiviner
Copy link

Still not work.
Same error:

[ERROR rust_analyzer::reload] failed to load workspace: Failed to find sysroot for Cargo.toml file /home/stardiviner/Documents/learning/Rust/hello/Cargo.toml. Is rust-src installed?: could not find libcore in sysroot path `/home/stardiviner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src`

I'm sure I installed rust-src component. But why I don't have libcore in sysroot path? I checked the upper path. I found I only have llvm-project directory. Is this correct and normal?

@rabdulatipoff
Copy link

rabdulatipoff commented Nov 8, 2020

You should unset RUST_SRC_PATH.

It probably should have worked. My build of Emacs (master) got a bit further when loading rust-analyzer and complained about exactly that when I unsetted the env var in a bash session. When I have restarted it without the RUST_SRC_PATH variable ever being set due the session, the issue persists.

Edit: I've encountered some peculiar behavior of Emacs with regards to this env variable. While RUST_SRC_PATH is not set anywhere in the system environment, emacs has this variable set for some odd reason (I can echo it in the M-x shell, nowhere else).

@kushaldas
Copy link

I don't have RUST_SRC_PATH set, tried to use both auto downloaded via coc-rust-analyzer, and local build:

rust-analyzer e8c8039

Same error.

@stardiviner
Copy link

@kushaldas Can you provide more info about your system and editor etc? and try to get env variable info from editor.

@flodiebold
Copy link
Member

Edit: I've encountered some peculiar behavior of Emacs with regards to this env variable. While RUST_SRC_PATH is not set anywhere in the system environment, emacs has this variable set for some odd reason (I can echo it in the M-x shell, nowhere else).

If you're using Spacemacs, it has this thing where it saves the environment in a file and reproduces it from there (see ~/.spacemacs.env). Or if you're not, maybe there's something similar going on. We're ignoring RUST_SRC_PATH now if it doesn't contain core though, so it shouldn't matter much anymore.

Same error.

Please post the exact error message you're getting, and the output from rustc --print sysroot in your project directory.

@kushaldas
Copy link

kushaldas commented Nov 14, 2020

@kushaldas Can you provide more info about your system and editor etc? and try to get env variable info from editor.

I am using neovim and coc-rust-analyzer. After fighting for the whole day, I removed all rust* from the system, and did a fresh install. Now everything is again working. Thank you for the help.

@uWynell
Copy link

uWynell commented Nov 19, 2020

@kushaldas Can you provide more info about your system and editor etc? and try to get env variable info from editor.

I am using neovim and coc-rust-analyzer. After fighting for the whole day, I removed all rust* from the system, and did a fresh install. Now everything is again working. Thank you for the help.

How did you install rust? I'm just experiencing the same issue now

@IgnisDa
Copy link

IgnisDa commented Jun 18, 2021

I encountered this problem when using rust in a custom alpine docker image. The following solved it.

RUN sudo apk del cargo rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

@soraiemame
Copy link

I want to use rustc 1.42.0 and I am getting the same error. I installed rust with rustup on Windows10.

rust-toolchain

1.42.0-x86_64-pc-windows-gnu

$ rustup toolchain list

stable-x86_64-pc-windows-gnu (default)
nightly-x86_64-pc-windows-gnu
1.42.0-x86_64-pc-windows-gnu (override)
rust-analyzer v0.2.853

I have tried

  • $ rustup component add --toolchain 1.42.0-x86_64-pc-windows-gnu rust-src
  • $ rustup component add rust-src

but rust-analyzer shows me the same error.

@lnicola
Copy link
Member

lnicola commented Jan 9, 2022

@soraiemame the sysroot (rust-src) structure changed in 1.47 and we only support that and newer versions.

@soraiemame
Copy link

Thank you for responding. I did not know that. I will use the stable toolchain for now then.

@hom
Copy link

hom commented Mar 23, 2022

In Windows system I try to install below and resolved:

scoop install rustup

@Integralist
Copy link

For anyone jumping to the end of this thread, the solution for me (mentioned here) was:

export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"

@pluveto
Copy link

pluveto commented Apr 15, 2022

export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"

for /etc/profile or ~/.zshrc or ~/.bashrc not working for me.

ls $(rustc --print sysroot)/lib/rustlib/src/rust/src
build_helper libpanic_abort libprofiler_builtins libtest tools
liballoc libpanic_unwind libstd libunwind
libcore libproc_macro libterm stdarch

@HoikanChan
Copy link

Same issues, just run rustup update, fixed it

@lnicola
Copy link
Member

lnicola commented Apr 30, 2022

@pluveto which Rust version are you on?

@pluveto
Copy link

pluveto commented May 1, 2022

@pluveto which Rust version are you on?

latest nightly when I post. finally I reinstalled my os and fixed it. this may be a issue with some other software

@Dequog
Copy link

Dequog commented Jul 25, 2022

After trying various things up above, I uninstalled and reinstalled vscode which fixed the problem for me.

@Jeklah
Copy link

Jeklah commented Jul 26, 2022

I ran into this problem installing rust_analyser.
I installed rustup, used that to install stable toolchain.
Ran rustup which rustc which showed a different version to what rustc -V showed.
Ran apt-get remove rustc to remove invalid install.
Checked with running rustc -V again, which now matched rustup.

After that, the rust_analyser error disappeared and clippy kicked into action.

@BruceGuanFF
Copy link

Hey, I just upgraded to the newest rust-analyzer version, and I've just started having the same issue.

  • I'm using nvim with coc-rust-analyzer
  • I've run rustup update
  • Ive run rustup comonent add rust-src
    the only thing left that I can think of doing is setting RUST_SRC_PATH but I'm not sure what to set that to/why I only now have to set it.

it works after running rustup component add rust-src

@ffanyq
Copy link

ffanyq commented Oct 9, 2022

I have sloved this problem after I copy the folder
".\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library" to the
".\nightly-2020-05-10-x86_64-pc-windows-msvc\lib\rustlib\src\rust"

(nightly-x86_64-pc-windows-msvc and nightly-2020-05-10-x86_64-pc-windows-msvc both are in the sysroot folder).

The reason of the problem is the version error of rustup, as above, it can't identified the old version toolchains' folder path layout.

@whu-geocat
Copy link

I have the same issue with nightly-x86_64-unknown-linux-gnu (1.48.0-nightly) on ubintu linux and vs code. I have completely uninstalled rust and reinstalled, but I get

rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /mnt/md2/woelper/dircpy/Cargo.toml.
Is rust-src installed?:
can't load standard library from sysroot /home/woelper/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src (discovered via `rustc --print sysroot`)
try running `rustup component add rust-src` or set `RUST_SRC_PATH`

running rustup component add rust-src yields info: component 'rust-src' is up to date.

it looks like I am missing the src folder: ls /home/woelper/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust shows just Cargo.lock library.

$(rustc --print sysroot) points to /home/woelper/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu, which does exist.

I should add that this is a VS code remote session, maybe this complicates things?

+1

@fritzrehde
Copy link

I had this problem on Arch Linux too, and solved it with sudo pacman -R rust. So, for some reason unknown to me, rust was installed by the systems package manager and rustup, so deleting the version installed by pacman has solved my problems.

@keks
Copy link

keks commented Dec 19, 2022

On manjaro linux I was able to resolve this by using the vscodium-bin package from AUR instead of the code package from community.

@Jayuda
Copy link

Jayuda commented Jan 8, 2023

I had this problem on Arch Linux too, and solved it with sudo pacman -R rust. So, for some reason unknown to me, rust was installed by the systems package manager and rustup, so deleting the version installed by pacman has solved my problems.

Yes its work like a charm.

@AndhikaWB
Copy link

This is a bit off-topic but in case you're using offline installer where rustup is not available, you can download rust-src directly using this URL format: https://static.rust-lang.org/dist/YYYY-MM-DD/rust-src-X.X.X.tar.gz.

Check release date and version from this page (latest release only). Example link for v1.71.0: https://static.rust-lang.org/dist/2023-07-13/rust-src-1.71.0.tar.gz.

@EugeneChung
Copy link

rustup component add rust-src doesn't work for me, neither.
As @AndhikaWB mentioned, I manually set up rust-src from https://static.rust-lang.org/dist/2023-12-07/rust-src-1.74.1.tar.gz.

@lpnh
Copy link

lpnh commented Dec 13, 2023

I had this problem on Arch Linux too, and solved it with sudo pacman -R rust. So, for some reason unknown to me, rust was installed by the systems package manager and rustup, so deleting the version installed by pacman has solved my problems.

For anyone who might be experiencing "the workspace is missing a sysroot" issue, the solution mentioned above worked perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests