Rust Analyzer does not check project with custom build Rust correctly

Our wasi related project requires a custom built of Rust, so I build Rust with ./x.py build --stage 1 library and a custom config.toml, in a folder say MY_RUST_FOLDER, and use environments to override configures to make it compile with this custom version of Rust:

WASI_SDK=****
WASI_SDK_PATH=****
CC=****
RUST_WASI_TOOLCHAIN=****
RUSTC=****

and it worked for compiling from command lines.

To have type checking in VS Code, I have Rust Analyzer with project level settings:

{
  "editor.formatOnSave": true,
  "rust-analyzer.cargo.extraEnv": {
    "WASI_SDK": "{MY_KIT}//wasi-sdk-24.0-arm64-macos/",
    "WASI_SDK_PATH": "{MY_KIT}/wasi-sdk-24.0-arm64-macos/",
    "RUST_WASI_TOOLCHAIN": "{MY_RUST_FOLDER}",
    "CC": "{MY_KIT}/wasi-sdk-24.0-arm64-macos/bin/clang --sysroot={MY_KIT}/wasi-sdk-24.0-arm64-macos/share/wasi-sysroot",
    "CFLAGS": "--sysroot={MY_KIT}/wasi-sdk-24.0-arm64-macos/share/wasi-sysroot",
    "RUSTUP_TOOLCHAIN": "{MY_RUST_FOLDER}/build/aarch64-apple-darwin/stage1"
  },
  "rust-analyzer.server.extraEnv": {
    "CC": "{MY_KIT}//wasi-sdk-24.0-arm64-macos/bin/clang",
    "CFLAGS": "--sysroot={MY_KIT}//kit/wasi-sdk-24.0-arm64-macos/share/wasi-sysroot"
  },
  "rust-analyzer.rustc.path": "{MY_RUST_FOLDER}/build/host/stage1/bin/rustc",
  "rust-analyzer.rustc.source": "{MY_RUST_FOLDER}/build/host/stage1/lib/rustlib/src/rust/",
  "rust-analyzer.check.overrideCommand": [
    "cargo",
    "check",
    "--message-format=json"
  ],
  "rust-analyzer.check.targets": ["wasm32-wasip1"]
}
rustup show # latest info
Default host: aarch64-apple-darwin
rustup home:  {MY_HOME}/.rustup

installed toolchains
--------------------

nightly-aarch64-apple-darwin
1.81.0-aarch64-apple-darwin (default)
my-custom-toolchain

installed targets for active toolchain
--------------------------------------

aarch64-apple-darwin
wasm32-wasip1

active toolchain
----------------

1.81.0-aarch64-apple-darwin (default)
rustc 1.81.0 (eeb90cda1 2024-09-04) # installed 1.82 a while back, then removed...
rustup toolchain list # latest info
nightly-aarch64-apple-darwin
1.81.0-aarch64-apple-darwin (default)
my-custom-toolchain

it worked in first weeks, but recently(can't figure out why and after which change), it broke and got errors for all macros in VS code,

rquickjs::class: failed to build proc-macrorust-analyzermacro-error

also error message is noticed from LSP outputs:

2025-03-05T18:46:50.392243+08:00 ERROR FetchBuildDataError: error: "{MY_RUST_FOLDER}}/build/aarch64-apple-darwin/stage1/lib/rustlib/src/rust/library/Cargo.lock" does not exist, unable to build with the standard library, try:
        rustup component add rust-src --toolchain {MY_RUST_FOLDER}}/build/aarch64-apple-darwin/stage1

the message does not really fix my problem

error: error: invalid value '{MY_RUST_FOLDER}/build/aarch64-apple-darwin/stage1' for '--toolchain <toolchain>': invalid toolchain name: '/{MY_RUST_FOLDER}/build/aarch64-apple-darwin/stage1'

How to figure out what's the real problem here? Any other information I should check?

/Users/jon.chen/work/container/rust/build/aarch64-apple-darwin/stage1 is not a valid value for a toolchain name. You can however do rustup toolchain link stage1 /Users/jon.chen/work/container/rust/build/aarch64-apple-darwin/stage1 and then use stage1 as toolchain name instead.

not sure if I understand that correctly, but stage1 still appears an invalid name,

$ rustup toolchain list
nightly-aarch64-apple-darwin
1.81.0-aarch64-apple-darwin (default)
my-custom-toolchain
stage1

$ rustup component add rust-src --toolchain stage1
error: error: invalid value 'stage1' for '--toolchain <toolchain>': invalid toolchain name: 'stage1'

For more information, try '--help'.
: invalid toolchain name: 'stage1'

You should skip the rustup component add rust-src --toolchain stage1. The rust-src component is already installed for locally built toolchains. And rustup component add can't work for locally built toolchains as there is nowhere to download components from.

...which means the locally built toolchain is already installed and should already work?

If you set RUSTUP_TOOLCHAIN to stage1 it should work.

1 Like

only got to bypass failed to build proc-macrorust-analyzer macro-error with settings by now:

  "rust-analyzer.procMacro.attributes.enable": false,
  "rust-analyzer.procMacro.derive.enable": false,
  "rust-analyzer.procMacro.enable": false,

at least I got unneccesary warnings hidden.

another issue I noticed that my custom built Rust is 1.81 , and Rust analyzer auto updated and breaks for many 1.81 projects, so I have to switch back to some xxx.2308 version to get it compatible with my local Rust.

that error src/rust/library/Cargo.lock" does not exist, unable to build with the standard library still exists, but rust analyzer got to work in many std functions.

didn't try building 1.82+ locally for now.