1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-03 09:49:31 +02:00

Upgrade protobuf to 2.0 and use protoc-rust to compile proto files

This commit is contained in:
ashthespy 2018-09-28 12:02:38 +02:00
parent 37c588d6a1
commit c5fcdfd43c
15 changed files with 3386 additions and 7893 deletions

View file

@ -1,15 +1,36 @@
extern crate protoc_rust;
use protoc_rust::Customize;
use std::fs::File;
use std::io::prelude::*;
mod files;
fn main() {
let mut changed = false;
let mut file = File::open("files.rs").unwrap();
let mut f_str = String::new();
file.read_to_string(&mut f_str).unwrap();
drop(file);
for &(path, expected_checksum) in files::FILES {
let actual = cksum_file(path).unwrap();
if expected_checksum != actual {
panic!("Checksum for {:?} does not match. Try running build.sh", path);
protoc_rust::run(protoc_rust::Args {
out_dir: "src",
input: &[path],
includes: &["proto"],
customize: Customize { ..Default::default() },
}).expect("protoc");
let new_checksum = cksum_file(path).unwrap();
f_str = f_str.replace(&expected_checksum.to_string(), &new_checksum.to_string());
changed = true;
}
}
if changed {
// Write new checksums to file
let mut file = File::create("files.rs").unwrap();
println!("f_str: {:?}",f_str);
file.write_all(f_str.as_bytes()).unwrap();
}
}
fn cksum_file<T: AsRef<std::path::Path>>(path: T) -> std::io::Result<u32> {