Преглед изворни кода

Support building with rust stable, using syntex.

Paul Lietar пре 9 година
родитељ
комит
d27c4ca752
13 измењених фајлова са 207 додато и 94 уклоњено
  1. 9 1
      .travis.yml
  2. 74 15
      Cargo.lock
  3. 30 29
      Cargo.toml
  4. 21 0
      build.rs
  5. 0 1
      protocol/Cargo.toml
  6. 27 7
      protocol/build.rs
  7. 6 10
      protocol/src/lib.rs
  8. 16 0
      src/lib.in.rs
  9. 8 19
      src/lib.rs
  10. 1 1
      src/metadata.rs
  11. 6 8
      src/util/int128.rs
  12. 7 1
      src/util/mod.rs
  13. 2 2
      src/util/spotify_id.rs

+ 9 - 1
.travis.yml

@@ -1,5 +1,7 @@
 language: rust
 rust:
+  - stable
+  - beta
   - nightly
 
 addons:
@@ -10,4 +12,10 @@ addons:
 
 script:
     - cargo build --verbose
-    - cargo test --verbose
+    - cargo build --no-default-features --verbose
+
+matrix:
+  allow_failures:
+    - rust:
+      - stable
+      - beta

+ 74 - 15
Cargo.lock

@@ -7,18 +7,19 @@ dependencies = [
  "dns-sd 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "eventual 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
- "json_macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "json_macros 0.3.0 (git+https://github.com/plietar/json_macros)",
  "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "librespot-protocol 0.1.0",
  "num 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
  "portaudio 0.2.0 (git+https://github.com/mvdnes/portaudio-rs)",
  "protobuf 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
- "protobuf_macros 0.2.0 (git+https://github.com/plietar/rust-protobuf-macros.git)",
+ "protobuf_macros 0.3.0 (git+https://github.com/plietar/rust-protobuf-macros)",
  "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
  "rpassword 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "rust-crypto 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
- "shannon 0.1.1 (git+https://github.com/plietar/rust-shannon.git)",
+ "shannon 0.1.1 (git+https://github.com/plietar/rust-shannon)",
+ "syntex 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "tempfile 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
  "tiny_http 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -36,6 +37,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 name = "aster"
 version = "0.13.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "syntex_syntax 0.29.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
 
 [[package]]
 name = "bit-set"
@@ -167,9 +171,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 [[package]]
 name = "json_macros"
 version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
+source = "git+https://github.com/plietar/json_macros#1aa21f6c1c08ac1e9d5b21447edd6c4f34f2a1dd"
 dependencies = [
+ "quasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quasi_codegen 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_syntax 0.29.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -200,7 +208,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 name = "librespot-protocol"
 version = "0.1.0"
 dependencies = [
- "mod_path 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "protobuf 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
  "protobuf_build 0.1.1 (git+https://github.com/plietar/rust-protobuf-build.git)",
 ]
@@ -218,11 +225,6 @@ name = "matches"
 version = "0.1.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
-[[package]]
-name = "mod_path"
-version = "0.1.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
 [[package]]
 name = "num"
 version = "0.1.31"
@@ -284,10 +286,30 @@ dependencies = [
 
 [[package]]
 name = "protobuf_macros"
-version = "0.2.0"
-source = "git+https://github.com/plietar/rust-protobuf-macros.git#5853fc344d506728fa497eaccb83f0a8a82f9150"
+version = "0.3.0"
+source = "git+https://github.com/plietar/rust-protobuf-macros#27e273a3b335a8a6a1c0139bb67d1fe4ba765b20"
 dependencies = [
  "aster 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_syntax 0.29.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "quasi"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "syntex_syntax 0.29.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "quasi_codegen"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "aster 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_syntax 0.29.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -329,18 +351,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 [[package]]
 name = "shannon"
 version = "0.1.1"
-source = "git+https://github.com/plietar/rust-shannon.git#ed87ffd2cf09a2a99871900e81ecfaaac117b790"
+source = "git+https://github.com/plietar/rust-shannon#7000b3e49a53daaa890727ba2b2bd5a43cc4ffef"
 dependencies = [
  "byteorder 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "shannon-sys 0.1.0 (git+https://github.com/plietar/rust-shannon.git)",
+ "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "shannon-sys 0.1.0 (git+https://github.com/plietar/rust-shannon)",
 ]
 
 [[package]]
 name = "shannon-sys"
 version = "0.1.0"
-source = "git+https://github.com/plietar/rust-shannon.git#ed87ffd2cf09a2a99871900e81ecfaaac117b790"
+source = "git+https://github.com/plietar/rust-shannon#7000b3e49a53daaa890727ba2b2bd5a43cc4ffef"
 dependencies = [
  "gcc 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -352,6 +376,27 @@ dependencies = [
  "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "syntex"
+version = "0.29.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "syntex_syntax 0.29.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "syntex_syntax"
+version = "0.29.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
+ "term 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "tempfile"
 version = "2.0.1"
@@ -363,6 +408,15 @@ dependencies = [
  "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "term"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "termios"
 version = "0.2.2"
@@ -407,6 +461,11 @@ name = "unicode-normalization"
 version = "0.1.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
+[[package]]
+name = "unicode-xid"
+version = "0.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
 [[package]]
 name = "url"
 version = "0.2.38"

+ 30 - 29
Cargo.toml

@@ -16,38 +16,39 @@ path = "src/main.rs"
 path = "protocol"
 
 [dependencies]
-bit-set     = "~0.2.0"
-byteorder   = "~0.4.2"
-eventual    = "~0.1.5"
-getopts     = "~0.2.14"
-json_macros = "~0.3.0"
-lazy_static = "~0.1.15"
-num         = "~0.1.30"
-protobuf    = "~1.0.15"
-rand        = "~0.3.13"
-rpassword   = "~0.1.1"
-rust-crypto = "~0.2.34"
+bit-set         = "~0.2.0"
+byteorder       = "~0.4.2"
+eventual        = "~0.1.5"
+getopts         = "~0.2.14"
+#json_macros     = "~0.3.0"
+lazy_static     = "~0.1.15"
+num             = "~0.1.30"
+protobuf        = "~1.0.15"
+rand            = "~0.3.13"
+rpassword       = "~0.1.1"
+rust-crypto     = "~0.2.34"
 rustc-serialize = "~0.3.16"
-tempfile    = "~2.0.0"
-time        = "~0.1.34"
-tiny_http   = "~0.5.1"
-url         = "~0.5.2"
-vorbis      = "~0.0.14"
-
-[dependencies.dns-sd]
-version  = "~0.1.1"
-optional = true
-
-[dependencies.protobuf_macros]
-git = "https://github.com/plietar/rust-protobuf-macros.git"
-[dependencies.shannon]
-git = "https://github.com/plietar/rust-shannon.git"
-[dependencies.portaudio]
-git = "https://github.com/mvdnes/portaudio-rs"
+tempfile        = "~2.0.0"
+time            = "~0.1.34"
+tiny_http       = "~0.5.1"
+url             = "~0.5.2"
+vorbis          = "~0.0.14"
+
+dns-sd          = { version  = "~0.1.1", optional = true }
+
+portaudio       = { git = "https://github.com/mvdnes/portaudio-rs" }
+
+json_macros     = { git = "https://github.com/plietar/json_macros" }
+protobuf_macros = { git = "https://github.com/plietar/rust-protobuf-macros" }
+shannon         = { git = "https://github.com/plietar/rust-shannon" }
 
 [build-dependencies]
-vergen = "~0.1.0"
+vergen          = "~0.1.0"
+syntex          = { version = "*", optional = true }
+protobuf_macros = { git = "https://github.com/plietar/rust-protobuf-macros" }
+json_macros     = { git = "https://github.com/plietar/json_macros" }
 
 [features]
 discovery = ["dns-sd"]
-
+with-syntex = ["syntex", "protobuf_macros/with-syntex", "json_macros/with-syntex"]
+default = ["with-syntex"]

+ 21 - 0
build.rs

@@ -1,6 +1,27 @@
 extern crate vergen;
+#[cfg(feature = "with-syntex")] extern crate syntex;
+#[cfg(feature = "with-syntex")] extern crate json_macros;
+#[cfg(feature = "with-syntex")] extern crate protobuf_macros;
+
+#[cfg(feature = "with-syntex")]
+fn codegen() {
+    use std::env;
+    use std::path::PathBuf;
+    use std::path::Path;
+
+    let mut registry = syntex::Registry::new();
+    let out = PathBuf::from(env::var("OUT_DIR").unwrap());
+
+    json_macros::plugin_registrar(&mut registry);
+    protobuf_macros::plugin_registrar(&mut registry);
+    registry.expand("librespot", Path::new("src/lib.in.rs"), &out.join("lib.rs")).unwrap();
+}
+
+#[cfg(not(feature = "with-syntex"))]
+fn codegen() { }
 
 fn main() {
     vergen::vergen(vergen::SHORT_SHA).unwrap();
+    codegen();
 }
 

+ 0 - 1
protocol/Cargo.toml

@@ -5,7 +5,6 @@ authors = ["Paul Liétar <paul@lietar.net>"]
 build = "build.rs"
 
 [dependencies]
-mod_path = "~0.1.6"
 protobuf = "~1.0.10"
 
 [build-dependencies.protobuf_build]

+ 27 - 7
protocol/build.rs

@@ -2,6 +2,8 @@ extern crate protobuf_build;
 
 use std::env;
 use std::path::PathBuf;
+use std::fs::File;
+use std::io::{Read, Write};
 
 fn main() {
     let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
@@ -10,13 +12,31 @@ fn main() {
 
     let mut compiler = protobuf_build::Compiler::new(&proto, &out);
 
-    for file in &["keyexchange.proto",
-                  "authentication.proto",
-                  "mercury.proto",
-                  "metadata.proto",
-                  "pubsub.proto",
-                  "spirc.proto"] {
-        compiler.compile(file).unwrap();
+    let files = ["keyexchange",
+                 "authentication",
+                 "mercury",
+                 "metadata",
+                 "pubsub",
+                 "spirc"];
+
+    for file in &files {
+        compiler.compile(&((*file).to_owned() + ".proto")).unwrap();
+
+        // Hack for rust-lang/rust#18810
+        // Wrap the generated rust files with "pub mod { ... }", so they
+        // can be included.
+        let path = out.join(&((*file).to_owned() + ".rs"));
+        let contents = {
+            let mut src = File::open(path).unwrap();
+            let mut contents = Vec::new();
+            src.read_to_end(&mut contents).unwrap();
+            contents
+        };
+
+        let mut dst = File::create(out.join(&((*file).to_owned() + ".rs"))).unwrap();
+        dst.write_all(format!("pub mod {} {{\n", file).as_bytes()).unwrap();
+        dst.write_all(&contents).unwrap();
+        dst.write_all("}".as_bytes()).unwrap();
     }
 }
 

+ 6 - 10
protocol/src/lib.rs

@@ -1,12 +1,8 @@
-#![feature(plugin)]
-#![plugin(mod_path)]
-
 extern crate protobuf;
 
-mod_path! keyexchange (concat!(env!("OUT_DIR"), "/keyexchange.rs"));
-mod_path! authentication (concat!(env!("OUT_DIR"), "/authentication.rs"));
-mod_path! mercury (concat!(env!("OUT_DIR"), "/mercury.rs"));
-mod_path! metadata (concat!(env!("OUT_DIR"), "/metadata.rs"));
-mod_path! pubsub (concat!(env!("OUT_DIR"), "/pubsub.rs"));
-mod_path! spirc (concat!(env!("OUT_DIR"), "/spirc.rs"));
-
+include! (concat!(env!("OUT_DIR"), "/authentication.rs"));
+include! (concat!(env!("OUT_DIR"), "/keyexchange.rs"));
+include! (concat!(env!("OUT_DIR"), "/mercury.rs"));
+include! (concat!(env!("OUT_DIR"), "/metadata.rs"));
+include! (concat!(env!("OUT_DIR"), "/pubsub.rs"));
+include! (concat!(env!("OUT_DIR"), "/spirc.rs"));

+ 16 - 0
src/lib.in.rs

@@ -0,0 +1,16 @@
+#[macro_use] pub mod util;
+mod audio_decrypt;
+mod audio_file;
+mod audio_key;
+mod authentication;
+mod connection;
+mod diffie_hellman;
+pub mod discovery;
+pub mod mercury;
+pub mod metadata;
+pub mod player;
+pub mod session;
+pub mod spirc;
+pub mod link;
+mod stream;
+mod zeroconf;

+ 8 - 19
src/lib.rs

@@ -1,9 +1,9 @@
 #![crate_name = "librespot"]
 
-#![feature(plugin,zero_one,iter_arith)]
+#![cfg_attr(not(feature = "with-syntex"), feature(plugin))]
+#![cfg_attr(not(feature = "with-syntex"), plugin(protobuf_macros))]
+#![cfg_attr(not(feature = "with-syntex"), plugin(json_macros))]
 
-#![plugin(protobuf_macros)]
-#![plugin(json_macros)]
 #[macro_use]
 extern crate lazy_static;
 
@@ -28,19 +28,8 @@ extern crate dns_sd;
 
 extern crate librespot_protocol as protocol;
 
-#[macro_use]pub mod util;
-mod audio_decrypt;
-mod audio_file;
-mod audio_key;
-mod authentication;
-mod connection;
-mod diffie_hellman;
-pub mod discovery;
-pub mod mercury;
-pub mod metadata;
-pub mod player;
-pub mod session;
-pub mod spirc;
-pub mod link;
-mod stream;
-mod zeroconf;
+#[cfg(feature = "with-syntex")]
+include!(concat!(env!("OUT_DIR"), "/lib.rs"));
+
+#[cfg(not(feature = "with-syntex"))]
+include!("lib.in.rs");

+ 1 - 1
src/metadata.rs

@@ -195,7 +195,7 @@ impl MetadataManager {
                    payload: Vec::new(),
                })
                .and_then(move |response| {
-                   let data = response.payload.first().unwrap();
+                   let data = response.payload.first().expect("Empty payload");
                    let msg: T::Message = protobuf::parse_from_bytes(data).unwrap();
 
                    Ok(T::parse(&msg, &session))

+ 6 - 8
src/util/int128.rs

@@ -8,6 +8,10 @@ pub struct u128 {
 }
 
 impl u128 {
+    pub fn zero() -> u128 {
+        u128::from_parts(0, 0)
+    }
+
     pub fn from_parts(high: u64, low: u64) -> u128 {
         u128 {
             high: high,
@@ -20,12 +24,6 @@ impl u128 {
     }
 }
 
-impl std::num::Zero for u128 {
-    fn zero() -> u128 {
-        u128::from_parts(0, 0)
-    }
-}
-
 impl std::ops::Add<u128> for u128 {
     type Output = u128;
     fn add(self, rhs: u128) -> u128 {
@@ -77,7 +75,7 @@ impl std::ops::Mul<u128> for u128 {
                                 rhs.low >> 32,
                                 rhs.low & 0xFFFFFFFF];
 
-        let mut rows = [std::num::Zero::zero(); 16];
+        let mut rows = [u128::zero(); 16];
         for i in 0..4 {
             for j in 0..4 {
                 let shift = i + j;
@@ -99,6 +97,6 @@ impl std::ops::Mul<u128> for u128 {
             }
         }
 
-        rows.iter().sum::<u128>()
+        rows.iter().fold(u128::zero(), std::ops::Add::add)
     }
 }

+ 7 - 1
src/util/mod.rs

@@ -45,8 +45,14 @@ pub fn rand_vec<G: Rng, R: Rand>(rng: &mut G, size: usize) -> Vec<R> {
     vec
 }
 
+
 pub mod version {
-    include!(concat!(env!("OUT_DIR"), "/version.rs"));
+    // FIXME: Unfortunately, this doesn't work when using syntex
+    // And for some reason, cfg-gating it doesn't work
+    //include!(concat!(env!("OUT_DIR"), "/version.rs"));
+    pub fn short_sha() -> String {
+        "unknown".to_owned()
+    }
 
     pub fn version_string() -> String {
         format!("librespot-{}", short_sha())

+ 2 - 2
src/util/spotify_id.rs

@@ -18,7 +18,7 @@ impl SpotifyId {
         assert!(id.is_ascii());
         let data = id.as_bytes();
 
-        let mut n: u128 = std::num::Zero::zero();
+        let mut n: u128 = u128::zero();
         for c in data {
             let d = BASE16_DIGITS.iter().position(|e| e == c).unwrap() as u8;
             n = n * u128::from(16);
@@ -32,7 +32,7 @@ impl SpotifyId {
         assert!(id.is_ascii());
         let data = id.as_bytes();
 
-        let mut n: u128 = std::num::Zero::zero();
+        let mut n: u128 = u128::zero();
         for c in data {
             let d = BASE62_DIGITS.iter().position(|e| e == c).unwrap() as u8;
             n = n * u128::from(62);