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 support for using Yoga from swift on non Darwin platforms. #1690

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

iainsmith
Copy link

@iainsmith iainsmith commented Aug 24, 2024

Specify that enums are closed for correct swift export on non darwin platforms.

Related Yoga Issue


Swift exports plain c enums as constants. On Darwin the yoga macros hit the NS_ENUM case which generates a swift enum, however on linux NS_ENUM is not defined.

See [This post] for a some more background. https://belkadan.com/blog/2021/10/Swift-Regret-Unannotated-C-Enums/

Tested on a couple of CI builds:

Which results in a compiler error for the missing switch cases.

[303/309] Compiling YogaSwift YGNodeView.swift
/home/runner/work/YogaSwift/YogaSwift/Sources/YogaSwift/YGNode.swift:50:56: error: type 'YGDirection' has no member 'LTR'
48 |     width: Float = YGValueUndefined.value, height: Float = YGValueUndefined.value
49 |   ) {
50 |     YGNodeCalculateLayout(self.__node, width, height, .LTR)
   |                                                        `- error: type 'YGDirection' has no member 'LTR'
51 |   }
52 | }

Copy link

vercel bot commented Aug 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
yoga-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 26, 2024 10:40pm

@facebook-github-bot
Copy link
Contributor

Hi @iainsmith!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added CLA Signed Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Aug 24, 2024
Copy link
Contributor

@NickGerleman NickGerleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the build on non-Clang platforms.

@@ -49,7 +49,7 @@
#define YG_ENUM_END(name)
#else
#define YG_ENUM_BEGIN(name) enum name
#define YG_ENUM_END(name) name
#define YG_ENUM_END(name) __attribute__((enum_extensibility(closed))) name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of these are flag enums, which would also need to be declared I think

Copy link
Author

@iainsmith iainsmith Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NickGerleman Are the only bitmask flags YGErrata & YGExperimentalFeature or are there others?

Copy link
Author

@iainsmith iainsmith Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realised that enums.py specifies that only Errata is a bitset enum.

How do you feel about us adding a YG_ENUM_FLAG_DECL macro, and then updating enums.py to check BITSET_ENUMS to decide on which macro to use?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good to me!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NickGerleman , I took a quick stab at this on this branch, but I've run into a compiler error I'm not sure how to approach.

~/Developer/personal/yoga/yoga/../yoga/YGEnums.h:61:5: 
error: enumeration value 'YGErrataClassic' is out of range of flags in enumeration type 'YGErrata' [-Werror,-Wflag-enum]
   61 |     YGErrataClassic = 2147483646,
      |     ^
~/Developer/personal/yoga/yoga/../yoga/YGEnums.h:62:5: 
error: enumeration value 'YGErrataAll' is out of range of flags in enumeration type 'YGErrata' [-Werror,-Wflag-enum]
   62 |     YGErrataAll = 2147483647)

Do you have thoughts on the best way to handle that?

@iainsmith
Copy link
Author

iainsmith commented Aug 26, 2024

This breaks the build on non-Clang platforms.

Makes sense. I'll push a change to wrap this in a clang check.


Should be fixed now. Quickly tested with
cmake -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ && make

note to self. /usr/bin/gcc on mac is a wrapper around clang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants