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

Initial support for CoreGraphics / Dispatch #632

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ target/

tests-ios/*
!tests-ios/prelude.rs
.idea/
16 changes: 16 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/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fn uses_system_config(library_name: &str) -> bool {
"System" | "bitflags" | "block2" | "libc" | "objc2" => true,
// Temporary
"CoreFoundation" => true,
"CoreGraphics" => true,
_ => false,
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/header-translator/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl Location {
}
}
} else {
error!(location = ?self, "failed getting crate name");
error!(location = ?self, ?library, "failed getting crate name");
LocationLibrary::System
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/header-translator/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl MethodModifiers {
UnexposedAttr::UIActor => {
this.mainthreadonly = true;
}
attr => error!(?attr, "unknown attribute"),
attr => error!(?attr, "unknown attribute on method modifiers"),
}
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ impl MethodModifiers {
EntityKind::AnnotateAttr => {
// TODO: `UI_APPEARANCE_SELECTOR`
}
_ => error!("unknown"),
kind => error!(?kind, "unknown entity kind"),
});

this
Expand Down Expand Up @@ -428,13 +428,13 @@ impl Method {
UnexposedAttr::Sendable => sendable = Some(true),
UnexposedAttr::NonSendable => sendable = Some(false),
UnexposedAttr::NoEscape => no_escape = true,
attr => error!(?attr, "unknown attribute"),
attr => error!(?attr, "unknown attribute on method"),
}
}
}
// For some reason we recurse into array types
EntityKind::IntegerLiteral => {}
_ => error!("unknown"),
kind => error!(?kind, "unknown entity kind"),
});

let ty = entity.get_type().expect("argument type");
Expand Down
2 changes: 1 addition & 1 deletion crates/header-translator/src/rust_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl Ty {
// Ignored for now; these are usually also emitted on the method/property,
// which is where they will be useful in any case.
}
Some(attr) => error!(?attr, "unknown attribute"),
Some(attr) => error!(?attr, "unknown attribute b"),
None => {}
}

Expand Down
72 changes: 62 additions & 10 deletions crates/header-translator/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ pub enum Stmt {
result_type: Ty,
// Some -> inline function.
body: Option<()>,
must_use: bool,
pure: bool,
safe: bool,
},
/// typedef Type TypedefName;
Expand All @@ -577,7 +579,15 @@ fn parse_fn_param_children(entity: &Entity<'_>, context: &Context<'_>) {
immediate_children(entity, |entity, _span| match entity.get_kind() {
EntityKind::UnexposedAttr => {
if let Some(attr) = UnexposedAttr::parse(&entity, context) {
error!(?attr, "unknown attribute");
match attr {
UnexposedAttr::NoEscape => {
// TODO: Pass this up
},
_ => {
error!(?attr, "unknown attribute f");
}
}

}
}
EntityKind::ObjCClassRef
Expand All @@ -587,7 +597,10 @@ fn parse_fn_param_children(entity: &Entity<'_>, context: &Context<'_>) {
EntityKind::NSConsumed => {
error!("found NSConsumed, which requires manual handling");
}
kind => error!(?kind, "unknown"),
EntityKind::IntegerLiteral => {
// This is an array, probably fine...
}
kind => error!(?kind, ?entity, "unknown abc"),
});
}

Expand Down Expand Up @@ -1075,7 +1088,7 @@ impl Stmt {
| EntityKind::TypeRef
| EntityKind::ParmDecl
| EntityKind::EnumDecl => {}
_ => error!("unknown"),
kind => error!(?kind, "unknown entity kind"),
});

if context
Expand Down Expand Up @@ -1141,7 +1154,7 @@ impl Stmt {
match attr {
UnexposedAttr::Sendable => sendable = Some(true),
UnexposedAttr::NonSendable => sendable = Some(false),
attr => error!(?attr, "unknown attribute"),
attr => error!(?attr, "unknown attribute e"),
}
}
}
Expand All @@ -1163,7 +1176,7 @@ impl Stmt {
boxable = true;
}
EntityKind::UnionDecl => error!("can't handle unions in structs yet"),
_ => error!("unknown"),
kind => error!(?kind, "unknown entity kind"),
});

vec![Self::StructDecl {
Expand Down Expand Up @@ -1235,7 +1248,15 @@ 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 attr {
UnexposedAttr::Deprecated => {
// TODO: Do we pass through the deprecated attribute here?
},
_ => {
error!(?attr, "unknown attribute d");
}
}

}
}
EntityKind::VisibilityAttr => {}
Expand Down Expand Up @@ -1279,7 +1300,7 @@ impl Stmt {
EntityKind::VisibilityAttr => {
// Already exposed as entity.get_visibility()
}
_ => error!("unknown"),
kind => error!(?kind, "unknown entity kind"),
});

if id.name.is_none() {
Expand Down Expand Up @@ -1335,7 +1356,7 @@ 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");
error!(?attr, "unknown attribute c");
}
}
EntityKind::VisibilityAttr => {}
Expand Down Expand Up @@ -1381,6 +1402,8 @@ impl Stmt {
let result_type = entity.get_result_type().expect("function result type");
let result_type = Ty::parse_function_return(result_type, context);
let mut arguments = Vec::new();
let mut must_use = false;
let mut is_pure = false;

if entity.is_static_method() {
warn!("unexpected static method");
Expand All @@ -1389,7 +1412,13 @@ 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 attr {
UnexposedAttr::NotOnEmbedded => {
// TODO: We might have to make availability mut here...
},
_ => error!(?attr, "unknown attribute a")
}

}
}
EntityKind::ObjCClassRef
Expand All @@ -1406,7 +1435,13 @@ impl Stmt {
EntityKind::VisibilityAttr => {
// CG_EXTERN or UIKIT_EXTERN
}
_ => error!("unknown"),
EntityKind::WarnUnusedResultAttr => {
must_use = true;
}
EntityKind::PureAttr => {
is_pure = true;
}
kind => error!(?kind, "unknown entity kind"),
});

let body = if entity.is_inline_function() {
Expand All @@ -1420,6 +1455,8 @@ impl Stmt {
availability,
arguments,
result_type,
must_use,
pure: is_pure,
body,
safe: !data.unsafe_,
}]
Expand Down Expand Up @@ -2347,10 +2384,15 @@ impl Stmt {
availability: _,
arguments,
result_type,
must_use,
pure: _,
body: Some(_),
safe: _,
} => {
write!(f, "// TODO: ")?;
if *must_use {
writeln!(f, "#[must_use]")?;
}
write!(f, "pub fn {}(", id.name)?;
for (param, arg_ty) in arguments {
let param = handle_reserved(&crate::to_snake_case(param));
Expand All @@ -2363,9 +2405,14 @@ impl Stmt {
availability,
arguments,
result_type,
must_use,
pure: _,
body: None,
safe: false,
} => {
if *must_use {
writeln!(f, "#[must_use]")?;
}
writeln!(f, "extern \"C\" {{")?;

write!(f, " {}", self.cfg_gate_ln(config))?;
Expand All @@ -2385,12 +2432,17 @@ impl Stmt {
availability,
arguments,
result_type,
must_use,
pure: _,
body: None,
safe: true,
} => {
write!(f, "{}", self.cfg_gate_ln(config))?;
write!(f, "{availability}")?;
writeln!(f, "#[inline]")?;
if *must_use {
writeln!(f, "#[must_use]")?;
}
write!(f, "pub extern \"C\" fn {}(", id.name)?;
for (param, arg_ty) in arguments {
let param = handle_reserved(&crate::to_snake_case(param));
Expand Down
15 changes: 15 additions & 0 deletions crates/header-translator/src/unexposed_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use clang::token::{Token, TokenKind};
use clang::{Entity, EntityKind};

use crate::context::Context;
use crate::unexposed_attr::UnexposedAttr::{Deprecated, NoEscape, NotOnEmbedded};

/// Parts of `EntityKind::UnexposedAttr` that we can easily parse.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
Expand All @@ -29,6 +30,8 @@ pub enum UnexposedAttr {
NonIsolated,

NoEscape,
NotOnEmbedded,
Deprecated
}

impl UnexposedAttr {
Expand Down Expand Up @@ -177,6 +180,18 @@ impl UnexposedAttr {
let _ = get_arguments();
None
}
"CF_IMPLICIT_BRIDGING_ENABLED" => {
None
},
"CG_UNAVAILABLE_EMBEDDED" => {
Some(NotOnEmbedded)
},
"__CG_DEPRECATED_ENUMERATOR" => {
Some(Deprecated)
},
"CF_NOESCAPE" => {
Some(NoEscape)
}
// For some reason we don't need to extract the arguments for
// these, perhaps because they simply delegate to other macros.
"AS_API_AVAILABLE" | "AS_HEADER_AUDIT_BEGIN" => None,
Expand Down
2 changes: 2 additions & 0 deletions crates/objc2/src/topics/about_generated/list_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
| `ContactsUI` | [![`objc2-contacts-ui`](https://badgen.net/crates/v/objc2-contacts-ui)](https://crates.io/crates/objc2-contacts-ui) | [![docs.rs](https://docs.rs/objc2-contacts-ui/badge.svg)](https://docs.rs/objc2-contacts-ui/) |
| `CoreBluetooth` | [![`objc2-core-bluetooth`](https://badgen.net/crates/v/objc2-core-bluetooth)](https://crates.io/crates/objc2-core-bluetooth) | [![docs.rs](https://docs.rs/objc2-core-bluetooth/badge.svg)](https://docs.rs/objc2-core-bluetooth/) |
| `CoreData` | [![`objc2-core-data`](https://badgen.net/crates/v/objc2-core-data)](https://crates.io/crates/objc2-core-data) | [![docs.rs](https://docs.rs/objc2-core-data/badge.svg)](https://docs.rs/objc2-core-data/) |
| `CoreGraphics` | [![`objc2-core-graphics`](https://badgen.net/crates/v/objc2-core-graphics)](https://crates.io/crates/objc2-core-graphics) | [![docs.rs](https://docs.rs/objc2-core-graphics/badge.svg)](https://docs.rs/objc2-core-graphics/) |
| `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/) |
| `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/) |
| `CoreWLAN` | [![`objc2-core-wlan`](https://badgen.net/crates/v/objc2-core-wlan)](https://crates.io/crates/objc2-core-wlan) | [![docs.rs](https://docs.rs/objc2-core-wlan/badge.svg)](https://docs.rs/objc2-core-wlan/) |
| `DataDetection` | [![`objc2-data-detection`](https://badgen.net/crates/v/objc2-data-detection)](https://crates.io/crates/objc2-data-detection) | [![docs.rs](https://docs.rs/objc2-data-detection/badge.svg)](https://docs.rs/objc2-data-detection/) |
| `DeviceCheck` | [![`objc2-device-check`](https://badgen.net/crates/v/objc2-device-check)](https://crates.io/crates/objc2-device-check) | [![docs.rs](https://docs.rs/objc2-device-check/badge.svg)](https://docs.rs/objc2-device-check/) |
| `Dispatch` | [![`objc2-dispatch`](https://badgen.net/crates/v/objc2-dispatch)](https://crates.io/crates/objc2-dispatch) | [![docs.rs](https://docs.rs/objc2-dispatch/badge.svg)](https://docs.rs/objc2-dispatch/) |
| `EventKit` | [![`objc2-event-kit`](https://badgen.net/crates/v/objc2-event-kit)](https://crates.io/crates/objc2-event-kit) | [![docs.rs](https://docs.rs/objc2-event-kit/badge.svg)](https://docs.rs/objc2-event-kit/) |
| `ExceptionHandling` | [![`objc2-exception-handling`](https://badgen.net/crates/v/objc2-exception-handling)](https://crates.io/crates/objc2-exception-handling) | [![docs.rs](https://docs.rs/objc2-exception-handling/badge.svg)](https://docs.rs/objc2-exception-handling/) |
| `ExtensionKit` | [![`objc2-extension-kit`](https://badgen.net/crates/v/objc2-extension-kit)](https://crates.io/crates/objc2-extension-kit) | [![docs.rs](https://docs.rs/objc2-extension-kit/badge.svg)](https://docs.rs/objc2-extension-kit/) |
Expand Down
Loading
Loading