Skip to content

Commit

Permalink
upgrade protobuf to v2.0 and gen binding file in the build script (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
flier authored and overvenus committed May 23, 2018
1 parent 2583e4b commit 8724e5a
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 596 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ dev = ["clippy"]
nightly = ["libc", "spin/unstable"]
push = ["hyper", "libc"]
process = ["libc", "procinfo"]
gen = ["protobuf-codegen-pure"]

[[bench]]
name = "benches"
path = "benches/benches.rs"

[dependencies]
protobuf = "=1.4.0"
protobuf = "2.0"
quick-error = "0.2"
clippy = {version = "^0", optional = true}
fnv = "1.0"
Expand All @@ -56,5 +57,8 @@ optional = true
getopts = "0.2"
hyper = {version = "0.9", default-features = false}

[build-dependencies]
protobuf-codegen-pure = {version = "2.0", optional = true}

[workspace]
members = ["static-metric"]
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ The main Structures and APIs are ported from [Go client](https://github.com/prom
features = ["nightly"]
```

### Note

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.

```toml
[dependencies.prometheus]
git = "https://github.com/pingcap/rust-prometheus.git"
features = ["gen"]
```

## Example

```rust
Expand Down
19 changes: 19 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#[cfg(feature = "gen")]
extern crate protobuf_codegen_pure;

#[cfg(feature = "gen")]
fn generate_protobuf_binding_file() {
protobuf_codegen_pure::run(protobuf_codegen_pure::Args {
out_dir: "proto",
input: &["proto/metrics.proto"],
includes: &["proto"],
..Default::default()
}).unwrap();
}

#[cfg(not(feature = "gen"))]
fn generate_protobuf_binding_file() {}

fn main() {
generate_protobuf_binding_file()
}
Loading

0 comments on commit 8724e5a

Please sign in to comment.