2018-03-14 17:03:21 -07:00
|
|
|
extern crate protoc_rust;
|
|
|
|
|
2018-04-18 13:23:39 -07:00
|
|
|
use std::env;
|
|
|
|
|
|
|
|
fn protoc_exists() -> bool {
|
|
|
|
let name = "PATH";
|
|
|
|
match env::var_os(name) {
|
|
|
|
Some(paths) => {
|
|
|
|
for path in env::split_paths(&paths) {
|
|
|
|
if path.join("protoc").exists() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-30 08:55:51 -07:00
|
|
|
None => println!("PATH environment variable is not defined."),
|
2018-04-18 13:23:39 -07:00
|
|
|
}
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2018-03-14 17:03:21 -07:00
|
|
|
fn main() {
|
2018-04-18 13:23:39 -07:00
|
|
|
if !protoc_exists() {
|
2018-04-30 08:55:51 -07:00
|
|
|
panic!(
|
|
|
|
"
|
2018-04-18 13:23:39 -07:00
|
|
|
protoc cannot be found. Install the protobuf compiler in the \
|
2018-04-30 08:55:51 -07:00
|
|
|
system path."
|
|
|
|
);
|
|
|
|
} else {
|
2018-04-18 13:23:39 -07:00
|
|
|
println!("cargo:rerun-if-changed=proto/message.proto");
|
|
|
|
protoc_rust::run(protoc_rust::Args {
|
|
|
|
out_dir: "src/proto",
|
|
|
|
input: &["proto/message.proto"],
|
|
|
|
includes: &["proto"],
|
|
|
|
}).expect("protoc");
|
|
|
|
}
|
2018-03-14 17:03:21 -07:00
|
|
|
}
|