gpt4 book ai didi

Rust 应用程序编译失败,因为缺少 CARGO_MANIFEST_DIR 环境变量

转载 作者:行者123 更新时间:2023-11-29 08:34:46 25 4
gpt4 key购买 nike

我最近向我的 Rust 应用程序添加了一个依赖项,其中包含一个过程宏。此过程宏使用 i18n_codegen::i18n!("locales"); 调用。它将在相对于 CARGO_MANIFEST_DIRlocales 目录中找到所有文件。据我了解,CARGO_MANIFEST_DIR 是您箱子的根目录,由 Cargo 设置。

这在本地运行良好,但当我尝试在我的 CI 服务器上构建它时,它失败并显示以下消息:

root@9eb2477f8a48:~# cd ./project/
root@9eb2477f8a48:~/project# cargo build --tests
Compiling i18n v0.1.0 (/root/project/i18n)
Compiling diesel-factories v0.0.1
Compiling rocket_contrib v0.4.0
error: Could not compile `i18n`.

Caused by:
process didn't exit successfully: `rustc --edition=2018 --crate-name i18n i18n/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=7a0984ff3e085e3a -C extra-filename=-7a0984ff3e085e3a --out-dir /root/project/target/debug/deps -C incremental=/root/project/target/debug/incremental -L dependency=/root/project/target/debug/deps --extern i18n_codegen=/root/project/target/debug/deps/libi18n_codegen-85460420d23be67d.so` (signal: 9, SIGKILL: kill)
warning: build failed, waiting for other jobs to finish...
error: Could not compile `i18n`.

运行 rustc 命令给出

root@9eb2477f8a48:~/project# rustc --edition=2018 --crate-name i18n i18n/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=7a0984ff3e085e3a -C extra-filename=-7a0984ff3e085e3a --out-dir /root/project/target/debug/deps -C incremental=/root/project/target/debug/incremental -L dependency=/root/project/target/debug/deps --extern i18n_codegen=/root/project/target/debug/deps/libi18n_codegen-85460420d23be67d.so
error: proc macro panicked
--> i18n/src/lib.rs:1:1
|
1 | i18n_codegen::i18n!("locales");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: message: Env var `CARGO_MANIFEST_DIR` was missing

error: aborting due to previous error

好像 CARGO_MANIFEST_DIR 不见了……怎么会这样?我以为那总是由 Cargo 设置的?我猜直接运行rustc可能会丢失,但是运行cargo build --tests怎么可能也丢失呢?

找到环境变量的代码在这里https://github.com/davidpdrsn/i18n_codegen/blob/master/src/lib.rs#L233 .

主应用程序本身是一个 Cargo 工作区,里面还有一些其他的 crate ,不确定这是否重要。

我每晚在本地和 CI 上使用相同版本的 Rust。

这是一个封闭源代码的工作项目,所以很遗憾我不能轻易分享它。

最佳答案

第一个和第二个错误无关:

  1. 失败是因为进程从“某个地方”被杀死(评论似乎已经解决了这个问题)。
  2. 失败,因为 CARGO_MANIFEST_DIR 是由 cargo 设置的,所以如果你手动运行 rustc 你必须自己设置变量,一般尽量不要运行rustc 完全手动。

关于Rust 应用程序编译失败,因为缺少 CARGO_MANIFEST_DIR 环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55420475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com