Skip to content

environment variable CFG_RELEASE_CHANNEL not defined #4230

Closed

Description

@Timmmm

I'm trying to build the latest version on Mac with this command:

CARGO_NET_GIT_FETCH_WITH_CLI=true cargo +nightly install --force --branch master --git https://github.com/rust-lang/rustfmt.git

But it gives the following errors:

   Compiling rustc-ap-rustc_parse v659.0.0
error: environment variable `CFG_RELEASE_CHANNEL` not defined
   --> /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-rustc_attr-659.0.0/builtin.rs:655:27
    |
655 |             let channel = env!("CFG_RELEASE_CHANNEL");
    |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: environment variable `CFG_RELEASE` not defined
   --> /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-rustc_attr-659.0.0/builtin.rs:657:48
    |
657 |             let rustc_version = Version::parse(env!("CFG_RELEASE")).unwrap();
    |                                                ^^^^^^^^^^^^^^^^^^^
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

Any ideas? I found it mentioned in #4174 but that seems to imply that it has been fixed. Am I missing something?

Activity

  1. Timmmm commented on Jun 3, 2020

    @Timmmm
    ContributorAuthor

    This comment suggests I need rustc version rustc 1.45.0-nightly (d79f1bd31 2020-05-17) but I have a later one:

    ✗ ~/.rustup/toolchains/nightly-x86_64-apple-darwin/bin/rustc --version
    rustc 1.45.0-nightly (fe10f1a49 2020-06-02)
    
  2. calebcartwright commented on Jun 3, 2020

    @calebcartwright
    Member

    You're going to have to set the environment variables (CFG_RELEASE_CHANNEL and CFG_RELEASE) in order to build rustfmt from source due to recent upstream changes in the rustc tree.

    We've updated the Contributing docs to call this out, though looks like we forgot to update the corresponding section in the readme
    https://github.com/rust-lang/rustfmt/blob/master/Contributing.md#building-and-testing

  3. Timmmm commented on Jun 4, 2020

    @Timmmm
    ContributorAuthor

    Ah cool, I changed the command to this:

    CFG_RELEASE_CHANNEL=nightly CFG_RELEASE=nightly CARGO_NET_GIT_FETCH_WITH_CLI=true cargo +nightly install --force --branch master --git https://github.com/rust-lang/rustfmt.git
    

    And it compiled successfully! But then gives this error:

        Finished release [optimized] target(s) in 1m 47s
    error: no binaries are available for install using the selected features
    

    Any ideas?

  4. Timmmm commented on Jun 4, 2020

    @Timmmm
    ContributorAuthor

    Ah I see it doesn't build anything by default. This command works perfectly - might be worth adding to the Readme?

    CFG_RELEASE_CHANNEL=nightly CFG_RELEASE=nightly CARGO_NET_GIT_FETCH_WITH_CLI=true cargo +nightly install --force --branch master --git https://github.com/rust-lang/rustfmt.git --features "rustfmt cargo-fmt"
    
  5. ahl commented on Jun 4, 2020

    @ahl
    Contributor

    We've updated the Contributing docs to call this out, though looks like we forgot to update the corresponding section in the readme
    https://github.com/rust-lang/rustfmt/blob/master/Contributing.md#building-and-testing

    Should the main README.md be updated to refer to these docs? This is what it currently says:

    ## How to build and test
    
    `cargo build` to build.
    
    `cargo test --manifest-path rustfmt-core/Cargo.toml` to run all tests.
    
  6. calebcartwright commented on Jun 5, 2020

    @calebcartwright
    Member

    Yes. I'm going to update this (and a few other minor items) in the docs later today

  7. Timmmm commented on Mar 22, 2025

    @Timmmm
    ContributorAuthor

    Ha I just ran into this problem again and made it all the way through this thread before realising it was me from 5 years ago...

    Anyway, this doesn't seem to work any more:

    CFG_RELEASE_CHANNEL=nightly CFG_RELEASE=nightly
    

    You get this error:

    error: CFG_RELEASE env var: failed to parse rustc version: "nightly"
      --> C:\Users\Tim\.cargo\git\checkouts\rust-a4081372e9049d90\d93f678\compiler\rustc_attr_data_structures\src\version.rs:18:31
       |
    18 |     pub const CURRENT: Self = current_rustc_version!();
       |                               ^^^^^^^^^^^^^^^^^^^^^^^^
    

    Also it looks like this was never added to the docs unfortunately. Or if it was it has since been removed. :-/

    Seems like CFG_RELEASE has to be an actual version now, as parsed by this code:

        fn parse_str(value: &str) -> Option<Self> {
            // Ignore any suffixes such as "-dev" or "-nightly".
            let mut components = value.split('-').next().unwrap().splitn(3, '.');
            let major = components.next()?.parse().ok()?;
            let minor = components.next()?.parse().ok()?;
            let patch = components.next().unwrap_or("0").parse().ok()?;
            Some(RustcVersion { major, minor, patch })
        }
    

    I used 1.85.0-nightly and it worked.

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