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 NS_ENUM support, for Swift #701
base: master
Are you sure you want to change the base?
Conversation
This is unnecessary given NS_ENUM caters to objc
@emilio I think all the issues are resolved, thanks for the reviews, please have another look when you have a chance :) |
src/bindgen/ir/enumeration.rs
Outdated
// technically you're not going to get #[repr(double)] because that's not valid rust, | ||
// but let's check anyway | ||
.map_or(false, |prim| prim.can_be_enum_fixed_type()); | ||
.is_some(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is not what you intended. This is effectively self.repr.ty.is_some()
so it should be simplified to that probably.
src/bindgen/config.rs
Outdated
@@ -669,12 +669,6 @@ impl EnumConfig { | |||
} | |||
self.private_default_tagged_enum_constructor | |||
} | |||
pub(crate) fn swift_enum_macro(&self, annotations: &AnnotationSet) -> Option<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, I wasn't particularly against the annotation (though it probably isn't terribly useful and we can add it back if ever needed). I just thought that storing the "resolved" value shouldn't be necessary, since we store the annotations already.
See NS_ENUM docs. See this excerpt from docs.md for motivation:
Config is like so:
Output is like so:
It clobbers
cpp_compat
's effect on enums, which is normally to add a C++11 fixed type in an ifdef (enum Name: uint32_t { ... }
). This is because CF_ENUM/NS_ENUM will already do that; the difference is it works in Objective-C as well, and maybe they do some other annotation magic to get Swift to recognise enums.Edit: I'll fix clippy later and also there's a failing test (test_body) but I think that was present before I made the changes so I'll check that too.