3 A small tool to help you generate version information
4 for packages installed from a git repo
8 Add a `build.rs` file to your repo and list it in `Cargo.toml`
13 List rustc_tools_util as regular AND build dependency.
16 rustc_tools_util = "0.1"
19 rustc_tools_util = "0.1"
22 In `build.rs`, generate the data in your `main()`
26 "cargo:rustc-env=GIT_HASH={}",
27 rustc_tools_util::get_commit_hash().unwrap_or_default()
30 "cargo:rustc-env=COMMIT_DATE={}",
31 rustc_tools_util::get_commit_date().unwrap_or_default()
34 "cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}",
35 rustc_tools_util::get_channel().unwrap_or_default()
41 Use the version information in your main.rs
43 use rustc_tools_util::*;
46 let version_info = rustc_tools_util::get_version_info!();
47 println!("{}", version_info);
50 This gives the following output in clippy:
51 `clippy 0.0.212 (a416c5e 2018-12-14)`
56 Copyright 2014-2020 The Rust Project Developers
58 Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
59 http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
60 <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
61 option. All files in the project carrying such notice may not be
62 copied, modified, or distributed except according to those terms.