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 CoreFoundation framework #471

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c2deb90
Add `CoreFoundation` framework boilerplate
samuelsleight Jun 19, 2023
cd451c3
Add some new `unexposed_attr`s
samuelsleight Jun 19, 2023
1d18fde
Treat `Bridged` types like `BridgedTypedef` types
samuelsleight Jun 19, 2023
0d1abd1
Use `libc` for a quantity of typedefs
samuelsleight Jun 19, 2023
d12dfd3
Final changes to get the `CoreFoundation` framework building
samuelsleight Jun 19, 2023
dc5614d
Get `Foundation` building
samuelsleight Jun 19, 2023
69c8115
Get `AppKit` building
samuelsleight Jun 20, 2023
ecee70d
Get `AuthenticationServices` building
samuelsleight Jun 20, 2023
fd03e2f
Get `Automator` building
samuelsleight Jun 20, 2023
fd7e333
Get `BusinessChat` building
samuelsleight Jun 20, 2023
32cf56a
Get `MapKit` building
samuelsleight Jun 20, 2023
1bc8a47
Get `FIleProvider` building
samuelsleight Jun 20, 2023
35c26f2
Get `GameKit` building
samuelsleight Jun 20, 2023
ecb575e
Get `InputMethodKit` building
samuelsleight Jun 20, 2023
81789f9
Get `LinkPresentation` building
samuelsleight Jun 20, 2023
b599607
Get `LocalAuthenticationEmbeddedUI` building
samuelsleight Jun 20, 2023
d3a2b70
Get `MediaPlayer` building
samuelsleight Jun 20, 2023
e232671
Get `MetalKit` building
samuelsleight Jun 20, 2023
9cddf0a
Get `OSAKit` building
samuelsleight Jun 20, 2023
b15520c
Get `PhotoKit` building
samuelsleight Jun 20, 2023
bb362dc
Get `CoreAnimation` building
samuelsleight Jun 20, 2023
35e6760
Get `StoreKit` building
samuelsleight Jun 20, 2023
fb6c529
Get `WebKit` building
samuelsleight Jun 20, 2023
706b194
Get `Accessibility` building
samuelsleight Jun 20, 2023
6335e4a
Fix tests building
samuelsleight Jun 20, 2023
df5e708
Allow `ParmDecl` as an entity type in function parameters
samuelsleight Jun 21, 2023
4272df4
Don't fail on functions tagged with `ReturnsRetained`
samuelsleight Jun 24, 2023
47b1c86
Add some more system headers
samuelsleight Jun 24, 2023
91a0777
Update the generated code submodule
samuelsleight Jun 24, 2023
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
5 changes: 3 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/header-translator/framework-includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

#import <CoreData/CoreData.h>

#import <CoreFoundation/CoreFoundation.h>

#import <CoreLocation/CoreLocation.h>

