Skip to content

Objective-C Headers cause dependency loop #2846

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

Closed
schroffl opened this issue Jul 7, 2019 · 3 comments
Closed

Objective-C Headers cause dependency loop #2846

schroffl opened this issue Jul 7, 2019 · 3 comments
Milestone

Comments

@schroffl
Copy link
Contributor

schroffl commented Jul 7, 2019

When importing objc/runtime.h and/or objc/message.h the compiler detects a dependency loop.

const objc = @cImport({
    @cInclude("objc/runtime.h");
    @cInclude("objc/message.h");
});

pub fn main() void {
    const value: objc.id = undefined;
}

The problem is caused by these definitions:

pub const Class = [*c]struct_objc_class;
pub const struct_objc_class = extern struct {
    isa: Class,
    super_class: Class,
    name: [*c]const u8,
    version: c_long,
    info: c_long,
    instance_size: c_long,
    ivars: [*c]struct_objc_ivar_list,
    methodLists: [*c]([*c]struct_objc_method_list),
    cache: [*c]struct_objc_cache,
    protocols: [*c]struct_objc_protocol_list,
};

which can be fixed by using @This() to reference the struct itself:

pub const struct_objc_class = extern struct {
    isa: [*c]@This(),
    super_class: [*c]@This(),
    // [...]
};

Another offender is this definition:

pub const struct_objc_object = extern struct {
    isa: Class,
};
pub const id = [*c]struct_objc_object;
pub const IMP = ?extern fn (id, SEL, ...) id;

A Class has a method list with IMPs, which causes the dependency loop.

Here's a hacky fix for that, but I would prefer not to loose type safety. Is there a better workaround?

pub const struct_objc_object = extern struct {
    isa: *c_void,
};

Edit: I am running macOS 10.14

@andrewrk andrewrk added this to the 0.5.0 milestone Jul 8, 2019
@andrewrk
Copy link
Member

andrewrk commented Jul 8, 2019

This sounds like it will be fixed by #2174 which is still planned for this release cycle.

@schroffl
Copy link
Contributor Author

schroffl commented Jul 9, 2019

Alright, does the *c_void fix have an consequences other than loosing type safety? Is the information relevant for linking et al.?

@andrewrk
Copy link
Member

I believe this was fixed by #2174. Please let me know if it is not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants