Skip to content

Commit

Permalink
Add the CoreMedia framework
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Dec 15, 2024
1 parent 0ee4d68 commit 0395b8b
Show file tree
Hide file tree
Showing 28 changed files with 373 additions and 113 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

19 changes: 19 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ This project also draws inspiration from:
- [`rust-macios`](https://github.com/a-isaiahharvey/rust-macios)
- [`uikit-sys`](https://github.com/simlay/uikit-sys) and `@simlay`'s [Objective-C work on `bindgen`](https://rust-lang.github.io/rust-bindgen/objc.html)
- [`cidre`](https://github.com/yury/cidre)
- [the `apple-media` project](https://github.com/rust-media/apple-media-rs)

Finally, this is by far not the only project that ever tried to interoperate with Objective-C; other languages have done so as well (to varying degrees of success):
- Swift: Built from the beginning for Objective-C interop, and is what `objc2` aspires to have feature-parity with (though will probably never reach). Truly beautifully designed language!
Expand Down
12 changes: 10 additions & 2 deletions crates/header-translator/src/rust_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ impl Ty {
let mut attributed_name = attributed_ty.get_display_name();
let mut name = ty.get_display_name();
let mut unexposed_nullability = None;
let mut no_escape = false;

while let TypeKind::Unexposed | TypeKind::Attributed = ty.get_kind() {
if let TypeKind::Attributed = ty.get_kind() {
Expand Down Expand Up @@ -532,6 +533,10 @@ impl Ty {
Some(UnexposedAttr::ReturnsNotRetained) => {
lifetime = Lifetime::Autoreleasing;
}
Some(UnexposedAttr::NoEscape) => {
// TODO: Use this on Pointer and BlockPointer
no_escape = true;
}
Some(attr) => error!(?attr, "unknown attribute on type"),
None => {}
}
Expand Down Expand Up @@ -971,6 +976,9 @@ impl Ty {
"ssize_t" => return Self::Primitive(Primitive::ISize),
"size_t" => return Self::Primitive(Primitive::USize),
"ptrdiff_t" => return Self::Primitive(Primitive::PtrDiff),
// https://github.com/rust-lang/rust/issues/65473
"intptr_t" => return Self::Primitive(Primitive::ISize),
"uintptr_t" => return Self::Primitive(Primitive::USize),

// MacTypes.h
"UInt8" => return Self::Primitive(Primitive::U8),
Expand Down Expand Up @@ -1036,7 +1044,7 @@ impl Ty {

Self::Fn {
is_variadic: ty.is_variadic(),
no_escape: false,
no_escape,
arguments,
result_type: Box::new(result_type),
}
Expand Down Expand Up @@ -1909,7 +1917,7 @@ impl Ty {
Some(UnexposedAttr::NoEscape) => {
// TODO: Use this if mapping `fn + context ptr` to closure.
}
Some(UnexposedAttr::ReturnsRetained) => {
Some(UnexposedAttr::ReturnsRetained | UnexposedAttr::ReturnsNotRetained) => {
// TODO: Massage this into a lifetime
}
Some(attr) => {
Expand Down
10 changes: 6 additions & 4 deletions crates/header-translator/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,15 +1035,17 @@ impl Stmt {
immediate_children(entity, |entity, _span| match entity.get_kind() {
EntityKind::UnexposedAttr => {
if let Some(attr) = UnexposedAttr::parse(&entity, context) {
if kind.is_some() {
panic!("got multiple unexposed attributes {kind:?}, {attr:?}");
}
match attr {
// TODO
UnexposedAttr::Sendable => warn!("sendable typedef"),
UnexposedAttr::NonSendable => warn!("non-sendable typedef"),
UnexposedAttr::UIActor => warn!("main-thread-only typedef"),
_ => kind = Some(attr),
_ => {
if kind.is_some() {
warn!(?kind, ?attr, "got multiple unexposed attributes");
}
kind = Some(attr);
}
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions crates/header-translator/src/unexposed_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,18 @@ impl UnexposedAttr {
| "NS_EXTENSIBLE_STRING_ENUM"
| "CF_EXTENSIBLE_STRING_ENUM" => Some(Self::TypedExtensibleEnum),
"NS_SWIFT_BRIDGED_TYPEDEF" | "CF_SWIFT_BRIDGED_TYPEDEF" => Some(Self::BridgedTypedef),
"CF_BRIDGED_TYPE" => Some(Self::Bridged),
"CF_BRIDGED_TYPE" | "CM_BRIDGED_TYPE" => Some(Self::Bridged),
"CF_BRIDGED_MUTABLE_TYPE" => Some(Self::BridgedMutable),
"NS_RETURNS_RETAINED"
| "CF_RETURNS_RETAINED"
| "CM_RETURNS_RETAINED"
| "CM_RETURNS_RETAINED_BLOCK"
| "CM_RETURNS_RETAINED_PARAMETER"
| "CV_RETURNS_RETAINED"
| "CV_RETURNS_RETAINED_PARAMETER" => Some(Self::ReturnsRetained),
"NS_RETURNS_NOT_RETAINED" | "CF_RETURNS_NOT_RETAINED" => Some(Self::ReturnsNotRetained),
"NS_RETURNS_NOT_RETAINED"
| "CF_RETURNS_NOT_RETAINED"
| "CM_RETURNS_NOT_RETAINED_PARAMETER" => Some(Self::ReturnsNotRetained),
"NS_RETURNS_INNER_POINTER" => None,
// This has two arguments: `sendability` and `nullability`.
// `nullability` is already exposed, so we won't bother with that.
Expand All @@ -79,8 +84,11 @@ impl UnexposedAttr {
let _ = get_arguments();
None
}
"NS_SWIFT_SENDABLE" | "AS_SWIFT_SENDABLE" | "CV_SWIFT_SENDABLE" => Some(Self::Sendable),
"NS_SWIFT_NONSENDABLE" | "CV_SWIFT_NONSENDABLE" => Some(Self::NonSendable),
"NS_SWIFT_SENDABLE" | "AS_SWIFT_SENDABLE" | "CM_SWIFT_SENDABLE"
| "CV_SWIFT_SENDABLE" => Some(Self::Sendable),
"NS_SWIFT_NONSENDABLE" | "CM_SWIFT_NONSENDABLE" | "CV_SWIFT_NONSENDABLE" => {
Some(Self::NonSendable)
}
"NS_SWIFT_UI_ACTOR" | "WK_SWIFT_UI_ACTOR" => Some(Self::UIActor),
"NS_SWIFT_NONISOLATED" | "UIKIT_SWIFT_ACTOR_INDEPENDENT" => Some(Self::NonIsolated),
// TODO
Expand Down
1 change: 1 addition & 0 deletions crates/objc2/src/topics/about_generated/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- `CoreAudioTypes` / `objc2-core-audio-types`.
- `CoreGraphics` / `objc2-core-graphics`.
- `CoreFoundation` / `objc2-core-foundation`.
- `CoreMedia` / `objc2-core-media`.
- `CoreText` / `objc2-core-text`.
- `CoreVideo` / `objc2-core-video`.
- `EventKitUI` / `objc2-event-kit-ui`.
Expand Down
1 change: 1 addition & 0 deletions crates/objc2/src/topics/about_generated/list_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
| `CoreImage` | [![`objc2-core-image`](https://badgen.net/crates/v/objc2-core-image)](https://crates.io/crates/objc2-core-image) | [![docs.rs](https://docs.rs/objc2-core-image/badge.svg)](https://docs.rs/objc2-core-image/) |
| `CoreLocation` | [![`objc2-core-location`](https://badgen.net/crates/v/objc2-core-location)](https://crates.io/crates/objc2-core-location) | [![docs.rs](https://docs.rs/objc2-core-location/badge.svg)](https://docs.rs/objc2-core-location/) |
| `CoreML` | [![`objc2-core-ml`](https://badgen.net/crates/v/objc2-core-ml)](https://crates.io/crates/objc2-core-ml) | [![docs.rs](https://docs.rs/objc2-core-ml/badge.svg)](https://docs.rs/objc2-core-ml/) |
| `CoreMedia` | [![`objc2-core-media`](https://badgen.net/crates/v/objc2-core-media)](https://crates.io/crates/objc2-core-media) | [![docs.rs](https://docs.rs/objc2-core-media/badge.svg)](https://docs.rs/objc2-core-media/) |
| `CoreMotion` | [![`objc2-core-motion`](https://badgen.net/crates/v/objc2-core-motion)](https://crates.io/crates/objc2-core-motion) | [![docs.rs](https://docs.rs/objc2-core-motion/badge.svg)](https://docs.rs/objc2-core-motion/) |
| `CoreText` | [![`objc2-core-text`](https://badgen.net/crates/v/objc2-core-text)](https://crates.io/crates/objc2-core-text) | [![docs.rs](https://docs.rs/objc2-core-text/badge.svg)](https://docs.rs/objc2-core-text/) |
| `CoreVideo` | [![`objc2-core-video`](https://badgen.net/crates/v/objc2-core-video)](https://crates.io/crates/objc2-core-video) | [![docs.rs](https://docs.rs/objc2-core-video/badge.svg)](https://docs.rs/objc2-core-video/) |
Expand Down
19 changes: 13 additions & 6 deletions framework-crates/objc2-av-kit/Cargo.toml

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

5 changes: 0 additions & 5 deletions framework-crates/objc2-av-kit/translation-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,3 @@ class.AVPlayerItem.categories.AVKitAdditions.skipped = true
class.AVPlayerViewController.methods.player.skipped = true
class.AVPlayerViewController.methods."setPlayer:".skipped = true
protocol.AVPlayerViewControllerDelegate.methods."playerViewController:didSelectMediaSelectionOption:inMediaSelectionGroup:".skipped = true

# Needs CoreMedia
protocol.AVPictureInPictureSampleBufferPlaybackDelegate.methods."pictureInPictureControllerTimeRangeForPlayback:".skipped = true
protocol.AVPictureInPictureSampleBufferPlaybackDelegate.methods."pictureInPictureController:didTransitionToRenderSize:".skipped = true
protocol.AVPictureInPictureSampleBufferPlaybackDelegate.methods."pictureInPictureController:skipByInterval:completionHandler:".skipped = true
Loading

0 comments on commit 0395b8b

Please sign in to comment.