Skip to content

Commit

Permalink
Merge pull request #600 from madsmtm/uikit
Browse files Browse the repository at this point in the history
Add UIKit framework crate (`objc2-ui-kit`)
  • Loading branch information
madsmtm authored May 10, 2024
2 parents c375275 + f099623 commit 75d24be
Show file tree
Hide file tree
Showing 24 changed files with 2,729 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ env:
FRAMEWORKS_MACOS_12: --package=objc2-accessibility --package=objc2-ad-services --package=objc2-ad-support --package=objc2-app-kit --package=objc2-authentication-services --package=objc2-automatic-assessment-configuration --package=objc2-automator --package=objc2-business-chat --package=objc2-class-kit --package=objc2-cloud-kit --package=objc2-contacts --package=objc2-core-bluetooth --package=objc2-core-data --package=objc2-core-location --package=objc2-core-wlan --package=objc2-data-detection --package=objc2-device-check --package=objc2-event-kit --package=objc2-exception-handling --package=objc2-external-accessory --package=objc2-file-provider --package=objc2-file-provider-ui --package=objc2-foundation --package=objc2-game-controller --package=objc2-game-kit --package=objc2-identity-lookup --package=objc2-input-method-kit --package=objc2-link-presentation --package=objc2-local-authentication --package=objc2-local-authentication-embedded-ui --package=objc2-mail-kit --package=objc2-map-kit --package=objc2-media-player --package=objc2-metal --package=objc2-metal-kit --package=objc2-metric-kit --package=objc2-osa-kit --package=objc2-photos --package=objc2-quartz-core --package=objc2-service-management --package=objc2-sound-analysis --package=objc2-speech --package=objc2-store-kit --package=objc2-uniform-type-identifiers --package=objc2-user-notifications --package=objc2-virtualization --package=objc2-web-kit
FRAMEWORKS_MACOS_13: --package=objc2-accessibility --package=objc2-ad-services --package=objc2-ad-support --package=objc2-app-kit --package=objc2-authentication-services --package=objc2-automatic-assessment-configuration --package=objc2-automator --package=objc2-background-assets --package=objc2-business-chat --package=objc2-call-kit --package=objc2-class-kit --package=objc2-cloud-kit --package=objc2-contacts --package=objc2-core-bluetooth --package=objc2-core-data --package=objc2-core-location --package=objc2-core-wlan --package=objc2-data-detection --package=objc2-device-check --package=objc2-event-kit --package=objc2-exception-handling --package=objc2-extension-kit --package=objc2-external-accessory --package=objc2-file-provider --package=objc2-file-provider-ui --package=objc2-foundation --package=objc2-game-controller --package=objc2-game-kit --package=objc2-health-kit --package=objc2-identity-lookup --package=objc2-input-method-kit --package=objc2-link-presentation --package=objc2-local-authentication --package=objc2-local-authentication-embedded-ui --package=objc2-mail-kit --package=objc2-map-kit --package=objc2-media-player --package=objc2-metal --package=objc2-metal-fx --package=objc2-metal-kit --package=objc2-metric-kit --package=objc2-osa-kit --package=objc2-photos --package=objc2-quartz-core --package=objc2-service-management --package=objc2-sound-analysis --package=objc2-speech --package=objc2-store-kit --package=objc2-uniform-type-identifiers --package=objc2-user-notifications --package=objc2-virtualization --package=objc2-web-kit
FRAMEWORKS_MACOS_14: --package=objc2-accessibility --package=objc2-ad-services --package=objc2-ad-support --package=objc2-app-kit --package=objc2-authentication-services --package=objc2-automatic-assessment-configuration --package=objc2-automator --package=objc2-background-assets --package=objc2-business-chat --package=objc2-call-kit --package=objc2-class-kit --package=objc2-cloud-kit --package=objc2-contacts --package=objc2-core-bluetooth --package=objc2-core-data --package=objc2-core-location --package=objc2-core-wlan --package=objc2-data-detection --package=objc2-device-check --package=objc2-event-kit --package=objc2-exception-handling --package=objc2-extension-kit --package=objc2-external-accessory --package=objc2-file-provider --package=objc2-file-provider-ui --package=objc2-foundation --package=objc2-game-controller --package=objc2-game-kit --package=objc2-health-kit --package=objc2-identity-lookup --package=objc2-input-method-kit --package=objc2-link-presentation --package=objc2-local-authentication --package=objc2-local-authentication-embedded-ui --package=objc2-mail-kit --package=objc2-map-kit --package=objc2-media-player --package=objc2-metal --package=objc2-metal-fx --package=objc2-metal-kit --package=objc2-metric-kit --package=objc2-osa-kit --package=objc2-photos --package=objc2-quartz-core --package=objc2-service-management --package=objc2-sound-analysis --package=objc2-speech --package=objc2-store-kit --package=objc2-symbols --package=objc2-uniform-type-identifiers --package=objc2-user-notifications --package=objc2-virtualization --package=objc2-web-kit
FRAMEWORKS_IOS_10: --package=objc2-foundation --package=objc2-metal
FRAMEWORKS_IOS_10: --package=objc2-foundation --package=objc2-metal --package=objc2-ui-kit
FRAMEWORKS_GNUSTEP: --package=objc2-app-kit --package=objc2-core-data --package=objc2-foundation
# END AUTOMATICALLY GENERATED

