仅在一个特定项目上使用 Rust-Analyzer 时,VS Code 错误“无法运行构建脚本”
2023-02-13
1002
我的公司刚刚为我正在开发的 Rust 项目启用了一个新的 repo,并将其与 Tauri 项目合并,现在 VS Code 给了我这个错误:
Failed to run build scripts
我可以编译、运行我的项目或使用
cargo check
查看警告/错误,但 Rust Analyzer 不起作用,每次我需要检查代码时都要运行
cargo check
,这很烦人。
此错误仅发生在此 repo 中,其中包含一个分为两个文件夹的 Rust 工作区:一个 Tauri/Rust 项目和一个基本 Rust 项目。
Cargo.toml
在根目录:
[workspace]
members = [
"builder",
"studio/src-tauri"
]
错误详情:
[ERROR rust_analyzer::lsp_utils] failed to run build scripts:
The following warnings were emitted during compilation:
error: failed to run custom build command for `cairo-sys-rs v0.15.1`
Caused by:
process didn't exit successfully: `/home/korocouille/Sogilis/IReflex/reflex2/target/debug/build/cairo-sys-rs-decf14405d906ced/build-script-build` (exit status: 1)
--- stdout
cargo:rerun-if-env-changed=CAIRO_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
cargo:warning=`"pkg-config" "--libs" "--cflags" "cairo" "cairo >= 1.14"` did not exit successfully: exit status: 1
error: could not find system library 'cairo' required by the 'cairo-sys-rs' crate
--- stderr
Package cairo was not found in the pkg-config search path.
Perhaps you should add the directory containing `cairo.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cairo' found
Package cairo was not found in the pkg-config search path.
Perhaps you should add the directory containing `cairo.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cairo' found
我尝试卸载并重新安装 Rust-Analyzer,切换到预发布或更旧的版本,删除我的目标文件夹,运行
cargo clean
cmd 但没有任何变化,我找不到任何解决方案。
2个回答
如果您使用的是 Windows,请搜索“环境变量”,然后单击右下角名为“环境变量”的按钮。 然后单击用户变量中的路径,然后单击编辑。 然后只需添加不带代码和“的路径
希望它有所帮助
编辑:我本来想添加为评论,但我没有足够的代表来这样做。
Morten Lindhard Hedegaard
2023-03-14
我遇到了同样的问题。 这是因为来自 export-esp.ps1 脚本的环境路径只是临时添加的。
所以我在 Windows 中手动添加了它们。现在它似乎可以正常工作了。
Morten Lindhard Hedegaard
2023-03-12