#import <DataDetection/DataDetection.h>
Expand Down
6 changes: 6 additions & 0 deletions crates/header-translator/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ impl<'a> Context<'a> {
include_dir: sdk.path.join("usr/include"),
system_headers: HashSet::from([
Path::new("MacTypes.h"),
Path::new("mach/machine.h"),
Path::new("sys/acl.h"),
Path::new("sys/_types/_mach_port_t.h"),
Path::new("sys/_types/_mode_t.h"),
Path::new("sys/_types/_gid_t.h"),
Path::new("sys/_types/_uid_t.h"),
Path::new("objc/objc.h"),
Path::new("objc/NSObject.h"),
Path::new("objc/NSObjCRuntime.h"),
Expand Down
15 changes: 11 additions & 4 deletions crates/header-translator/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,10 @@ fn parse_fn_param_children(entity: &Entity<'_>, context: &Context<'_>) {
error!(?attr, "unknown attribute");
}
}
EntityKind::ObjCClassRef | EntityKind::TypeRef | EntityKind::ObjCProtocolRef => {}
EntityKind::ParmDecl
| EntityKind::ObjCClassRef
| EntityKind::TypeRef
| EntityKind::ObjCProtocolRef => {}
EntityKind::NSConsumed => {
error!("found NSConsumed, which requires manual handling");
}
Expand Down Expand Up @@ -1051,8 +1054,12 @@ impl Stmt {

immediate_children(entity, |entity, _span| match entity.get_kind() {
EntityKind::UnexposedAttr => {
if let Some(attr) = UnexposedAttr::parse(&entity, context) {
error!(?attr, "unknown attribute");
match UnexposedAttr::parse(&entity, context) {
Some(UnexposedAttr::ReturnsRetained) => {
// TODO: Ignore for now, but at some point handle in a similar way to in methods
}
Some(attr) => error!(?attr, "unknown attribute"),
None => {}
}
}
EntityKind::ObjCClassRef
Expand Down Expand Up @@ -1711,7 +1718,7 @@ impl fmt::Display for Stmt {
Some(UnexposedAttr::TypedExtensibleEnum) => {
writeln!(f, "typed_extensible_enum!(pub type {} = {ty};);", id.name)?;
}
None | Some(UnexposedAttr::BridgedTypedef) => {
None | Some(UnexposedAttr::BridgedTypedef | UnexposedAttr::Bridged) => {
// "bridged" typedefs should use a normal type alias.
writeln!(f, "pub type {} = {ty};", id.name)?;
}
Expand Down
21 changes: 15 additions & 6 deletions crates/header-translator/src/unexposed_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,35 @@ impl UnexposedAttr {
let _ = get_arguments();
Some(Self::ErrorEnum)
}
"NS_TYPED_ENUM" | "NS_STRING_ENUM" | "CF_TYPED_ENUM" => Some(Self::TypedEnum),
"NS_TYPED_ENUM" | "NS_STRING_ENUM" | "CF_TYPED_ENUM" | "CF_STRING_ENUM" => {
Some(Self::TypedEnum)
}
"_NS_TYPED_EXTENSIBLE_ENUM"
| "NS_TYPED_EXTENSIBLE_ENUM"
| "CF_TYPED_EXTENSIBLE_ENUM"
| "NS_EXTENSIBLE_STRING_ENUM" => Some(Self::TypedExtensibleEnum),
| "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_MUTABLE_TYPE" => Some(Self::BridgedMutable),
"NS_RETURNS_RETAINED" | "CF_RETURNS_RETAINED" => Some(Self::ReturnsRetained),
"NS_RETURNS_NOT_RETAINED" | "CF_RETURNS_NOT_RETAINED" => Some(Self::ReturnsNotRetained),
"NS_RETURNS_INNER_POINTER" => None,
// TODO
"NS_FORMAT_FUNCTION" | "NS_FORMAT_ARGUMENT" => {
"CF_FORMAT_ARGUMENT" | "CF_FORMAT_FUNCTION" | "NS_FORMAT_FUNCTION"
| "NS_FORMAT_ARGUMENT" => {
let _ = get_arguments();
None
}
// TODO
"NS_NOESCAPE" => None,
"CF_NOESCAPE" | "NS_NOESCAPE" => None,
// TODO: We could potentially automatically elide this argument
// from the method call, though it's rare enough that it's
// probably not really worth the effort.
"__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 All @@ -84,6 +88,8 @@ impl UnexposedAttr {
| "API_DEPRECATED"
| "API_UNAVAILABLE_BEGIN"
| "API_UNAVAILABLE"
| "CF_AVAILABLE"
| "CF_DEPRECATED"
| "CF_SWIFT_UNAVAILABLE"
| "CG_AVAILABLE_BUT_DEPRECATED"
| "CG_AVAILABLE_STARTING"
Expand Down Expand Up @@ -130,6 +136,7 @@ impl UnexposedAttr {
| "__WATCHOS_UNAVAILABLE"
| "APPKIT_API_UNAVAILABLE_BEGIN_MACCATALYST"
| "MP_INIT_UNAVAILABLE"
| "CF_AUTOMATED_REFCOUNT_UNAVAILABLE"
| "NS_AUTOMATED_REFCOUNT_UNAVAILABLE"
| "NS_AUTOMATED_REFCOUNT_WEAK_UNAVAILABLE"
| "NS_UNAVAILABLE"
Expand All @@ -140,6 +147,7 @@ impl UnexposedAttr {
s if s.starts_with("FILEPROVIDER_API_AVAILABILITY_") => None,
// Might be interesting in the future
"CF_SWIFT_NAME"
| "CF_SWIFT_UNAVAILABLE_FROM_ASYNC"
| "NS_HEADER_AUDIT_BEGIN"
| "NS_REFINED_FOR_SWIFT_ASYNC"
| "NS_SWIFT_ASYNC_NAME"
Expand All @@ -152,7 +160,8 @@ impl UnexposedAttr {
let _ = get_arguments();
None
}
"CF_REFINED_FOR_SWIFT"
"CF_IMPLICIT_BRIDGING_ENABLED"
| "CF_REFINED_FOR_SWIFT"
| "NS_REFINED_FOR_SWIFT"
| "NS_SWIFT_DISABLE_ASYNC"
| "NS_SWIFT_NONISOLATED"
Expand Down
71 changes: 52 additions & 19 deletions crates/header-translator/translation-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
###

[library.Accessibility]
imports = ["Foundation"]
imports = ["CoreFoundation", "Foundation"]
macos = "11.0"
maccatalyst = "14.0"
ios = "14.0"
Expand All @@ -26,7 +26,7 @@ ios = "6.0"
tvos = "9.0"

[library.AppKit]
imports = ["CoreData", "Foundation"]
imports = ["CoreData", "CoreFoundation", "Foundation"]
extra-features = [
# Temporary, since some structs and statics use these
"AppKit_NSApplication",
Expand All @@ -45,7 +45,7 @@ macos = "10.0"
maccatalyst = "13.0"

[library.AuthenticationServices]
imports = ["AppKit", "Foundation"]
imports = ["AppKit", "CoreFoundation", "Foundation"]
# Temporary, since some structs and statics use these
extra-features = ["Foundation_NSURL"]
macos = "10.15"
Expand All @@ -61,7 +61,7 @@ maccatalyst = "13.4"
ios = "13.4"

[library.Automator]
imports = ["AppKit", "Foundation", "OSAKit"]
imports = ["AppKit", "CoreFoundation", "Foundation", "OSAKit"]
macos = "10.4"
maccatalyst = "14.0"

Expand All @@ -78,7 +78,7 @@ ios = "13.0"
tvos = "13.0"

[library.BusinessChat]
imports = ["AppKit", "Foundation"]
imports = ["AppKit", "CoreFoundation", "Foundation"]
macos = "10.14"
maccatalyst = "13.0" # Unsure
ios = "11.0" # Unsure
Expand Down Expand Up @@ -124,6 +124,15 @@ ios = "3.0"
tvos = "9.0"
watchos = "2.0"

[library.CoreFoundation]
imports = []
extra-features= ["block"]
macos = "10.0"
maccatalyst = "13.0"
ios = "2.0"
tvos = "9.0"
watchos = "2.0"

[library.CoreLocation]
imports = ["Contacts", "Foundation"]
extra-features = [
Expand Down Expand Up @@ -183,7 +192,7 @@ ios = "3.0"
tvos = "10.0"

[library.FileProvider]
imports = ["AppKit", "Foundation", "UniformTypeIdentifiers"]
imports = ["AppKit", "CoreFoundation", "Foundation", "UniformTypeIdentifiers"]
macos = "10.15"
ios = "11.0"

Expand All @@ -194,7 +203,7 @@ maccatalyst = "15.0"
ios = "11.0"

[library.Foundation]
imports = []
imports = ["CoreFoundation"]
extra-features = [
"objective-c",
"block",
Expand Down Expand Up @@ -236,7 +245,7 @@ ios = "7.0"
tvos = "9.0"

[library.GameKit]
imports = ["AppKit", "Foundation"]
imports = ["AppKit", "CoreFoundation", "Foundation"]
extra-features = [
"AppKit_NSViewController",
]
Expand All @@ -260,7 +269,7 @@ maccatalyst = "13.0"
ios = "11.0"

[library.InputMethodKit]
imports = ["AppKit", "Foundation"]
imports = ["AppKit", "CoreFoundation", "Foundation"]
macos = "10.5"
maccatalyst = "13.0"

Expand All @@ -272,7 +281,7 @@ ios = "8.0"
watchos = "9.0"

[library.LocalAuthenticationEmbeddedUI]
imports = ["AppKit", "Foundation", "LocalAuthentication"]
imports = ["AppKit", "CoreFoundation", "Foundation", "LocalAuthentication"]
extra-features = [
"AppKit_NSWindow",
]
Expand All @@ -281,7 +290,7 @@ maccatalyst = "16.0"
ios = "16.0"

[library.LinkPresentation]
imports = ["AppKit", "Foundation"]
imports = ["AppKit", "CoreFoundation", "Foundation"]
macos = "10.15"
maccatalyst = "13.0"
ios = "13.0"
Expand All @@ -292,7 +301,7 @@ imports = ["AppKit", "Foundation"]
macos = "12.0"

[library.MapKit]
imports = ["AppKit", "Contacts", "CoreLocation", "Foundation"]
imports = ["AppKit", "Contacts", "CoreFoundation", "CoreLocation", "Foundation"]
extra-features = [
"MapKit_MKDirectionsResponse",
"MapKit_MKETAResponse",
Expand All @@ -306,7 +315,7 @@ tvos = "9.2"
watchos = "2.0"

[library.MediaPlayer]
imports = ["AppKit", "Foundation"]
imports = ["AppKit", "CoreFoundation", "Foundation"]
macos = "10.12.1"
maccatalyst = "13.0"
ios = "2.0"
Expand All @@ -327,7 +336,7 @@ maccatalyst = "16.0"
ios = "16.0"

[library.MetalKit]
imports = ["AppKit", "Foundation", "Metal"]
imports = ["AppKit", "CoreFoundation", "Foundation", "Metal"]
# Temporary, since some structs and statics use these
extra-features = [
"Metal_MTLRenderPipelineReflection",
Expand All @@ -346,20 +355,20 @@ ios = "13.0"

[library.Photos]
name = "PhotoKit"
imports = ["AppKit", "CoreLocation", "Foundation"]
imports = ["AppKit", "CoreFoundation", "CoreLocation", "Foundation"]
macos = "10.11"
maccatalyst = "13.0"
ios = "8.0"
tvos = "10.0"
watchos = "9.0"

[library.OSAKit]
imports = ["AppKit", "Foundation"]
imports = ["AppKit", "CoreFoundation", "Foundation"]
macos = "10.4"

[library.QuartzCore]
name = "CoreAnimation"
imports = ["Foundation"]
imports = ["CoreFoundation", "Foundation"]
macos = "10.3"
maccatalyst = "13.0"
ios = "2.0"
Expand All @@ -380,7 +389,7 @@ maccatalyst = "13.0"
ios = "10.0"

[library.StoreKit]
imports = ["AppKit", "Foundation"]
imports = ["AppKit", "CoreFoundation", "Foundation"]
macos = "10.7"
maccatalyst = "13.0"
ios = "3.0"
Expand All @@ -407,7 +416,7 @@ tvos = "10.0"
watchos = "3.0"

[library.WebKit]
imports = ["AppKit", "Foundation"]
imports = ["AppKit", "CoreFoundation", "Foundation"]
extra-features = ["Foundation_NSAttributedString"]
macos = "10.2"
maccatalyst = "13.0"
Expand Down Expand Up @@ -1567,3 +1576,27 @@ skipped-protocols = ["NSCopying", "NSMutableCopying"]
skipped-protocols = ["NSCopying", "NSMutableCopying"]
[class.NSPurgeableData]
skipped-protocols = ["NSCopying", "NSMutableCopying"]

# Uses variadics
[fn.CFStringCreateWithFormatAndArguments]
skipped = true
[fn.CFStringCreateStringWithValidatedFormatAndArguments]
skipped = true
[fn.CFStringAppendFormatAndArguments]
skipped = true

# Name clash with containing module
[enum.__CFByteOrder]
skipped = true

# Needs dispatch_queue_t
[fn.CFMessagePortSetDispatchQueue]
skipped = true
[fn.CFReadStreamSetDispatchQueue]
skipped = true
[fn.CFWriteStreamSetDispatchQueue]
skipped = true
[fn.CFReadStreamCopyDispatchQueue]
skipped = true
[fn.CFWriteStreamCopyDispatchQueue]
skipped = true
Loading
Loading