Expand Down
17 changes: 17 additions & 0 deletions Cargo.lock

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

16 changes: 8 additions & 8 deletions crates/header-translator/framework-includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#import <Automator/Automator.h>
#import <MailKit/MailKit.h>
#import <OSAKit/OSAKit.h>
#import <ServiceManagement/ServiceManagement.h>
#import <InputMethodKit/InputMethodKit.h>
#import <ExceptionHandling/ExceptionHandling.h>
#import <CoreWLAN/CoreWLAN.h>
#import <Virtualization/Virtualization.h>
#endif

Expand Down Expand Up @@ -38,16 +42,12 @@

#import <CoreLocation/CoreLocation.h>

#import <CoreWLAN/CoreWLAN.h>

#import <DataDetection/DataDetection.h>

#import <DeviceCheck/DeviceCheck.h>

#import <EventKit/EventKit.h>

#import <ExceptionHandling/ExceptionHandling.h>

#import <ExtensionKit/ExtensionKit.h>

#import <ExternalAccessory/ExternalAccessory.h>
Expand All @@ -66,8 +66,6 @@

#import <IdentityLookup/IdentityLookup.h>

#import <InputMethodKit/InputMethodKit.h>

#import <LinkPresentation/LinkPresentation.h>

#import <LocalAuthentication/LocalAuthentication.h>
Expand All @@ -90,8 +88,6 @@

#import <QuartzCore/CoreAnimation.h>

#import <ServiceManagement/ServiceManagement.h>

#import <SoundAnalysis/SoundAnalysis.h>

#import <Speech/Speech.h>
Expand All @@ -105,3 +101,7 @@
#import <UserNotifications/UserNotifications.h>

#import <WebKit/WebKit.h>

#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#endif
5 changes: 1 addition & 4 deletions crates/header-translator/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ impl Location {
Some(krate.to_string())
}
} else {
debug!(
library = self.library,
"tried to get feature name of unknown library"
);
debug!(?self, "tried to get feature name of unknown library");
None
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/header-translator/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ impl Library {

// Output `src/generated/*.rs`.
for (name, file) in &self.files {
let _span = debug_span!("writing file", name).entered();

let name = clean_name(name);
let mut path = generated_dir.join(name);
path.set_extension("rs");
Expand Down
33 changes: 26 additions & 7 deletions crates/header-translator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn main() -> Result<(), BoxError> {
error!("should have one of each platform: {sdks:?}");
}

let mut libraries = None;
let mut libraries = BTreeMap::new();

// TODO: Compare between SDKs
for sdk in sdks {
Expand All @@ -95,7 +95,7 @@ fn main() -> Result<(), BoxError> {
// "i686-apple-macosx10.12.0",
],
Platform::IPhoneOs => &[
// "arm64-apple-ios10.0.0",
"arm64-apple-ios10.0.0",
// "armv7s-apple-ios10.0.0",
// "arm64-apple-ios14.0-macabi",
// "x86_64-apple-ios13.0-macabi",
Expand Down Expand Up @@ -128,12 +128,28 @@ fn main() -> Result<(), BoxError> {
}
}

if sdk.platform == Platform::MacOsX {
libraries = result;
let result = result.unwrap();

// Hacky way to support UIKit
match sdk.platform {
Platform::MacOsX => {
for (name, library) in result {
if library.data.macos.is_some() {
libraries.insert(name, library);
}
}
}
Platform::IPhoneOs => {
for (name, library) in result {
if library.data.macos.is_none() {
libraries.insert(name, library);
}
}
}
_ => {}
}
}

let mut libraries = libraries.expect("got a result");
let span = info_span!("analyzing").entered();
for (name, library) in &mut libraries {
let _span = debug_span!("library", name).entered();
Expand Down Expand Up @@ -333,7 +349,7 @@ fn get_translation_unit<'i: 'tu, 'tu>(
.include_attributed_types(true)
.visit_implicit_attributes(true)
// .ignore_non_errors_from_included_files(true)
.retain_excluded_conditional_blocks(true)
// .retain_excluded_conditional_blocks(true)
.arguments(&[
"-x",
"objective-c",
Expand Down Expand Up @@ -463,7 +479,10 @@ fn update_ci(workspace_dir: &Path, config: &Config) -> io::Result<()> {
writer(&mut ci, config, "FRAMEWORKS_IOS_10", |lib| {
// HACK: We can't test iOS frameworks with the `"all"` feature, as
// that enables `objc2-app-kit` as well.
matches!(&*lib.krate, "objc2-foundation" | "objc2-metal")
matches!(
&*lib.krate,
"objc2-foundation" | "objc2-metal" | "objc2-ui-kit"
)
})?;
writer(&mut ci, config, "FRAMEWORKS_GNUSTEP", |lib| {
lib.gnustep
Expand Down
3 changes: 3 additions & 0 deletions crates/header-translator/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ impl MethodModifiers {
EntityKind::VisibilityAttr => {
// TODO: Handle these visibility attributes
}
EntityKind::AnnotateAttr => {
// TODO: `UI_APPEARANCE_SELECTOR`
}
_ => error!("unknown"),
});

Expand Down
12 changes: 8 additions & 4 deletions crates/header-translator/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::collections::BTreeSet;
use std::collections::HashSet;
use std::fmt;
use std::iter;
use std::mem;

use clang::{Entity, EntityKind, EntityVisitResult};

Expand Down Expand Up @@ -581,7 +580,10 @@ fn parse_fn_param_children(entity: &Entity<'_>, context: &Context<'_>) {
error!(?attr, "unknown attribute");
}
}
EntityKind::ObjCClassRef | EntityKind::TypeRef | EntityKind::ObjCProtocolRef => {}
EntityKind::ObjCClassRef
| EntityKind::TypeRef
| EntityKind::ObjCProtocolRef
| EntityKind::ParmDecl => {}
EntityKind::NSConsumed => {
error!("found NSConsumed, which requires manual handling");
}
Expand Down Expand Up @@ -1568,7 +1570,7 @@ impl Stmt {

pub fn fmt<'a>(&'a self, config: &'a Config) -> impl fmt::Display + 'a {
FormatterFn(move |f| {
let _span = debug_span!("stmt", discriminant = ?mem::discriminant(self)).entered();
let _span = debug_span!("stmt", provided_item = ?self.provided_item()).entered();

struct GenericTyHelper<'a>(&'a [String]);

Expand Down Expand Up @@ -1933,9 +1935,11 @@ impl Stmt {
("Foundation", "NSMutableCopying") => ("?Sized + IsIdCloneable", None),
// TODO: Do we need further tweaks to this?
("Foundation", "NSFastEnumeration") => ("?Sized", None),
// AppKit fixes. TODO: Should we add more bounds here?
// AppKit/UIKit fixes. TODO: Should we add more bounds here?
("AppKit", "NSCollectionViewDataSource") => ("?Sized", None),
("UIKit", "UICollectionViewDataSource") => ("?Sized + Message", None),
("AppKit", "NSTableViewDataSource") => ("?Sized", None),
("UIKit", "UITableViewDataSource") => ("?Sized + Message", None),
_ => {
error!(
?protocol,
Expand Down
16 changes: 13 additions & 3 deletions crates/header-translator/src/unexposed_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl UnexposedAttr {
"NS_SWIFT_SENDABLE" | "AS_SWIFT_SENDABLE" => Some(Self::Sendable),
"NS_SWIFT_NONSENDABLE" => Some(Self::NonSendable),
"NS_SWIFT_UI_ACTOR" => Some(Self::UIActor),
"NS_SWIFT_NONISOLATED" => Some(Self::NonIsolated),
"NS_SWIFT_NONISOLATED" | "UIKIT_SWIFT_ACTOR_INDEPENDENT" => Some(Self::NonIsolated),
// TODO
"NS_FORMAT_FUNCTION" | "NS_FORMAT_ARGUMENT" => {
let _ = get_arguments();
Expand Down Expand Up @@ -111,19 +111,22 @@ impl UnexposedAttr {
| "API_DEPRECATED_WITH_REPLACEMENT"
| "API_UNAVAILABLE_BEGIN"
| "API_UNAVAILABLE"
| "CF_AVAILABLE_IOS"
| "CF_AVAILABLE_MAC"
| "CF_SWIFT_UNAVAILABLE"
| "CG_AVAILABLE_BUT_DEPRECATED"
| "CG_AVAILABLE_STARTING"
| "CK_UNAVAILABLE"
| "FPUI_AVAILABLE"
| "MP_API"
| "MP_DEPRECATED_WITH_REPLACEMENT"
| "MP_DEPRECATED"
| "MP_DEPRECATED_WITH_REPLACEMENT"
| "MP_UNAVAILABLE_BEGIN"
| "MP_UNAVAILABLE"
| "NS_AVAILABLE_IOS"
| "NS_AVAILABLE_MAC"
| "NS_AVAILABLE"
| "NS_CLASS_AVAILABLE_IOS"
| "NS_CLASS_AVAILABLE_MAC"
| "NS_CLASS_AVAILABLE"
| "NS_CLASS_DEPRECATED_IOS"
Expand All @@ -132,18 +135,24 @@ impl UnexposedAttr {
| "NS_DEPRECATED_MAC"
| "NS_DEPRECATED"
| "NS_ENUM_AVAILABLE"
| "NS_ENUM_AVAILABLE_IOS"
| "NS_ENUM_AVAILABLE_MAC"
| "NS_ENUM_DEPRECATED"
| "NS_ENUM_DEPRECATED_IOS"
| "NS_ENUM_DEPRECATED_MAC"
| "NS_EXTENSION_UNAVAILABLE"
| "NS_EXTENSION_UNAVAILABLE_IOS"
| "NS_OPENGL_CLASS_DEPRECATED"
| "NS_OPENGL_DEPRECATED"
| "NS_OPENGL_ENUM_DEPRECATED"
| "NS_SWIFT_UNAVAILABLE"
| "OBJC_AVAILABLE"
| "OBJC_DEPRECATED"
| "OBJC_SWIFT_UNAVAILABLE"
| "UIKIT_AVAILABLE_TVOS_ONLY"
| "UIKIT_AVAILABLE_IOS_ONLY"
| "UIKIT_CLASS_AVAILABLE_IOS_ONLY"
| "UIKIT_CLASS_AVAILABLE_IOS_TVOS"
| "WEBKIT_AVAILABLE_MAC"
| "WEBKIT_CLASS_DEPRECATED_MAC"
| "WEBKIT_DEPRECATED_MAC"
Expand All @@ -169,7 +178,8 @@ impl UnexposedAttr {
| "NS_AUTOMATED_REFCOUNT_WEAK_UNAVAILABLE"
| "NS_UNAVAILABLE"
| "UNAVAILABLE_ATTRIBUTE"
| "UT_AVAILABLE_BEGIN" => None,
| "UT_AVAILABLE_BEGIN"
| "MP_DEPRECATED_BEGIN" => None,
s if s.starts_with("AVAILABLE_MAC_OS_X_VERSION_") => None,
s if s.starts_with("DEPRECATED_IN_MAC_OS_X_VERSION_") => None,
s if s.starts_with("FILEPROVIDER_API_AVAILABILITY_") => None,
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 @@ -50,6 +50,7 @@
| `Speech` | [![`objc2-speech`](https://badgen.net/crates/v/objc2-speech)](https://crates.io/crates/objc2-speech) | [![docs.rs](https://docs.rs/objc2-speech/badge.svg)](https://docs.rs/objc2-speech/) |
| `StoreKit` | [![`objc2-store-kit`](https://badgen.net/crates/v/objc2-store-kit)](https://crates.io/crates/objc2-store-kit) | [![docs.rs](https://docs.rs/objc2-store-kit/badge.svg)](https://docs.rs/objc2-store-kit/) |
| `Symbols` | [![`objc2-symbols`](https://badgen.net/crates/v/objc2-symbols)](https://crates.io/crates/objc2-symbols) | [![docs.rs](https://docs.rs/objc2-symbols/badge.svg)](https://docs.rs/objc2-symbols/) |
| `UIKit` | [![`objc2-ui-kit`](https://badgen.net/crates/v/objc2-ui-kit)](https://crates.io/crates/objc2-ui-kit) | [![docs.rs](https://docs.rs/objc2-ui-kit/badge.svg)](https://docs.rs/objc2-ui-kit/) |
| `UniformTypeIdentifiers` | [![`objc2-uniform-type-identifiers`](https://badgen.net/crates/v/objc2-uniform-type-identifiers)](https://crates.io/crates/objc2-uniform-type-identifiers) | [![docs.rs](https://docs.rs/objc2-uniform-type-identifiers/badge.svg)](https://docs.rs/objc2-uniform-type-identifiers/) |
| `UserNotifications` | [![`objc2-user-notifications`](https://badgen.net/crates/v/objc2-user-notifications)](https://crates.io/crates/objc2-user-notifications) | [![docs.rs](https://docs.rs/objc2-user-notifications/badge.svg)](https://docs.rs/objc2-user-notifications/) |
| `Virtualization` | [![`objc2-virtualization`](https://badgen.net/crates/v/objc2-virtualization)](https://crates.io/crates/objc2-virtualization) | [![docs.rs](https://docs.rs/objc2-virtualization/badge.svg)](https://docs.rs/objc2-virtualization/) |
Expand Down
3 changes: 3 additions & 0 deletions framework-crates/objc2-event-kit/translation-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ ios = "4.0"
watchos = "2.0"
visionos = "1.0"

# CF_RETURNS_NOT_RETAINED
class.EKParticipant.methods."ABRecordWithAddressBook:".skipped = true

# Needs `CGColorRef`
class.EKCalendar.methods.CGColor.skipped = true
class.EKCalendar.methods."setCGColor:".skipped = true
Expand Down
3 changes: 3 additions & 0 deletions framework-crates/objc2-quartz-core/translation-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class.CAMetalDisplayLinkUpdate.methods.drawable.skipped = true
# I'm unsure of the ABI of the array this takes
class.CAMediaTimingFunction.methods."getControlPointAtIndex:values:".skipped = true

# Needs `EAGLDrawable` from `OpenGLES`
class.CAEAGLLayer.skipped-protocols = ["EAGLDrawable"]

###
### Safety
###
Expand Down
Loading

0 comments on commit 75d24be

Please sign in to comment.