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?