A small tool to help you generate version information for packages installed from a git repo
Add a build.rs
file to your repo and list it in Cargo.toml
toml
build = "build.rs"
List rustctoolsutil as regular AND build dependency. ````toml [dependencies] rustctoolsutil = "0.2.1"
[build-dependencies] rustctoolsutil = "0.2.1" ````
In build.rs
, generate the data in your main()
````rust
fn main() {
println!(
"cargo:rustc-env=GITHASH={}",
rustctoolsutil::getcommithash().unwrapordefault()
);
println!(
"cargo:rustc-env=COMMITDATE={}",
rustctoolsutil::getcommitdate().unwrapordefault()
);
println!(
"cargo:rustc-env=RUSTCRELEASECHANNEL={}",
rustctoolsutil::getchannel().unwrapor_default()
);
}
````
Use the version information in your main.rs ````rust use rustctoolsutil::*;
fn showversion() {
let versioninfo = rustctoolsutil::getversioninfo!();
println!("{}", version_info);
}
```
This gives the following output in clippy:
clippy 0.0.212 (a416c5e 2018-12-14)`
Copyright 2014-2022 The Rust Project Developers
Licensed under the Apache License, Version 2.0