Skip to content

Commit effa043

Browse files
Merge pull request #33 from simlay/add-ios-support
Fixes iOS compiling.
2 parents 8d27848 + ff8b3fe commit effa043

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

.github/workflows/coreaudio-sys.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ jobs:
2121
- name: cargo test - all features
2222
run: cargo test --all-features --verbose
2323

24+
- name: add ios targets
25+
run: rustup target add aarch64-apple-ios x86_64-apple-ios
26+
- name: Build ios targets
27+
run: for i in aarch64-apple-ios x86_64-apple-ios; do cargo build --verbose --target=$i; done
28+
2429
# Build the docs with all features to make sure docs.rs will work.
2530
macos-docs:
2631
runs-on: macOS-latest

build.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ fn sdk_path(target: &str) -> Result<String, std::io::Error> {
1111

1212
let sdk = if target.contains("apple-darwin") {
1313
"macosx"
14-
} else if target.contains("apple-ios") {
14+
} else if target == "x86_64-apple-ios" || target == "i386-apple-ios" {
15+
"iphonesimulator"
16+
} else if target == "aarch64-apple-ios"
17+
|| target == "armv7-apple-ios"
18+
|| target == "armv7s-apple-ios"
19+
{
1520
"iphoneos"
1621
} else {
1722
unreachable!();
@@ -47,14 +52,19 @@ fn build(sdk_path: Option<&str>, target: &str) {
4752

4853
#[cfg(feature = "audio_unit")]
4954
{
50-
println!("cargo:rustc-link-lib=framework=AudioUnit");
55+
println!("cargo:rustc-link-lib=framework=AudioToolbox");
5156
headers.push("AudioUnit/AudioUnit.h");
5257
}
5358

5459
#[cfg(feature = "core_audio")]
5560
{
5661
println!("cargo:rustc-link-lib=framework=CoreAudio");
57-
headers.push("CoreAudio/CoreAudio.h");
62+
63+
if target.contains("apple-ios") {
64+
headers.push("CoreAudio/CoreAudioTypes.h");
65+
} else {
66+
headers.push("CoreAudio/CoreAudio.h");
67+
}
5868
}
5969

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

92+
// See https://github.com/rust-lang/rust-bindgen/issues/1211
93+
// Technically according to the llvm mailing list, the argument to clang here should be
94+
// -arch arm64 but it looks cleaner to just change the target.
95+
let target = if target == "aarch64-apple-ios" {
96+
"arm64-apple-ios"
97+
} else {
98+
target
99+
};
82100
builder = builder.size_t_is_usize(true);
83101

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

86104
if let Some(sdk_path) = sdk_path {
87105
builder = builder.clang_args(&["-isysroot", sdk_path]);
88106
}
107+
if target.contains("apple-ios") {
108+
// time.h as has a variable called timezone that conflicts with some of the objective-c
109+
// calls from NSCalendar.h in the Foundation framework. This removes that one variable.
110+
builder = builder.blacklist_item("timezone");
111+
builder = builder.blacklist_item("objc_object");
112+
}
89113

90114
let meta_header: Vec<_> = headers
91115
.iter()
@@ -95,9 +119,7 @@ fn build(sdk_path: Option<&str>, target: &str) {
95119
builder = builder.header_contents("coreaudio.h", &meta_header.concat());
96120

97121
// Generate the bindings.
98-
builder = builder
99-
.trust_clang_mangling(false)
100-
.derive_default(true);
122+
builder = builder.trust_clang_mangling(false).derive_default(true);
101123

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

0 commit comments

Comments
 (0)