簡體   English   中英

由於缺少CARGO_MANIFEST_DIR環境變量,Rust應用程序無法編譯

[英]Rust app failes to compile because CARGO_MANIFEST_DIR environment variable is missing

我最近在我的Rust應用程序中添加了一個包含程序宏的依賴項。 使用i18n_codegen::i18n!("locales");來調用此過程宏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 ...那怎么可能? 我以為是貨物始終設定的? 我猜想直接運行rustc時可能會丟失它,但是運行cargo build --tests時也可能會丟失它嗎?

查找環境變量的代碼在這里https://github.com/davidpdrsn/i18n_codegen/blob/master/src/lib.rs#L233

主應用程序本身是一個Cargo工作區,其中包含其他幾個板條箱,不確定是否重要。

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

這是一個封閉源代碼的工作項目,所以不幸的是我無法輕松共享它。

第一個和第二個錯誤無關:

  1. 之所以失敗,是因為該過程是從“某處”殺死的(注釋似乎已解決了該問題)。
  2. 由於CARGO_MANIFEST_DIRcargo設置而失敗,因此,如果您手動運行rustc ,則必須自己設置變量,通常嘗試完全不要手動運行rustc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM