Reputation: 467
I recently added a dependency to my Rust app that contains a procedural macro. This procedural macro is called with i18n_codegen::i18n!("locales");
. It will find all files in the locales
directory relative to CARGO_MANIFEST_DIR
. As far as I understand CARGO_MANIFEST_DIR
is the root of your crate, and gets set by Cargo.
This works fine locally but when I try to build it on my CI server it fails with this message:
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`.
Running the rustc command gives
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
Seems like CARGO_MANIFEST_DIR
is missing... How can that be? I thought that was always set by Cargo? I guess it might be missing when running rustc
directly, but how can it also be missing when running cargo build --tests
?
The code that finds the env var is here https://github.com/davidpdrsn/i18n_codegen/blob/master/src/lib.rs#L233.
The main app itself it a Cargo workspace with a few other crates inside it, not sure if that matters.
I'm using the same version of Rust nightly locally and on CI.
It is a work project that is closed source, so unfortunately I cannot easily share it.
Upvotes: 0
Views: 3485
Reputation: 71
The first and second error are unrelated:
CARGO_MANIFEST_DIR
is set by cargo
so if you run rustc
manually you have to set the variable yourself, generally try not to run rustc
manually at all.Upvotes: 3