From 13d10316e8b51eb1254e02eef96a8804fc592af3 Mon Sep 17 00:00:00 2001 From: johannes Date: Tue, 30 May 2017 09:47:32 +0200 Subject: [PATCH 1/3] moved ffi from extern crate to internal mod --- Cargo.toml | 6 +++- rust-portaudio-sys/build.rs => build.rs | 35 +++++++++++++------ rust-portaudio-sys/.gitignore | 30 ---------------- rust-portaudio-sys/Cargo.toml | 19 ---------- .../src/lib.rs => src/ffi/mod.rs | 10 +++--- .../src => src/ffi}/portaudio.rs | 1 + src/lib.rs | 4 +-- 7 files changed, 37 insertions(+), 68 deletions(-) rename rust-portaudio-sys/build.rs => build.rs (79%) delete mode 100644 rust-portaudio-sys/.gitignore delete mode 100644 rust-portaudio-sys/Cargo.toml rename rust-portaudio-sys/src/lib.rs => src/ffi/mod.rs (92%) rename {rust-portaudio-sys/src => src/ffi}/portaudio.rs (99%) 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..13a6982 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,6 +81,7 @@ 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"; @@ -76,35 +89,35 @@ mod unix_platform { 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,10 @@ mod platform { use super::unix_platform; use std::path::Path; - use super::err_to_panic; + use super::execute_or_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) { @@ -134,7 +147,7 @@ mod platform { let portaudio_pc_file = out_dir.join("lib/pkgconfig/portaudio-2.0.pc"); let portaudio_pc_file = portaudio_pc_file.to_str().unwrap(); - err_to_panic(pkg_config::Config::new().statik(true).find(portaudio_pc_file)); + execute_or_panic(pkg_config::Config::new().statik(true).find(portaudio_pc_file)); } } 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. /// From 0579a4e16d19ec02fc554f893d46af3b40e1fdf2 Mon Sep 17 00:00:00 2001 From: johannes Date: Tue, 30 May 2017 10:01:12 +0200 Subject: [PATCH 2/3] fixed compiler error on linux --- build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 13a6982..a2907f4 100644 --- a/build.rs +++ b/build.rs @@ -134,6 +134,7 @@ mod platform { use std::path::Path; use super::execute_or_panic; + use super::err_to_panic; pub fn download() { execute_or_panic(Command::new("wget").arg(unix_platform::PORTAUDIO_URL)); @@ -147,7 +148,7 @@ mod platform { let portaudio_pc_file = out_dir.join("lib/pkgconfig/portaudio-2.0.pc"); let portaudio_pc_file = portaudio_pc_file.to_str().unwrap(); - execute_or_panic(pkg_config::Config::new().statik(true).find(portaudio_pc_file)); + err_to_panic(pkg_config::Config::new().statik(true).find(portaudio_pc_file)); } } From 52c90ad2faa8ba0050c2ab8549f80058505084a6 Mon Sep 17 00:00:00 2001 From: Johannes Schoisswohl Date: Sun, 12 Nov 2017 14:22:13 +0100 Subject: [PATCH 3/3] use new portaudio version pa_stable_v190600_20161030.tgz --- build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index a2907f4..f5b2ffc 100644 --- a/build.rs +++ b/build.rs @@ -84,8 +84,8 @@ mod unix_platform { 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() {