Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ script:
- if [ "$TRAVIS_OS_NAME" = linux ]; then curl -sL https://github.com/phracker/MacOSX-SDKs/releases/download/10.13/MacOSX10.13.sdk.tar.xz | tar -Jxf -; export COREAUDIO_SDK_PATH="$PWD/MacOSX10.13.sdk"; fi
- RUSTFMT=rustfmt cargo build --verbose --target=x86_64-apple-darwin
- if [ "$TRAVIS_OS_NAME" = osx ]; then RUSTFMT=rustfmt cargo test --verbose; fi
- if [ "$TRAVIS_OS_NAME" = osx ]; then rustup target add aarch64-apple-ios x86_64-apple-ios; for i in aarch64-apple-ios x86_64-apple-ios; do RUSTFMT=rustfmt cargo build --verbose --target=$i; done; fi
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ homepage = "https://github.com/RustAudio/coreaudio-sys"
repository = "https://github.com/RustAudio/coreaudio-sys.git"
build = "build.rs"

[target.'cfg(target_os = "ios")'.dependencies]
objc = "0.2.7"
block = "0.1.6"

[build-dependencies.bindgen]
version = "0.51"
#version = "0.52"
git = "https://github.com/rust-lang/rust-bindgen.git"
revision = "ba409edf5d3a1acc6ac4dcb32d1e168cc3a2a41b"
default-features = false

[features]
Expand Down
39 changes: 33 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ fn sdk_path(target: &str) -> Result<String, std::io::Error> {

let sdk = if target.contains("apple-darwin") {
"macosx"
} else if target.contains("apple-ios") {
} else if target == "x86_64-apple-ios" || target == "i386-apple-ios" {
"iphonesimulator"
} else if target == "aarch64-apple-ios"
|| target == "armv7-apple-ios"
|| target == "armv7s-apple-ios"
{
"iphoneos"
} else {
unreachable!();
Expand All @@ -37,7 +42,7 @@ fn build(sdk_path: Option<&str>, target: &str) {
use std::env;
use std::path::PathBuf;

let mut headers = vec![];
let mut headers: Vec<&str> = vec![];

#[cfg(feature = "audio_toolbox")]
{
Expand All @@ -54,7 +59,12 @@ fn build(sdk_path: Option<&str>, target: &str) {
#[cfg(feature = "core_audio")]
{
println!("cargo:rustc-link-lib=framework=CoreAudio");
headers.push("CoreAudio/CoreAudio.h");

if target.contains("apple-ios") {
headers.push("CoreAudio/CoreAudioTypes.h");
} else {
headers.push("CoreAudio/CoreAudio.h");
}
}

#[cfg(feature = "open_al")]
Expand All @@ -79,11 +89,30 @@ fn build(sdk_path: Option<&str>, target: &str) {
// Begin building the bindgen params.
let mut builder = bindgen::Builder::default();

// See https://github.com/rust-lang/rust-bindgen/issues/1211
// Technically according to the llvm mailing list, the argument to clang here should be
// -arch arm64 but it looks cleaner to just change the target.
let target = if target == "aarch64-apple-ios" {
"arm64-apple-ios"
} else {
target
};

builder = builder.clang_args(&[&format!("--target={}", target)]);

if let Some(sdk_path) = sdk_path {
builder = builder.clang_args(&["-isysroot", sdk_path]);
}
if target.contains("apple-ios") {
builder = builder.clang_args(&["-x", "objective-c", "-fblocks"]);
builder = builder.objc_extern_crate(true);
builder = builder.generate_block(true);
builder = builder.block_extern_crate(true);
builder = builder.rustfmt_bindings(true);
// time.h as has a variable called timezone that conflicts with some of the objective-c
// calls from NSCalendar.h in the Foundation framework. This removes that one variable.
builder = builder.blacklist_item("timezone");
}

let meta_header: Vec<_> = headers
.iter()
Expand All @@ -93,9 +122,7 @@ fn build(sdk_path: Option<&str>, target: &str) {
builder = builder.header_contents("coreaudio.h", &meta_header.concat());

// Generate the bindings.
builder = builder
.trust_clang_mangling(false)
.derive_default(true);
builder = builder.trust_clang_mangling(false).derive_default(true);

let bindings = builder.generate().expect("unable to generate bindings");

Expand Down