coreutils
coreutils copied to clipboard
Error: `PROJECT_NAME_FOR_VERSION_STRING` environment variable not defined at compile time when installing `coreutils`
First of all, thank you for providing this very useful tool!
When trying to install coreutils on Ubuntu 24.04 (WSL2), the build fails due to a missing environment variable.
Environment
- OS
- Ubuntu 24.04 under WSL2 on Windows 11
- Rust version (use stable)
cargo 1.87.0 (99624be96 2025-05-06)rustc 1.87.0 (17067e9ac 2025-05-09)
Reproduce
Run install command: cargo install coreutils --locked
Expected Behavior
coreutilsshould compile and install successfully.
Actual Behavior
- Compilation fails with multiple errors like:
Full log: https://gist.github.com/hawk-tomy/b03db482558db40dfab31085df5185bd
cargo install coreutils --locked
Updating crates.io index
Installing coreutils v0.1.0
Updating crates.io index
Updating crates.io index
Compiling libc v0.2.172
# ...
Compiling uu_unlink v0.1.0
error: environment variable `PROJECT_NAME_FOR_VERSION_STRING` not defined at compile time
--> /home/hawk-tomy/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/uu_base32-0.1.0/src/base_common.rs:107:18
|
107 | .version(uucore::crate_version!())
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: use `std::env::var("PROJECT_NAME_FOR_VERSION_STRING")` to read the variable at run time
= note: this error originates in the macro `env` which comes from the expansion of the macro `uucore::crate_version` (in Nightly builds, run with -Z macro-backtrace for more info)
# ...
error: failed to compile `coreutils v0.1.0`, intermediate artifacts can be found at `/tmp/cargo-install95GA05`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
Thank you for your help!
I can reproduce it on my machine.
A workaround is to use:
PROJECT_NAME_FOR_VERSION_STRING="uutils coreutils" cargo install coreutils --locked
I was also able to reproduce this on an M1 Mac Studio @ os 15.5, @cakebaker's fix worked.
I am curious to know what changed on our side for this regression ?!
I am curious to know what changed on our side for this regression ?!
@sylvestre it's a new feature I implemented in https://github.com/uutils/coreutils/pull/7441
Same happens on Win 11. Setting the env variable fixes it.
Also hit this on an M3 Macbook Pro running 15.5.
I see the same problem on Arch Linux, but the work-around above solved it. Using same Rust versions as OP.
@cakebaker can we fix it in the repo directly? Thanks
@sylvestre it looks like it's a bug/feature in cargo: https://github.com/rust-lang/cargo/issues/14001, and we have to look for a different approach :|
I can send a fix, unless you're already working on it. I need such a configuration mechanism for a PR anyway.
I also experienced the same issue today while updating on openSUSE Tumbleweed 20250601.
error: environment variable PROJECT_NAME_FOR_VERSION_STRINGnot defined at compile time --> /home/dad/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/uu_yes-0.1.0/src/yes.rs:41:18 | 41 | .version(uucore::crate_version!()) | ^^^^^^^^^^^^^^^^^^^^^^^^ | = help: usestd::env::var("PROJECT_NAME_FOR_VERSION_STRING")to read the variable at run time = note: this error originates in the macroenvwhich comes from the expansion of the macrouucore::crate_version` (in Nightly builds, run with -Z macro-backtrace for more info)
` Setting environment variable allowed me to finish compiling the update
Finishedreleaseprofile [optimized] target(s) in 50.40s Replacing /home/dad/.cargo/bin/coreutils Replaced packagecoreutils v0.0.30withcoreutils v0.1.0(executablecoreutils)
@Ecordonnier don't hesitate for the fix :)
Yep this is still a thing, cargo install --locked coreutils produce this error on arm64 mac and on windows
can reproduce on my linux fedora 42 machine with cargo install coreutils and cargo install coreutils --features unix --locked, the workaround did work for me
@Ecordonnier don't hesitate for the fix :)
I'll give it a try. A simple way to reproduce (because of https://github.com/rust-lang/cargo/issues/2930 ):
git clone https://github.com/uutils/coreutils.git
mkdir test && cd test
cargo build --manifest-path=../coreutils/Cargo.toml