-
Notifications
You must be signed in to change notification settings - Fork 229
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
Adds Swift Package Manager Support #150
Conversation
* Isolates all the C & Non-C code * Adds a swift package manifest with targets for FlexLayout, FlexLayoutYoga, and FlexLayoutYogaKit * Moves the public headers to the [target]/include/[target] folder per Apple's documentation * Updates YogaKit -> Yoga includes to use `<yoga/*.h>` syntax. Unfortunately, this breaks the non-package build
* Fixes much of the import/include issues * There's an enum translation issue. When in the context of a package, the enums declared in YGEnums have to have their values referred to like "YGFlexDirectionColumn", but when not in the context of a package we have to do "YGFlexDirection.column". I'm not sure how to make this consistent.
Since NS_ENUM types are not being translated to Swift enums while in the SPM context, extensions were added to provide equivalent translations. Hopefully, there's a build setting that can be tweaked so we can get rid of these. This fixes the non-SPM build and switches back to the less verbose dot syntax when referring to these enums.
That's present by default and `.define(xxx)` settings don't carry through to consumers of packages
Consider updating Installation section in README.md |
For some reason FlexLayout is failing to build when I install it on app target using SPM. I am able to build the package alone. It seems that I have tried to fix it (link to branch) by explicitly defining
|
There appears to be a bug in Xcode regarding the SWIFT_PACKAGE macro. In some cases, the macro is not defined, leading to compilation failures. This defines a `FLEXLAYOUT_SWIFT_PACKAGE` setting that is used in place of `SWIFT_PACKAGE`. While this doesn't solve the problem, it does allow one to add `FLEXLAYOUT_SWIFT_PACKAGE=1` to their app target's `GCC_PREPROCESSOR_DEFINITIONS` build setting to workaround the problem.
@pju-trifork Yeah, what a pain. I think this is a bug in Xcode or SwiftPM or both. See my latest commit which makes a simple workaround possible, and probably safe. |
@pju-trifork Added a new target to the |
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.
Thanks for these changes. Please add a "Swift Package Manager (SPM)" in the section "Installation" of the Readme (https://github.com/layoutBox/FlexLayout#installation)
@lucdion I added it. Since SPM requires some type of qualification of a specific version/tag/branch/etc, we may need to tweak the README again if there's another version bump before this gets merged. |
* Includes requirement of adding the FLEXLAYOUT_SWIFT_PACKAGE definition
why not merge ? |
Resolves #144
FlexLayoutSample
project calledFlexLayoutExampleSPM
that imports FlexLayout via the Swift package.NS_ENUM typedefs
don't seem to be translated to Swift enums when imported via a module. Because of that, static values were added to the various NS_ENUM types as extensions when in the context of a Swift package. Perhaps there's a build setting to eliminate the need for that?CAVEAT
To build a target that imports FlexLayout via the new swift package, you'll need to add
FLEXLAYOUT_SWIFT_PACKAGE=1
to the target'sGCC_PREPROCESSOR_DEFINITIONS
build setting. The newFlexLayoutExampleSPM
target does this, so look there for an example.The reason is that there appears to be an Xcode/SwiftPM/Both bug regarding the
SWIFT_PACKAGE
macro. As a result, when building an application target that includes FlexLayout via the new Swift package, theSWIFT_PACKAGE
macro is undefined when compiling theFlexLayoutYogaKit
target, which causes the build to fail. To work around this, I defined a new macro in the swift package calledFLEXLAYOUT_SWIFT_PACKAGE
and replaced all usages ofSWIFT_PACKAGE
withFLEXLAYOUT_SWIFT_PACKAGE
. This way, you can safely define the macro in your own targets and allow the build to succeed.