VSCode and Rust

FreeBSD 13.1, fully updated packages and ports.

When trying to run a simple Rust program in VSCode got this error:

Code:
This platform (x64-freebsd) is not suported.

(the typo is not mine).

It seems that the rust-analyzer extension does not work on FreeBSD.

Otherwise cargo works fine, at least for some simple Rust programs.
 
First, use pkg install:
pkg install rust-analyzer
then find the file:
whereis rust-analyzer
always:
/usr/local/bin/rust-analyzer

and then find the vscode extensions directory, like:
~/.vscode-oss/extensions/ust-lang.rust-analyzer-0.3..../server/

cp -f /usr/local/bin/rust-analyzer ~/.vscode-oss/extensions/rust-lang.rust-analyzer-0.3..../server/rust-analyzer

That's ok.
 
"rust-analyzer.server.path": "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rust-analyzer"
Maybe you could try to add this to your settings.json
With the correct path ofc
 
First, you should install rust with rustup, not pkg install.
Then run "$ rustup component add rust-analyzer"
then, check "rust-analyzer --version"
at last, replace "~/.vscode-oss/extensions/ust-lang.rust-analyzer-0.3..../server/rust-analyzer" with "/home/sam/.cargo/bin/rust-analyzer"
 
This trick isn't working. I tried the instructions above.

To be clear, I 'cd' to a folder where commands like 'cargo test' and 'cargo run' work. From there I launch vscode.

I then try to run the code from vscode. From the top menu, Run -> Start Debugging and Run -> Run without Debugging - both of these yield same 'not suported' (sic) error.

I can run cargo commands from the terminal window inside vscode but that's some weak sauce right there.
 
I just got this working, not sure if all the steps are absolutely required though. Here goes:

- Installed Rust and rust-analyzer through pkg. Rust came with some other packages anyway so I left it there.
- Installed Rust in my homedir using rustup.
- Installed the Linux emulation driver: linux_enable="YES" in /etc/rc.conf
- Install linux_base_rl9 through pkg

..and now things work. This may yet bite me in uncomfortable places in the near future, but vscode doesn't dump errors on me anymore.
 
rust-analyzer work fine on FreeBSD, see for instance on emacs.
So definitely an issue with vscode, not the rust-analyzer backend.
(There is a run button and debug for main, I wonder if it is the backend that make it to show up)
 

Attachments

  • rust-lsp.png
    rust-lsp.png
    78.9 KB · Views: 14
Indeed, the issue is with vscode. It feels the need to call onto a Linux binary for rust-analyzer that it has somewhere in its dark underbelly. Giving it what it wants by enabling Linux binary compatibility was a quick way to resolve the errors. I haven't been able to get it to accept the binary in
Code:
/usr/local/bin
yet.
 
Scratch that. Fixed it. You need to find the settings.json that holds your user settings and add a line to it. Mine now looks like this:

Code:
{
    "git.autofetch": true,
    "diffEditor.ignoreTrimWhitespace": false,
    "rust-analyzer.server.path": "/usr/local/bin/rust-analyzer"
}

The file lives in
Code:
~/.config/Code - OSS/User/settings.json
 
Back
Top