Skip to content

What does cargo:VERSION do? #125

Description

@qknight

@dtolnay help!

Can you please explain to me what cargo:VERSION does? You added this here:
f40afcc

In order to reverse-engineer this I've setup a crate library (version-printer) which uses a build.rs with:

fn main() {
    println!("cargo:VERSION=999");
}

And in the main-crate I use:

use version_printer::version;

fn main() {
    version();
    for (key, value) in std::env::vars() {
        // Filter out sensitive keys that might contain secrets
        if key.contains("SECRET")
            || key.contains("KEY")
            || key.contains("TOKEN")
            || key.contains("PASSWORD")
            || key.contains("AUTH")
            || key.starts_with("REPLIT_")
        {
            println!("{}=<redacted>", key);
        } else {
            println!("'{}'='{}'", key, value);
        }
    }
}

Which shows that the version() function is actually called from the main.rs context so the library is properly used. BUT I don't see any environment variable exposed with VERSION or DEP_VERSION_SOMETHING and also I don't see any prints on the shell cargo build -vv. I've tried to pass invalid data like Strings instead of version numbers but it won't fail either.
I also studied the cargo source code but it is like searching for a needle in the hey stack as VERSION pops up pretty often.

So if you remember what your commit does please tell me.

fn main() {
    println!(concat!("cargo:VERSION=", env!("CARGO_PKG_VERSION")));
}

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions