Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the CoreAudioTypes framework #467

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/header-translator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ proc-macro2 = "1.0.49"
syn = { version = "2.0", features = ["parsing"] }
heck = "0.4"
semver = { version = "1.0", features = ["serde"] }
four-char-code = "2.2.0"
2 changes: 2 additions & 0 deletions crates/header-translator/framework-includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

#import <Contacts/Contacts.h>

#import <CoreAudioTypes/CoreAudioTypes.h>

#import <CoreData/CoreData.h>

#import <CoreLocation/CoreLocation.h>
Expand Down
8 changes: 8 additions & 0 deletions crates/header-translator/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ impl Expr {
s = s.trim_start_matches('(').trim_end_matches(')').to_string();
}

// Handle four character codes
if s.len() == 6 && s.starts_with('\'') && s.ends_with('\'') {
let fcc = four_char_code::FourCharCode::from_str(&s[1..5])
.expect("Invalid four character code");

return Some(Self::Unsigned(fcc.as_u32().into()));
}

Some(Self::String(s))
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/header-translator/src/unexposed_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl UnexposedAttr {
"__unused" => None,
// We assume that a function is inline if it has a body, so not
// interesting.
"NS_INLINE" => None,
"CF_INLINE" | "NS_INLINE" => None,
// We don't synthethize properties, so irrelevant for us.
"NS_REQUIRES_PROPERTY_DEFINITIONS" => None,
// Weak specifiers - would be interesting if Rust supported weak statics
Expand Down Expand Up @@ -129,6 +129,7 @@ impl UnexposedAttr {
| "__WATCHOS_PROHIBITED"
| "__WATCHOS_UNAVAILABLE"
| "APPKIT_API_UNAVAILABLE_BEGIN_MACCATALYST"
| "CA_CANONICAL_DEPRECATED"
| "MP_INIT_UNAVAILABLE"
| "NS_AUTOMATED_REFCOUNT_UNAVAILABLE"
| "NS_AUTOMATED_REFCOUNT_WEAK_UNAVAILABLE"
Expand Down
12 changes: 12 additions & 0 deletions crates/header-translator/translation-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ maccatalyst = "13.0"
ios = "9.0"
watchos = "2.0"

[library.CoreAudioTypes]
imports = []
macos = "10.15"
maccatalyst = "13.0"
ios = "13.0"
tvos = "13.0"
watchos = "6.0"

[library.CoreData]
imports = ["Foundation"]
# Temporary, since some structs and statics use these
Expand Down Expand Up @@ -1567,3 +1575,7 @@ skipped-protocols = ["NSCopying", "NSMutableCopying"]
skipped-protocols = ["NSCopying", "NSMutableCopying"]
[class.NSPurgeableData]
skipped-protocols = ["NSCopying", "NSMutableCopying"]

# Requires a cast
[enum.anonymous.constants.AVAudioSessionErrorInsufficientPriority]
skipped = true
5 changes: 5 additions & 0 deletions crates/icrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,10 @@ CoreAnimation_all = [
"CoreAnimation_CATransition",
"CoreAnimation_CAValueFunction",
]
CoreAudioTypes = []
CoreAudioTypes_all = [
"CoreAudioTypes",
]
CoreData = [
"Foundation",
"CoreData_NSAsynchronousFetchResult",
Expand Down Expand Up @@ -5318,6 +5322,7 @@ unstable-frameworks-macos-13 = [
"BackgroundAssets_all",
"BusinessChat_all",
"CallKit_all",
"CoreAudioTypes_all",
"DeviceCheck_all",
"ExtensionKit_all",
"FileProviderUI_all",
Expand Down
11 changes: 11 additions & 0 deletions crates/icrate/src/CoreAudioTypes/fixes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::common::*;
use crate::CoreAudioTypes::*;

extern_enum!(
#[underlying(c_uint)]
pub enum __anonymous__ {
#[deprecated]
AVAudioSessionErrorInsufficientPriority =
AVAudioSessionErrorCodeInsufficientPriority as c_uint,
}
);
6 changes: 6 additions & 0 deletions crates/icrate/src/CoreAudioTypes/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod fixes;
#[path = "../generated/CoreAudioTypes/mod.rs"]
mod generated;

pub use self::fixes::*;
pub use self::generated::*;
1 change: 1 addition & 0 deletions crates/icrate/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ pub(crate) type FourCharCode = u32;
pub(crate) type OSType = FourCharCode;
pub(crate) type ResType = FourCharCode;
pub(crate) type UTF32Char = u32; // Or maybe Rust's char?
pub(crate) type OSStatus = i32;

pub(crate) const INT64_MAX: i64 = i64::MAX;
2 changes: 1 addition & 1 deletion crates/icrate/src/generated
2 changes: 2 additions & 0 deletions crates/icrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub mod CloudKit;
pub mod Contacts;
#[cfg(feature = "CoreAnimation")]
pub mod CoreAnimation;
#[cfg(feature = "CoreAudioTypes")]
pub mod CoreAudioTypes;
#[cfg(feature = "CoreData")]
pub mod CoreData;
#[cfg(feature = "CoreLocation")]
Expand Down
9 changes: 9 additions & 0 deletions crates/icrate/tests/four_char_codes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![cfg(feature = "CoreAudioTypes")]

use icrate::CoreAudioTypes::*;

#[test]
fn generated_four_char_code_is_correct() {
// 'lpcm' == 1819304813
assert_eq!(kAudioFormatLinearPCM, 1819304813);
}
Loading