dtolnay / dtolnay/prettyplease

What does cargo:VERSION do?

Open
#125 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
772
Forks
48
PR merge metrics
No merged PRs in 30d

Description

@dtolnay help!

Can you please explain to me what cargo:VERSION does? You added this here:
https://github.com/dtolnay/prettyplease/commit/f40afcc70f4eed7133e35c30fdc8e38f7d101eec

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!("{}=", 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")));
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.