Reputation: 1503
I join these two questions in one, as they maybe are related. A few days ago, I started having this error in the [#actix_rt::main] line, before the main function:
proc macro `main` not expanded: cannot find proc-macro server in sysroot `C:\Users\zerok\.rustup\toolchains\stable-x86_64-pc-windows-gnu`
At the same time, in VSCode my rust-analyzer extension started failing. I uninstalled it, restarted VSCode, and reinstalled. It keeps giving the same error over and over:
Failed to spawn one or more proc-macro servers.
How can I fix this problem?
Upvotes: 6
Views: 12779
Reputation: 296
This applies to those who install rust
via macports
that currently does not install the source as well as rustup.
% port search rust-src
rust-src @1.84.0 (lang, devel)
Rust source code for the Rust programming language
% port install rust-src
% port contents rust-src
/opt/local/libexec/rust/src/rustc-1.84.0-src/vendor/yansi-term-0.1.2/src/windows.rs
....
(A list of the source will follow)
Open VS Code settings.
Type sysroot. Navigate to rust-analyzer > cargo
.
Edit in settings.json
"rust-analyzer.cargo.sysrootSrc": "/opt/local/libexec/rust/src/rustc-1.84.0-src"
Of course modify the version string 1.84.0-src
to your situation found in port content rust-src
Upvotes: 0
Reputation: 119
To disable this specifically in VSCode settings, edit your settings.json
configuration for your User:
// @see {@link https://rust-analyzer.github.io/manual.html#unresolved-proc-macro}
"rust-analyzer.diagnostics.disabled": ["unresolved-proc-macro"],
rust-analyzer
$ rustup component add rust-analyzer
$ brew install rust-analyzer
VSCode Rust Analyzer GitHub Tree
Upvotes: 0
Reputation: 345
i had the same issue in VsCode fixed with :
rustup update
rustup component add rust-src
Upvotes: 0
Reputation: 69
My problem was related to a setting on VS Code
"rust-analyzer.cargo.sysroot": "discover"
Don't know how but the above setting was set to null. The default is "discover".
Upvotes: 6
Reputation: 938
I had a different problem that I just figured out. I'm on my work laptop and I had previously installed just
using MacPorts, since I like it but I didn't want to install a full rust toolchain on this machine as we didn't have any Rust projects yet. Now a few months later I installed rustup
and got the warning about there being an outdated preexisting toolchain elsewhere on the machine, which left me super confused because I didn't remember installing it, but I went through with it anyways since I thought I could figure it out. The other answers didn't work for me since I already had rust-src
installed, but after trying to run rustc --print sysroot
and doing a bit of detective work with zsh -xl
thanks to this answer I realized MacPorts was fighting with the rest of my shell config and overriding $PATH
.
So the solution for me was removing the old toolchains (and MacPorts entirely), and confirming that my $PATH
was set up properly. I still couldn't get rust-analyzer to cooperate afterwards, but running rustc --print sysroot
and setting "rust-analyzer.cargo.sysroot": "/path/to/sysroot"
with the output of that command fixed the problem, I just had to restart rust-analyzer afterwards.
Upvotes: 1
Reputation: 111
I had the same problem on Mac, this my error
Failed to spawn one or more proc-macro servers.
- cannot find proc-macro-srv, the workspace
`/Users/xxxx/vscode/rust/guessing_game` is missing a sysroot
Failed to find sysroot for Cargo.toml file
/Users/xxxx/vscode/rust/guessing_game/Cargo.toml. Is rust-src installed?
can't load standard library from sysroot
/Users/xxxx/.rustup/toolchains/stable-x86_64-apple-darwin
(discovered via `rustc --print sysroot`)
try installing the Rust source the same way you installed rustc
here's my fix
# install rust-src
sudo rustup component add rust-src
Upvotes: 6
Reputation: 1503
Soon after posting the question, I finally found out how to install the toolchain, which seems to have fixed both errors:
rustup toolchain install stable-x86_64-pc-windows-gnu
After that, I clicked on the rust-analyzer
box on the bottom of VSCode, clicked in "Restart Server", and everything worked after the command completion.
Upvotes: 5