由于系统配置问题导致 `cargo install` 失败时,如何避免重建依赖关系?

How can I avoid rebuilding dependencies when `cargo install` fails due to a system configuration issue?

我正在尝试 cargo install 一个有很多依赖项的项目。由于某些系统配置问题,后来的依赖项之一无法构建:

cargo install diesel_cli
   ... many dependencies here...
   Compiling diesel_cli v1.4.1
error: linking with `cc` failed: exit code: 1
  |
  = note: ...large output removed...
  = note: ld: library not found for -lmysqlclient
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

一旦我认为我已经解决了系统配置问题,我需要重新运行 cargo install,等待第一组依赖项构建,然后看看我是否得到过去的失败。

如何避免重建所有这些依赖项?

错误消息包含包含失败构建工件的目录:

error: failed to compile `diesel_cli v1.4.1`, intermediate artifacts can be found at `/var/folders/_b/d4_bd15x7s5g99cjvyhpw26w0000gp/T/cargo-installDQOdPD`

您可以通过 --target-dir 选项(或设置 CARGO_TARGET_DIR 环境变量)传递该目录以再次使用它,避免重建依赖关系:

cargo install diesel_cli --target-dir=/var/folders/_b/d4_bd15x7s5g99cjvyhpw26w0000gp/T/cargo-installDQOdPD