Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
54 changes: 45 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
6 changes: 6 additions & 0 deletions download.cmake
Original file line number Diff line number Diff line change
@@ -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}")