coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

Error: `PROJECT_NAME_FOR_VERSION_STRING` environment variable not defined at compile time when installing `coreutils`

Open hawk-tomy opened this issue 6 months ago • 12 comments

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

  • coreutils should 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!

hawk-tomy avatar May 26 '25 02:05 hawk-tomy

I can reproduce it on my machine.

A workaround is to use:

PROJECT_NAME_FOR_VERSION_STRING="uutils coreutils" cargo install coreutils --locked

cakebaker avatar May 26 '25 09:05 cakebaker

I was also able to reproduce this on an M1 Mac Studio @ os 15.5, @cakebaker's fix worked.

0x4D5352 avatar May 26 '25 15:05 0x4D5352

I am curious to know what changed on our side for this regression ?!

sylvestre avatar May 26 '25 15:05 sylvestre

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

cakebaker avatar May 26 '25 15:05 cakebaker

Same happens on Win 11. Setting the env variable fixes it.

vDorst avatar May 27 '25 11:05 vDorst

Also hit this on an M3 Macbook Pro running 15.5.

lashomb avatar May 27 '25 22:05 lashomb

I see the same problem on Arch Linux, but the work-around above solved it. Using same Rust versions as OP.

Fairglow avatar May 29 '25 09:05 Fairglow

@cakebaker can we fix it in the repo directly? Thanks

sylvestre avatar May 29 '25 13:05 sylvestre

@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 :|

cakebaker avatar May 29 '25 16:05 cakebaker

I can send a fix, unless you're already working on it. I need such a configuration mechanism for a PR anyway.

Ecordonnier avatar May 29 '25 18:05 Ecordonnier

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)

kenmac999 avatar Jun 03 '25 20:06 kenmac999

@Ecordonnier don't hesitate for the fix :)

sylvestre avatar Jun 11 '25 15:06 sylvestre

Yep this is still a thing, cargo install --locked coreutils produce this error on arm64 mac and on windows

melMass avatar Jul 05 '25 12:07 melMass

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

seafiish avatar Jul 17 '25 03:07 seafiish

@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

Ecordonnier avatar Jul 20 '25 20:07 Ecordonnier