最近我注意到,随着我对项目所做的每一次更改,
cargo build
都会重新编译大量依赖项。我使用详细选项运行构建,我发现它是由使用 x11-dl
的 pkg-config
引起的。
Dirty x11-dl v2.21.0: the env variable PKG_CONFIG_PATH changed
Compiling x11-dl v2.21.0
2023-11-28T16:00:29.568162Z DEBUG cargo::core::compiler::fingerprint: new local fingerprints deps "/home/m2johnson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/x11-dl-2.21.0"
2023-11-28T16:00:29.568527Z DEBUG cargo::core::compiler::fingerprint: write fingerprint (59a258ee54e4dd64) : /home/m2johnson/project/target/debug/.fingerprint/x11-dl-63f654e4528e2978/run-build-script-build-script-build
Running `/home/m2johnson/.rustup/toolchains/1.73.0-x86_64-unknown-linux-gnu/bin/rustc --crate-name x11_dl --edition=2021 /home/m2johnson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/x11-dl-2.21.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=309 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=on -C metadata=a622a30e33ea17c3 -C extra-filename=-a622a30e33ea17c3 --out-dir /home/m2johnson/project/target/debug/deps -C linker=clang -L dependency=/home/m2johnson/project/target/debug/deps --extern libc=/home/m2johnson/project/target/debug/deps/liblibc-eaa316218c225a80.rmeta --extern once_cell=/home/m2johnson/project/target/debug/deps/libonce_cell-d50086842dfc3ee6.rmeta --cap-lints allow -C link-arg=-fuse-ld=lld -l dl`
我尝试过的:
PKG_CONFIG_PATH
和 build.rs
文件,它们是相同的。vscode
并完全从终端跑了。这did似乎停止了重新编译。我想这意味着 vscode
(rust-analyser
) 正在修改 PKG_CONFIG_PATH
或者它在启动时没有读取值(即清除它)。那么,变化检测是如何工作的呢?到目前为止,我已将其追溯到here,但尚未了解发生了什么。
这是 Rust 1.73.0
rustc 1.73.0 (cc66ad468 2023-10-03)
我遇到了类似的问题,大量依赖项被不必要地重新编译。对我来说,当我在 vscode 中禁用 rust-analyzer 时,它就被修复了,但这并不理想。
对我来说更好的解决方案是从命令菜单运行任务
rust: cargo run
(与单击主 fn 上方的运行按钮相同)。
这解决了这个问题。
您还可以为此创建快捷方式:
{
"key": "ctrl+[Backslash] r",
"command": "workbench.action.tasks.runTask",
"args": "rust: cargo run"
}