diff --git a/Cargo.toml b/Cargo.toml index d545478..62f641d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,9 +8,13 @@ description = "PortAudio bindings for Rust." license = "MIT" homepage = "https://github.com/RustAudio/rust-portaudio" repository = "https://github.com/RustAudio/rust-portaudio.git" +build = "build.rs" +links = "portaudio" [dependencies] bitflags = "0.7" libc = "0.2.14" num = { version = "0.1.34", default-features = false } -portaudio_sys = { path = "./rust-portaudio-sys", version = "0.1.0" } + +[build-dependencies] +pkg-config = "0.3.6" diff --git a/rust-portaudio-sys/build.rs b/build.rs similarity index 79% rename from rust-portaudio-sys/build.rs rename to build.rs index bc0e78d..f5b2ffc 100644 --- a/rust-portaudio-sys/build.rs +++ b/build.rs @@ -62,6 +62,18 @@ fn err_to_panic(result: Result) -> T { } } +/// Executes the given command and prints it to stdout. (Stdout will only be displayed by cargo if the build +/// script panics). +/// Panics if the execution fails or the command returns non-successful. +#[allow(dead_code)] +fn execute_or_panic(cmd: &mut std::process::Command) { + let output = err_to_panic(cmd.output()); + println!("{:?}", cmd); + if !output.status.success() { + panic!("{}", String::from_utf8_lossy(&output.stderr)); + } +} + #[allow(dead_code)] mod unix_platform { use std::process::Command; @@ -69,42 +81,43 @@ mod unix_platform { use std::env; + use super::execute_or_panic; use super::err_to_panic; - pub const PORTAUDIO_URL: &'static str = "http://www.portaudio.com/archives/pa_stable_v19_20140130.tgz"; - pub const PORTAUDIO_TAR: &'static str = "pa_stable_v19_20140130.tgz"; + pub const PORTAUDIO_URL: &'static str = "http://www.portaudio.com/archives/pa_stable_v190600_20161030.tgz"; + pub const PORTAUDIO_TAR: &'static str = "pa_stable_v190600_20161030.tgz"; pub const PORTAUDIO_FOLDER: &'static str = "portaudio"; pub fn download() { - err_to_panic(Command::new("curl").arg(PORTAUDIO_URL).arg("-O").output()); + execute_or_panic(Command::new("curl").arg(PORTAUDIO_URL).arg("-O")); } pub fn build(out_dir: &Path) { // untar portaudio sources - err_to_panic(Command::new("tar").arg("xvf").arg(PORTAUDIO_TAR).output()); + execute_or_panic(Command::new("tar").arg("xvf").arg(PORTAUDIO_TAR)); // change dir to the portaudio folder err_to_panic(env::set_current_dir(PORTAUDIO_FOLDER)); // run portaudio autoconf - err_to_panic(Command::new("./configure") + execute_or_panic(Command::new("./configure") .args(&["--disable-shared", "--enable-static"]) // Only build static lib .args(&["--prefix", out_dir.to_str().unwrap()]) // Install on the outdir .arg("--with-pic") // Build position-independent code (required by Rust) - .output()); + ); // then make - err_to_panic(Command::new("make").output()); + execute_or_panic(&mut Command::new("make")); // "install" on the outdir - err_to_panic(Command::new("make").arg("install").output()); + execute_or_panic(Command::new("make").arg("install")); // return to rust-portaudio root err_to_panic(env::set_current_dir("..")); // cleaning portaudio sources - err_to_panic(Command::new("rm").arg("-rf") - .args(&[PORTAUDIO_TAR, PORTAUDIO_FOLDER]).output()); + execute_or_panic(Command::new("rm").arg("-rf") + .args(&[PORTAUDIO_TAR, PORTAUDIO_FOLDER])); } pub fn print_libs(out_dir: &Path) { @@ -120,10 +133,11 @@ mod platform { use super::unix_platform; use std::path::Path; + use super::execute_or_panic; use super::err_to_panic; pub fn download() { - err_to_panic(Command::new("wget").arg(unix_platform::PORTAUDIO_URL).output()); + execute_or_panic(Command::new("wget").arg(unix_platform::PORTAUDIO_URL)); } pub fn build(out_dir: &Path) { diff --git a/rust-portaudio-sys/.gitignore b/rust-portaudio-sys/.gitignore deleted file mode 100644 index 67a7572..0000000 --- a/rust-portaudio-sys/.gitignore +++ /dev/null @@ -1,30 +0,0 @@ -/lib/ - -# rust-empty -.DS_Store -*~ -*# -*.o -*.so -*.swp -*.dylib -*.dSYM -*.dll -*.rlib -*.dummy -*.exe -*-test -/bin/main -/bin/test-internal -/bin/test-external -/doc/ -/target/ -/build/ -/.rust/ -rusti.sh -watch.sh -/examples/** -!/examples/*.rs -!/examples/assets/ -.portaudio -Cargo.lock diff --git a/rust-portaudio-sys/Cargo.toml b/rust-portaudio-sys/Cargo.toml deleted file mode 100644 index 98a8028..0000000 --- a/rust-portaudio-sys/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] - -name = "portaudio_sys" -version = "0.1.0" -authors = ["Jeremy Letang ", - "Mitchell Nordine "] -description = "PortAudio bindings for Rust." -license = "MIT" -build = "build.rs" -homepage = "https://github.com/RustAudio/rust-portaudio" -repository = "https://github.com/RustAudio/rust-portaudio.git" -links = "portaudio" - -[lib] -name = "portaudio_sys" -crate-type = ["rlib"] - -[build-dependencies] -pkg-config = "0.3.6" diff --git a/rust-portaudio-sys/src/lib.rs b/src/ffi/mod.rs similarity index 92% rename from rust-portaudio-sys/src/lib.rs rename to src/ffi/mod.rs index 34bbb23..ea66354 100644 --- a/rust-portaudio-sys/src/lib.rs +++ b/src/ffi/mod.rs @@ -5,15 +5,15 @@ --blacklist-type PaStreamCallbackResult */ +mod portaudio; + #[cfg(any(target_os="macos", target_os="linux", target_os="win32", target_os="windows"))] mod c_library { #[link(name = "portaudio")] extern {} } -mod portaudio; - -pub use portaudio::*; +pub use self::portaudio::*; pub const PA_NO_DEVICE : PaDeviceIndex = -1; @@ -46,14 +46,14 @@ pub const OUTPUT_OVERFLOW : StreamCallbackFlags = 0x00000008; pub const PRIMING_OUTPUT : StreamCallbackFlags = 0x00000010; /// A function to convert C `*const char` arrays into Rust `&'a str`s. -pub fn c_str_to_str<'a>(c_str: *const std::os::raw::c_char) -> Result<&'a str, ::std::str::Utf8Error> { +pub fn c_str_to_str<'a>(c_str: *const ::std::os::raw::c_char) -> Result<&'a str, ::std::str::Utf8Error> { unsafe { ::std::ffi::CStr::from_ptr(c_str).to_str() } } /// A function to convert Rust strings to C strings -pub fn str_to_c_str(rust_str: &str) -> *const std::os::raw::c_char { +pub fn str_to_c_str(rust_str: &str) -> *const ::std::os::raw::c_char { rust_str.as_ptr() as *const _ } diff --git a/rust-portaudio-sys/src/portaudio.rs b/src/ffi/portaudio.rs similarity index 99% rename from rust-portaudio-sys/src/portaudio.rs rename to src/ffi/portaudio.rs index 8d1e57f..6cad581 100644 --- a/rust-portaudio-sys/src/portaudio.rs +++ b/src/ffi/portaudio.rs @@ -1,6 +1,7 @@ #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] +#![allow(dead_code)] /* automatically generated by rust-bindgen */ diff --git a/src/lib.rs b/src/lib.rs index 764e230..b4adc56 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,7 +54,6 @@ #[macro_use] extern crate bitflags; extern crate libc; extern crate num; -extern crate portaudio_sys as ffi; use num::FromPrimitive; use std::os::raw; @@ -108,8 +107,9 @@ use std::ptr; pub mod error; pub mod ext; pub mod stream; -mod types; +mod types; +mod ffi; /// A type-safe wrapper around the PortAudio API. ///