First-party dependencies are internal libraries you develop as part of your project:
App/BUCK (lines 23-37)
# This is a list of all of our first-party libraries that are depended upon# (directly or transitively) by this application.first_party_library_dependencies = [ "//Libraries/ASwiftModule:ASwiftModule", "//Libraries/Cpp1:Cpp1", "//Libraries/Objc1:Objc1", "//Libraries/ObjcAndSwift:ObjcAndSwift", "//Libraries/SecondSwiftModule:SecondSwiftModule", "//Libraries/SwiftAndObjc:SwiftAndObjc", "//Libraries/SwiftReliesOnCXX:SwiftReliesOnCXX", "//Libraries/SwiftWithAssets:SwiftWithAssets", "//Libraries/SwiftWithMLModel:SwiftWithMLModel", "//Libraries/SwiftWithPrecompiledDependency:SwiftWithPrecompiledDependency", "//Libraries/YetAnotherSwiftModule:YetAnotherSwiftModule",]
Every first-party library has an associated test target. This list is used to determine what test targets to run in CI.
prebuilt_frameworks = [ "//PrebuiltFrameworks:AFNetworking", # Hack to enable project generation to work for the Carthage BUCK file # which otherwise only has `prebuilt_apple_framework`s. "//PrebuiltFrameworks:PrebuiltFrameworksProjectGeneratorHack",]
App/BUCK (lines 46-49)
prebuilt_dynamic_frameworks = [ # TODO: Comment out CardinalMobile for now until it supports M1 mac: # https://github.com/braintree/braintree_ios/issues/564 # "//Pods:CardinalMobile", # Prebuilt dylib]
Build scripts must be added as dependencies to ensure proper execution order:
App/BUCK (lines 51-56)
# Build Phase scripts need to be added as dependencies.# These only get executed when building with Xcode, not Buck.build_phase_scripts = [ ":Hello_World", ":Bye_World",]
//App:ExampleApp//App:ExampleAppBinary//App:ExampleAppLibrary//App:ExampleAppAssets//Libraries/ASwiftModule:ASwiftModule//Libraries/SwiftAndObjc:SwiftAndObjc//Pods:CryptoSwift//Pods:PromiseKit//App/Resources:ExampleAppStringResources//App/Resources:StoryboardResources# ... and more
Buck automatically resolves transitive dependencies. When a target depends on a library, it also gets access to that library’s dependencies.
Example
# Libraries/SwiftAndObjc depends on Objc1first_party_library( name = "SwiftAndObjc", has_objective_c = True,)# ExampleAppLibrary depends on SwiftAndObjc# It automatically gets Objc1 as a transitive dependencyapple_library( name = "ExampleAppLibrary", deps = [ "//Libraries/SwiftAndObjc:SwiftAndObjc", ],)
Buck builds dependencies in the correct order automatically, so you never need to worry about build order.
Makes dependencies easier to understand and maintain.
Document Dependency Requirements
# This library requires AFNetworking for networking# and CryptoSwift for encryptiondeps = [ "//PrebuiltFrameworks:AFNetworking", "//Pods:CryptoSwift",]
Helps other developers understand why dependencies exist.
BuckSample uses a special test target that bundles all tests into one:
App/BUCK (lines 128-133)
# This test bundles all unit test libraries into a single test target.# Test targets can be slow to create in CI; creating only one can save significant time.apple_test_all( name = "ExampleAppCITests", libraries = first_party_library_dependencies, additional_tests = app_tests, prebuilt_frameworks = prebuilt_frameworks + prebuilt_dynamic_frameworks,)
This optimization reduces CI build time by avoiding the overhead of creating multiple test targets.