facebook / buck

A fast build system that encourages the creation of small, reusable modules over a variety of platforms and languages.
https://buck.build
Apache License 2.0
8.56k stars 1.16k forks source link

Swift Playgrounds Support #1852

Open AttilaTheFun opened 6 years ago

AttilaTheFun commented 6 years ago

I think the addition of an apple_playground rule would be a fantastic addition to BUCK. It could facilitate test driven development and rapid prototyping. It would have a syntax similar to apple_library but it would only be used for buck project generation. The xcodeproj generated would be for a cocoa framework that links all the deps plus an empty Swift file to get it to link them. It would also create and embed a playground with all the sources in that xcodeproj which would be able to use all of the Swift or Objective-C dependencies. What do you think? Would it be doable and/or valuable?

This article explains how to link existing frameworks into a Swift playground: https://m.pardel.net/using-3rd-party-frameworks-in-swift-playgrounds-fd415f6dba10

mgrebenets commented 6 years ago

+1.

We've been migrating existing library projects from CocoaPods to Buck. Playgrounds were working with CocoaPods when we added playground to the same workspace as the framework project.

The same wouldn't work with Buck so far. I've tried adding playground using other_xcode_files as well as other_xcode_sources. I've tried to manually add playground to autogenerated Xcode workspace as well. In all cases the error is error: MyPlanground.playground:10:8: error: no such module 'MyLibrary'.

It must be due to the fact that buck creates a static library target, while with cocoapods we've been using dynamic libraries so far.

Another question that is interesting, is how can we use playgrounds together with libraries that have additional resources. While using dynamic frameworks, the resources would be packaged inside .framework bundle and would be available to the app and/or playground as part of that bundle.

When building library as a static library, the resources come as a separate dependency. Which is fine for the apps, the resources will be copied directly to the application bundle and can be accessed there. But what about playgrounds? How would a playground be able to access those resources without some extra support from buck tool?

While static libraries with extra resources and playgrounds is not something that's buck-specific, it would be helpful to have support for playgrounds from buck anyway.