objc2 icon indicating copy to clipboard operation
objc2 copied to clipboard

Initial support for CoreGraphics / Dispatch

Open not-jan opened this issue 1 year ago • 1 comments

Hey, I've talked about it in https://github.com/madsmtm/objc2/issues/631, so here's my draft PR for adding CoreGraphics and I think I have it most of the way there but now I'm encountering a lot of these errors:

│ ├─ERROR tried to get library config from "__Unknown__"
│ ├─ WARN ItemIdentifier from unknown header, entity=Entity { kind: ObjCProtocolDecl, display_name: Some("OS_dispatch_queue"), location: Some(SourceLocation { file: Some(File { path: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/dispatch/queue.h" }), line: 70, column: 1, offset: 2513 }) }
│ ├─ERROR tried to get library config from "__Unknown__"
│ ├─ WARN ItemIdentifier from unknown header, entity=Entity { kind: ObjCProtocolDecl, display_name: Some("OS_dispatch_object"), location: Some(SourceLocation { file: Some(File { path: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/dispatch/object.h" }), line: 56, column: 37, offset: 1725 }) }
│ ├─ERROR tried to get library config from "__Unknown__"
│ ├─ WARN ItemIdentifier from unknown header, entity=Entity { kind: ObjCProtocolDecl, display_name: Some("OS_dispatch_queue"), location: Some(SourceLocation { file: Some(File { path: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/dispatch/queue.h" }), line: 70, column: 1, offset: 2513 }) }
│ ├─ WARN ItemIdentifier from unknown header, entity=Entity { kind: ObjCProtocolDecl, display_name: Some("OS_dispatch_object"), location: Some(SourceLocation { file: Some(File { path: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/dispatch/object.h" }), line: 56, column: 37, offset: 1725 }) }
│ ├─ERROR tried to get library config from "__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["IOKit", "IOTypes"] }, library="IOKit"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["IOKit", "IOTypes"] }, library="IOKit"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"
│ ├─ERROR failed getting crate name, location=Location { path_components: ["__Unknown__"] }, library="__Unknown__"

I've modified some of the error messages to actually trace down compilation errors and also implemented ObjC's version of #[must_use]. I'm hopeful that you can help me figure out the remaining issues.

not-jan avatar Jun 18 '24 09:06 not-jan

Not sure if this could be of help, but I've encountered these errors before:

The first batch is regarding dispatch:

  • it bases itself on C and exposes a C, C++, Obj-C and Swift API, if I remember correctly;
  • item names are therefore often different between the languages: in C there is for example dispatch_queue_t, but in Obj-C it is NSObject<OS_dispatch_queue>;
  • the header translator sees OS_dispatch_queue and tries to find it in its watched headers, but does not find it since it is actually dispatch_queue_t that is only an alias to dispatch_object_s*, hence the errors.

This is currently "solved" by grafting any framework item that mentions anything of dispatch from its crate using the exclusions possible in the translation-config.toml: maybe try this first? I used a good old grep in the past to find all items that use it by searching for OS_dispatch or something like that in the framework's Headers directory.

Properly having support for dispatch will probably require modifying the translator in order to add the hacks necessary to connect the pipes correctly. It could also be easier to develop and review if it were done separately: much of the existing higher-level framework crates already need dispatch and can therefore serve as a test basis.

The second batch may be because some regular Obj-C types used in CoreGraphics depend on ones from other frameworks? You can also grep for #(include|import) <.*\.h> and then | sort -u in order to determine the dependencies of a framework from its header files. The dependencies need to have a generated objc2 framework crate before the dependent can be generated.

PaulDance avatar Jul 05 '24 18:07 PaulDance

I've added #[must_use] in 84876184a9acb2a3ab4bbf8a6465daabca096d8b based on your work here.

I've also added CoreGraphics in eaf268dc5010e17cfecc26257417bcab0943ab38, and I ended up doing mostly the same fixes as you have in here (?).

So I'm going to close this PR, since the contents are now out of date. Dispatch / objc2-dispatch is still desired (see #77), but I think it makes sense to open a new PR for that (if I don't get to doing it myself first).

Thanks for the input both of you!

madsmtm avatar Dec 12 '24 03:12 madsmtm