Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade protobuf to v2.0 and gen binding file in the build script #171

Merged
merged 10 commits into from
May 23, 2018
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