diff --git a/Cargo.toml b/Cargo.toml index 2fc9945..b5f8aff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,9 @@ crate-type = ["rlib"] [build-dependencies] pkg-config = "0.3.6" +[target.'cfg(windows)'.build-dependencies] +cmake = "0.1" + [dependencies] bitflags = "0.7" libc = "0.2.14" diff --git a/build.rs b/build.rs index bc0e78d..f7de249 100644 --- a/build.rs +++ b/build.rs @@ -140,23 +140,59 @@ mod platform { #[cfg(windows)] mod platform { + use std; use std::path::Path; + use std::process::Command; - const PORTAUDIO_DOWNLOAD_URL: &'static str = "http://www.portaudio.com"; + extern crate cmake; - fn print_lib_url() { - panic!("Don't know how to build portaudio on Windows yet. Sources and build instructions available at: {}", PORTAUDIO_DOWNLOAD_URL); + pub fn download() { + let mut command = Command::new("cmake"); + + command.arg("-P"); + command.arg("download.cmake"); + + match command.status() { + Ok(status) => + if !status.success() { + panic!("Failed to execute command: {:?}", command) + }, + Err(error) => + panic!("Failed to execute command: {:?}\n{}", command, error) + } } - pub fn download() { - print_lib_url(); + pub fn build(out_dir: &Path) { + let source_path = out_dir.join("portaudio"); + + // Note: the 'PA_WDMKS_NO_KSGUID_LIB' preprocessor definition is a + // workaround for an issue which is fixed in the newer versions. See + // https://app.assembla.com/spaces/portaudio/subversion/commits/1944 + cmake::Config::new(source_path) + .define("CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG", out_dir) + .define("CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE", out_dir) + .cflag("-DPA_WDMKS_NO_KSGUID_LIB") + .out_dir(out_dir) + .build_target("portaudio_static") + .build(); + + std::fs::rename( + out_dir.join(platform_specific_library_name()), + out_dir.join("portaudio.lib")).unwrap(); + } + + pub fn print_libs(out_dir: &Path) { + println!( + "cargo:rustc-link-search=native={}", out_dir.to_str().unwrap()); } - pub fn build(_: &Path) { - print_lib_url(); + #[cfg(target_arch = "x86")] + fn platform_specific_library_name() -> &'static str { + "portaudio_static_x86.lib" } - pub fn print_libs(_: &Path) { - print_lib_url(); + #[cfg(target_arch = "x86_64")] + fn platform_specific_library_name() -> &'static str { + "portaudio_static_x64.lib" } } diff --git a/download.cmake b/download.cmake new file mode 100644 index 0000000..cd89a61 --- /dev/null +++ b/download.cmake @@ -0,0 +1,6 @@ +set(url http://www.portaudio.com/archives/pa_stable_v19_20140130.tgz) +set(archive "$ENV{OUT_DIR}/portaudio.tgz") + +file(DOWNLOAD "${url}" "${archive}") +execute_process(COMMAND "${CMAKE_COMMAND}" -E tar xvf "${archive}" + WORKING_DIRECTORY "$ENV{OUT_DIR}")