typhoon icon indicating copy to clipboard operation
typhoon copied to clipboard

Add build target for dynamic framework to support

Open mowens opened this issue 12 years ago • 21 comments

With the introduction of swift, and cocoapods lack of swift support, it would be nice (and likely needed once cocoapods does support swift - e.g dynamic frameworks) to support building typhoon as a dynamic framework. This is necessary for supported typhoon DI in swift libraries that themselves build dynamic frameworks and link into the main app project.

For example, say I have the following swift projects that build dynamic frameworks:

XXFoo-> XXFoo.framework XXBar -> XXBar.framework

These libraries are then linked into my main app project, XXMyApp. In order for XXMyApp to leverage Typhoon DI, cocoapods can be used to create a libPods.a static library with the Typhoon source and a bridging header (XXMyApp-Bridging-header.h) can be created and #import "Tyhoon.h". Now this is al well and good if all of my Typhoon assemblies exist in XXMyApp, however, if I truly want to leverage the power of DI in XXFoo and XXBar I should be able to define my TyphoonAssembly factories in each library and import them for use in XXMyApp. This way each library would be responsible for setting up its own dependencies.

This is currently not possible with the pods approach as you cannot link a static library (e.g. libPods.a) into a dynamic swift framework. You can however link to dynamic frameworks, so if Typhoon was able to build a dynamic framework (e.g. Typhoon.framework) then XXFoo, XXBar and XXMyApp could link against it; XXFoo and XXBar could define their own assemblies and XXMyApp would be able to instantiate them.

Because dynamic frameworks are not yet supported by cocoapods, the approach that several swift-only libraries are taking are git modules, so swift libraries want to dynamic link against Typhoon could:

  1. Create a git submodule
  2. Add Typhoon.xcodeproj to their workspace
  3. Add Typhoon.framework as a target dependencies in the build phases
  4. Add a "Copy Frameworks" build phase and copy Typhoon.framwork to their Frameworks path

mowens avatar Nov 26 '14 18:11 mowens

Hi @mowens

Our build server publishes some artifacts up to www.typhoonframework.org for each successful build, so we'd be able to include this as part of that.

If you'd like to do the build target? I'll do the build server part and put a link on GitHub and www.typhoonframework.org

jasperblues avatar Nov 27 '14 01:11 jasperblues

For the time being, Apple has recommended not linking against pre-built binaries using the swift compiler as it is still young. So I believe the "ideal" integration would be a git submodule and link directly against the build artifact from the Typhoon xcodeproject.

I will start looking into/working on the dynamic framework build target.

mowens avatar Dec 05 '14 19:12 mowens

Thanks @mowens, that is excellent. Have you seen this issue: #286 ?

Its second highest priority, but neither @alexgarbarev or I have been able to look at it yet.

jasperblues avatar Dec 08 '14 05:12 jasperblues

@jasperblues PR: https://github.com/typhoon-framework/Typhoon/pull/290

mowens avatar Dec 09 '14 06:12 mowens

Ready to close?

jasperblues avatar Dec 25 '14 04:12 jasperblues

@mowens how about using Carthage package manager for Swift?

jasperblues avatar Dec 26 '14 05:12 jasperblues

https://github.com/Carthage/Carthage

jasperblues avatar Dec 26 '14 05:12 jasperblues

@jasperblues sorry it took so long to get back to you. I have taken a look at Carthage and I like the concept as it doesn't mock with project settings like Cocoapods does but the project is still pretty young. Currently, I couldn't get Carthage to build Typhoon out-of-the-box. I didn't look too much into the failure case, but seems to be schema related.

A downfall of Carthage is it is (more or less) a wrapper around git and xcodebuild, which means developing local pods would be a pain in the ass (not that it is much better with Cocoapods but it is better).

A beta has been released for Swift and framework support for Cocoapods which I am currently looking into. It doesn't build Typhoon as a framework out-of-the-box either, but with a few teaks i'm sure it can! IMO pods would support should take precedence to Carthage. Thoughts?

mowens avatar Jan 09 '15 19:01 mowens

@jasperblues Typhoon does work with Cocoapods 0.3.6 beta out of the box! For swift libraries/apps that need to link against Typhoon they must specify in their pod file that it uses frameworks

# platform *must* be atleast 8.0
platform :ios, '8.0'

# flag makes all dependencies build as frameworks
use_frameworks!

# framework dependencies
pod 'Typhoon', '2.3.3'

mowens avatar Jan 09 '15 21:01 mowens

great work@mowens. lets stick with cocoa pods for now. We may need to support carthage when it becomes popular

jasperblues avatar Jan 12 '15 04:01 jasperblues

Agreed

mowens avatar Jan 12 '15 14:01 mowens

Hey guys, we're currently using carthage and we would like to include Typhoon in it. Is it a good time to reconsider adding support for Carthage ?

According to the Carthage docs, it should just be a matter of marking your schemes as shared.

StyleOffDev avatar Apr 17 '15 17:04 StyleOffDev

All schemes were shared except for the Typhoon Framework scheme. . . i shared it and pushed to master. Next step?

jasperblues avatar Apr 18 '15 00:04 jasperblues

Hmm, I'm not seeing the push to master. I just tested it locally, and marking the Typhoon framework scheme as shared was sufficient to allow Typhoon to be compatible with Carthage. So once that commit is available in master, it doesn't look like any other changes need to be made, fortunately.

jarod2d avatar Apr 18 '15 04:04 jarod2d

Oops. . . sorry! I did that early this morning in between a bunch of other tasks and didn't pay attention to console output. Its pushed now.

jasperblues avatar Apr 18 '15 05:04 jasperblues

Awesome, thanks for the quick response!

One other thing I just realized is that Carthage tries to grab the latest version of a dependency based on tags, so if you include Typhoon using github "appsquickly/Typhoon", the 3.0.2 tag will be used, which doesn't include the shared scheme. It can still be used by explicitly depending on the master branch though, as in github "appsquickly/Typhoon" "master", so no need to rush bumping the version.

Thanks again!

jarod2d avatar Apr 18 '15 05:04 jarod2d

OK, just pushed 3.0.3 tag, and also to CocoaPods mater repo.

jasperblues avatar Apr 18 '15 05:04 jasperblues

Oh, one more thing to note: While pushing the podspec just now, linting failed as there was a function declared as public in TyphoonFactoryAutoInjectionPostProcessor that was not used publicly. . I fixed that then deleted and recreated the 3.0.3 tag. . . just mentioning in the unlikely event this confuses Carthage.

jasperblues avatar Apr 18 '15 05:04 jasperblues

Cool -- I believe Carthage will just pull down whatever the tag is currently pointing to when retrieving dependencies, so it should be okay. Thanks!

jarod2d avatar Apr 18 '15 05:04 jarod2d

@jarod2d Did it all work? I'm just adding the 'Carthage compatible" badge in the readme.

jasperblues avatar Apr 30 '15 10:04 jasperblues