]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/rustc_tools_util/README.md
New upstream version 1.52.1+dfsg1
[rustc.git] / src / tools / clippy / rustc_tools_util / README.md
CommitLineData
f20569fa
XL
1# rustc_tools_util
2
3A small tool to help you generate version information
4for packages installed from a git repo
5
6## Usage
7
8Add a `build.rs` file to your repo and list it in `Cargo.toml`
9````
10build = "build.rs"
11````
12
13List rustc_tools_util as regular AND build dependency.
14````
15[dependencies]
16rustc_tools_util = "0.1"
17
18[build-dependencies]
19rustc_tools_util = "0.1"
20````
21
22In `build.rs`, generate the data in your `main()`
23````rust
24fn main() {
25 println!(
26 "cargo:rustc-env=GIT_HASH={}",
27 rustc_tools_util::get_commit_hash().unwrap_or_default()
28 );
29 println!(
30 "cargo:rustc-env=COMMIT_DATE={}",
31 rustc_tools_util::get_commit_date().unwrap_or_default()
32 );
33 println!(
34 "cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}",
35 rustc_tools_util::get_channel().unwrap_or_default()
36 );
37}
38
39````
40
41Use the version information in your main.rs
42````rust
43use rustc_tools_util::*;
44
45fn show_version() {
46 let version_info = rustc_tools_util::get_version_info!();
47 println!("{}", version_info);
48}
49````
50This gives the following output in clippy:
51`clippy 0.0.212 (a416c5e 2018-12-14)`
52
53
54## License
55
56Copyright 2014-2020 The Rust Project Developers
57
58Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
59http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
60<LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
61option. All files in the project carrying such notice may not be
62copied, modified, or distributed except according to those terms.