diff --git a/Cargo.toml b/Cargo.toml index c45d5b1..ece70a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,13 +24,13 @@ serde = { version = "^1.0.55", optional = true } serde_derive = { version = "^1.0.55", optional = true } [build-dependencies] -protoc-rust = "1.7.1" +protoc-rust = { version = "1.7.1", optional = true } [dev-dependencies] serde_json = "1.0.17" [features] -serialization-protobuf = [ "protobuf" ] +serialization-protobuf = [ "protobuf", "protoc-rust" ] serialization-serde = [ "serde", "serde_derive" ] [package.metadata.release] diff --git a/build.rs b/build.rs index 7d3c457..85a2548 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,26 @@ +#[cfg(feature = "serialization-protobuf")] extern crate protoc_rust; -fn build_protobuf<'a>(out_dir: &'a str, input: &'a [&'a str], includes: &'a [&'a str]) { +#[cfg(feature = "serialization-protobuf")] +fn assert_protobuf_version(version: &str) { + use std::process::{Command, Stdio}; + let protoc = Command::new("protoc") + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .args(&["--version"]) + .spawn() + .unwrap(); + let version_output = protoc.wait_with_output().unwrap(); + assert!(version_output.status.success()); + assert_eq!( + String::from_utf8(version_output.stdout).unwrap().trim(), + version + ); +} + +#[cfg(feature = "serialization-protobuf")] +fn build_protobuf(out_dir: &str, input: &[&str], includes: &[&str]) { use self::protoc_rust::{run, Args}; run(Args { out_dir, @@ -9,7 +29,13 @@ fn build_protobuf<'a>(out_dir: &'a str, input: &'a [&'a str], includes: &'a [&'a }).expect("protoc"); } -fn main() { - #[cfg(feature = "serialization-protobuf")] +#[cfg(feature = "serialization-protobuf")] +fn build_protobuf_schemata() { + assert_protobuf_version("libprotoc 3.5.1"); build_protobuf("src/proto", &["protobuf/proof.proto"], &[]); } + +fn main() { + #[cfg(feature = "serialization-protobuf")] + build_protobuf_schemata(); +}