Skip to content

Commit 44ffda7

Browse files
committed
Auto merge of #3578 - matthiaskrgr:rustc_tools_util, r=oli-obk
rustc_tools_util: changes in preparation of release on crates.io I want to release my [cargo-cache](https://github.com/matthiaskrgr/cargo-cache) crate on crates.io however it depends on rustc_tools_util, thus I need to publish rustc_tools_util on crates.io first. This PR expands the Cargo.toml and adds a readme.
2 parents c10c515 + 345fe6d commit 44ffda7

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

rustc_tools_util/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@
22
name = "rustc_tools_util"
33
version = "0.1.0"
44
authors = ["Matthias Krüger <[email protected]>"]
5+
description = "small helper to generate version information for git packages"
6+
repository = "https://github.com/rust-lang/rust-clippy"
7+
readme = "README.md"
8+
license = "MIT/Apache-2.0"
9+
keywords = ["rustc", "tool", "git", "version", "hash"]
10+
categories = ["development-tools"]
511
edition = "2018"
612
[dependencies]

rustc_tools_util/README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# rustc_tools_util
2+
3+
A small tool to help you generate version information
4+
for packages installed from a git repo
5+
6+
## Usage
7+
8+
Add a `build.rs` file to your repo and list it in `Cargo.toml`
9+
````
10+
build = "build.rs"
11+
````
12+
13+
List rustc_tools_util as regular AND build dependency.
14+
````
15+
[dependencies]
16+
rustc_tools_util = "0.1"
17+
18+
[build-dependencies]
19+
rustc_tools_util = "0.1"
20+
````
21+
22+
In `build.rs`, generate the data in your `main()`
23+
````rust
24+
fn 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+
}
34+
35+
````
36+
37+
Use the version information in your main.rs
38+
````rust
39+
use rustc_tools_util::*;
40+
41+
fn show_version() {
42+
let version_info = rustc_tools_util::get_version_info!();
43+
println!("{}", version_info);
44+
}
45+
````
46+
This gives the following output in clippy:
47+
`clippy 0.0.212 (a416c5e 2018-12-14)`
48+
49+
50+
## License
51+
52+
Copyright 2014-2018 The Rust Project Developers
53+
54+
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
55+
http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
56+
<LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
57+
option. All files in the project carrying such notice may not be
58+
copied, modified, or distributed except according to those terms.

0 commit comments

Comments
 (0)