Skip to content

Commit 8724e5a

Browse files
flierovervenus
authored andcommitted
upgrade protobuf to v2.0 and gen binding file in the build script (#171)
1 parent 2583e4b commit 8724e5a

File tree

4 files changed

+241
-596
lines changed

4 files changed

+241
-596
lines changed

Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ dev = ["clippy"]
2727
nightly = ["libc", "spin/unstable"]
2828
push = ["hyper", "libc"]
2929
process = ["libc", "procinfo"]
30+
gen = ["protobuf-codegen-pure"]
3031

3132
[[bench]]
3233
name = "benches"
3334
path = "benches/benches.rs"
3435

3536
[dependencies]
36-
protobuf = "=1.4.0"
37+
protobuf = "2.0"
3738
quick-error = "0.2"
3839
clippy = {version = "^0", optional = true}
3940
fnv = "1.0"
@@ -56,5 +57,8 @@ optional = true
5657
getopts = "0.2"
5758
hyper = {version = "0.9", default-features = false}
5859

60+
[build-dependencies]
61+
protobuf-codegen-pure = {version = "2.0", optional = true}
62+
5963
[workspace]
6064
members = ["static-metric"]

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ The main Structures and APIs are ported from [Go client](https://github.com/prom
3131
features = ["nightly"]
3232
```
3333

34+
### Note
35+
36+
The crate has a pre-generated protobuf binding file for `protobuf` v2.0, if you need use the latest version of `protobuf`, you can generate the binding file on building with the `gen` feature.
37+
38+
```toml
39+
[dependencies.prometheus]
40+
git = "https://github.com/pingcap/rust-prometheus.git"
41+
features = ["gen"]
42+
```
43+
3444
## Example
3545

3646
```rust

build.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#[cfg(feature = "gen")]
2+
extern crate protobuf_codegen_pure;
3+
4+
#[cfg(feature = "gen")]
5+
fn generate_protobuf_binding_file() {
6+
protobuf_codegen_pure::run(protobuf_codegen_pure::Args {
7+
out_dir: "proto",
8+
input: &["proto/metrics.proto"],
9+
includes: &["proto"],
10+
..Default::default()
11+
}).unwrap();
12+
}
13+
14+
#[cfg(not(feature = "gen"))]
15+
fn generate_protobuf_binding_file() {}
16+
17+
fn main() {
18+
generate_protobuf_binding_file()
19+
}

0 commit comments

Comments
 (0)