Skip to content

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

Closed

Description

@hawk-tomy

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!

Activity

  1. cakebaker commented on May 26, 2025

    @cakebaker
    Contributor

    I can reproduce it on my machine.

    A workaround is to use:

    PROJECT_NAME_FOR_VERSION_STRING="uutils coreutils" cargo install coreutils --locked
    
  2. 0x4D5352 commented on May 26, 2025

    @0x4D5352

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

  3. sylvestre commented on May 26, 2025

    @sylvestre
    SponsorContributor

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

  4. cakebaker commented on May 26, 2025

    @cakebaker
    Contributor

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

    @sylvestre it's a new feature I implemented in #7441

  5. vDorst commented on May 27, 2025

    @vDorst

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

  6. lashomb commented on May 27, 2025

    @lashomb

    Also hit this on an M3 Macbook Pro running 15.5.

  7. Fairglow commented on May 29, 2025

    @Fairglow

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

  8. sylvestre commented on May 29, 2025

    @sylvestre
    SponsorContributor

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

  9. cakebaker commented on May 29, 2025

    @cakebaker
    Contributor

    @sylvestre it looks like it's a bug/feature in cargo: rust-lang/cargo#14001, and we have to look for a different approach :|

  10. Ecordonnier commented on May 29, 2025

    @Ecordonnier
    Collaborator

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

  11. kenmac999 commented on Jun 3, 2025

    @kenmac999

    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)

  12. sylvestre commented on Jun 11, 2025

    @sylvestre
    SponsorContributor

    @Ecordonnier don't hesitate for the fix :)

  13. melMass commented on Jul 5, 2025

    @melMass

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

  14. seafiish commented on Jul 17, 2025

    @seafiish

    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

  15. Ecordonnier commented on Jul 20, 2025

    @Ecordonnier
    Collaborator

    @Ecordonnier don't hesitate for the fix :)

    I'll give it a try. A simple way to reproduce (because of rust-lang/cargo#2930 ):

    git clone https://github.com/uutils/coreutils.git
    mkdir test && cd test
    cargo build --manifest-path=../coreutils/Cargo.toml
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions