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

Adds Swift Package Manager Support #150

Merged
merged 17 commits into from
Apr 11, 2020
Merged

Conversation

gcox
Copy link
Contributor

@gcox gcox commented Nov 22, 2019

Resolves #144

  • 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
  • Adds a new target to the FlexLayoutSample project called FlexLayoutExampleSPM 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's GCC_PREPROCESSOR_DEFINITIONS build setting. The new FlexLayoutExampleSPM 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, the SWIFT_PACKAGE macro is undefined when compiling the FlexLayoutYogaKit target, which causes the build to fail. To work around this, I defined a new macro in the swift package called FLEXLAYOUT_SWIFT_PACKAGE and replaced all usages of SWIFT_PACKAGE with FLEXLAYOUT_SWIFT_PACKAGE. This way, you can safely define the macro in your own targets and allow the build to succeed.

gcox added 5 commits November 22, 2019 16:47
* 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
@gcox gcox marked this pull request as ready for review November 23, 2019 12:21
@gcox gcox changed the title Start of support for SPM (*) - NEED HELP Add Swift Package Manager Support Nov 23, 2019
@gcox gcox changed the title Add Swift Package Manager Support Adds Swift Package Manager Support Nov 23, 2019
@pju-dawn
Copy link

Consider updating Installation section in README.md

@pju-dawn
Copy link

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 SWIFT_PACKAGE macro is either undefined or ignored when FlexLayoutYogaKit is being built.

I have tried to fix it (link to branch) by explicitly defining SWIFT_PACKAGE in Package.swift, unfortunately without any luck.

<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "/Users/povilasjuzeliunas/Library/Developer/Xcode/DerivedData/AppName-chgnrgvfpwnbhsfhdndefkgdwdpc/SourcePackages/checkouts/FlexLayout/Sources/YogaKit/include/YogaKit/YGLayout+Private.h"
        ^
/Users/povilasjuzeliunas/Library/Developer/Xcode/DerivedData/AppName-chgnrgvfpwnbhsfhdndefkgdwdpc/SourcePackages/checkouts/FlexLayout/Sources/YogaKit/include/YogaKit/YGLayout+Private.h:8:9: note: in file included from /Users/povilasjuzeliunas/Library/Developer/Xcode/DerivedData/AppName-chgnrgvfpwnbhsfhdndefkgdwdpc/SourcePackages/checkouts/FlexLayout/Sources/YogaKit/include/YogaKit/YGLayout+Private.h:8:
#import "YGLayout.h"
        ^
/Users/povilasjuzeliunas/Library/Developer/Xcode/DerivedData/AppName-chgnrgvfpwnbhsfhdndefkgdwdpc/SourcePackages/checkouts/FlexLayout/Sources/YogaKit/include/YogaKit/YGLayout.h:15:9: error: 'YGEnums.h' file not found
#import "YGEnums.h"
        ^
<unknown>:0: error: could not build Objective-C module 'FlexLayoutYogaKit'

Screenshot 2020-02-27 at 10 50 14

gcox added 6 commits February 28, 2020 16:39
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.
@gcox
Copy link
Contributor Author

gcox commented Feb 28, 2020

@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.

@gcox
Copy link
Contributor Author

gcox commented Feb 29, 2020

@pju-trifork Added a new target to the FlexLayoutSample project, FlexLayoutExampleSPM, that imports FlexLayout as a swift package so playing with this is trivial now.

@gcox gcox mentioned this pull request Feb 29, 2020
Copy link
Member

@lucdion lucdion left a 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)

@gcox
Copy link
Contributor Author

gcox commented Mar 1, 2020

@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
@conversun
Copy link

why not merge ?

@lucdion lucdion merged commit e3c1237 into layoutBox:master Apr 11, 2020
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

Successfully merging this pull request may close these issues.

SPM support
4 participants