Use the protobuf_build crate to simplify build process.

Removes external dependency on rust-protobuf, which prevents version
mismatch between the runtime and the compiler.
This commit is contained in:
Paul Lietar 2016-01-12 23:10:57 +00:00
parent 2eeb1c9817
commit 3c29d744a9
3 changed files with 32 additions and 46 deletions

18
Cargo.lock generated
View file

@ -12,7 +12,7 @@ dependencies = [
"librespot-protocol 0.1.0", "librespot-protocol 0.1.0",
"num 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"portaudio 0.1.2 (git+https://github.com/mvdnes/portaudio-rs)", "portaudio 0.1.2 (git+https://github.com/mvdnes/portaudio-rs)",
"protobuf 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
"protobuf_macros 0.1.1 (git+https://github.com/plietar/rust-protobuf-macros.git)", "protobuf_macros 0.1.1 (git+https://github.com/plietar/rust-protobuf-macros.git)",
"rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
"rpassword 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -213,7 +213,8 @@ name = "librespot-protocol"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"mod_path 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "mod_path 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"protobuf 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
"protobuf_build 0.1.1 (git+https://github.com/plietar/rust-protobuf-build.git)",
] ]
[[package]] [[package]]
@ -279,9 +280,20 @@ dependencies = [
[[package]] [[package]]
name = "protobuf" name = "protobuf"
version = "1.0.10" version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "protobuf_build"
version = "0.1.1"
source = "git+https://github.com/plietar/rust-protobuf-build.git#4859623ecb8d4208f955f0c5758b49630d007cd2"
dependencies = [
"gcc 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"protobuf 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "protobuf_macros" name = "protobuf_macros"
version = "0.1.1" version = "0.1.1"

View file

@ -8,3 +8,5 @@ build = "build.rs"
mod_path = "~0.1.6" mod_path = "~0.1.6"
protobuf = "~1.0.10" protobuf = "~1.0.10"
[build-dependencies.protobuf_build]
git = "https://github.com/plietar/rust-protobuf-build.git"

View file

@ -1,50 +1,22 @@
extern crate protobuf_build;
use std::env; use std::env;
use std::process::{Command, Stdio}; use std::path::PathBuf;
use std::path::{Path,PathBuf};
#[derive(Debug)]
enum ProtobufError {
IoError(::std::io::Error),
Other
}
impl std::convert::From<::std::io::Error> for ProtobufError {
fn from(e: ::std::io::Error) -> ProtobufError {
ProtobufError::IoError(e)
}
}
fn compile(prefix : &Path, files : &[&Path]) -> Result<(),ProtobufError>{
let mut c = Command::new("protoc");
c.arg("--rust_out").arg(env::var("OUT_DIR").unwrap())
.arg("--proto_path").arg(prefix.to_str().unwrap());
for f in files.iter() {
c.arg(f.to_str().unwrap());
}
//c.stdout(Stdio::inherit());
c.stderr(Stdio::inherit());
let mut p = try!(c.spawn());
let r = try!(p.wait());
return match r.success() {
true => Ok(()),
false => Err(ProtobufError::Other),
};
}
fn main() { fn main() {
let root = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap()); let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let out = PathBuf::from(env::var("OUT_DIR").unwrap());
let proto = root.join("proto"); let proto = root.join("proto");
compile(&proto, &[ let mut compiler = protobuf_build::Compiler::new(&proto, &out);
&proto.join("keyexchange.proto"),
&proto.join("authentication.proto"), for file in &["keyexchange.proto",
&proto.join("mercury.proto"), "authentication.proto",
&proto.join("metadata.proto"), "mercury.proto",
&proto.join("pubsub.proto"), "metadata.proto",
&proto.join("spirc.proto"), "pubsub.proto",
]).unwrap(); "spirc.proto"] {
compiler.compile(file).unwrap();
}
} }