Skip to main content

Target Naming Convention

Buck targets follow a specific naming pattern that identifies their location and name:
//cell/path/to/package:target_name
  • // - Root of the repository
  • cell/path/to/package - Path to the directory containing the BUCK file
  • : - Separator between package path and target name
  • target_name - The name defined in the BUCK file

Listing Targets

You can list all targets in a package using the buck targets command:
buck targets //App:
//App:ExampleApp
//App:ExampleAppBinary
//App:ExampleAppLibrary
//App:ExampleAppAssets
//App:ExampleAppCITests
//App:ExampleWatchApp
//App:ExampleMessageExtension
//App:ExampleWidgetExtension

Target Types in BuckSample

Library Targets

Library targets compile source code into reusable modules:
App/BUCK (lines 58-86)
apple_library(
    name = "ExampleAppLibrary",
    visibility = [
        "//App:",
        "//App/...",
    ],
    configs = library_configs(),
    swift_version = "4.0",
    srcs = [
        "ViewController.swift",
        "AppDelegate.swift",
        "LocalizationHelper.swift",
    ],
    tests = app_tests,
    deps = [
        "//Pods:CryptoSwift",
        "//Pods:PromiseKit",
        ":ExampleAppAssets",
        "//App/Resources:ExampleAppStringResources",
        "//App/Resources:StoryboardResources",
    ]
    + first_party_library_dependencies
    + prebuilt_dynamic_frameworks
    + build_phase_scripts,
)
Library targets can have associated test targets via the tests parameter.

Binary Targets

Binary targets create executable code:
App/BUCK (lines 88-104)
buck_local_binary(
    name = "ExampleAppBinary",
    visibility = [
        "//App:",
        "//App/...",
    ],
    configs = app_binary_configs("ExampleApp"),
    swift_version = "4.0",
    srcs = [
        "BuckSupportFiles/Dummy.swift",
    ],
    native_xcode_deps = [":ExampleAppLibrary"],
    buck_local_deps=[
        "//BuckLocal:BuckLocal",
        "//BuckLocal:RemapDBGSourcePath",
    ],
)

Bundle Targets

Bundle targets package binaries and resources into distributable applications:
App/BUCK (lines 149-168)
buck_local_bundle(
    name = "ExampleApp",
    visibility = [
        "//App:",
    ],
    extension = "app",
    binary = ":ExampleAppBinary",
    product_name = "ExampleApp",
    info_plist = "Info.plist",
    info_plist_substitutions = info_plist_substitutions("ExampleApp"),
    native_xcode_deps=prebuilt_frameworks + [
        # For "#watch", https://buckbuild.com/rule/apple_bundle.html#deps
        ":ExampleWatchApp#watch",
        ":ExampleMessageExtension",
        ":ExampleWidgetExtension",
    ]
    + prebuilt_frameworks
    + prebuilt_dynamic_frameworks,
    buck_local_deps=prebuilt_frameworks,
)
The #watch suffix is a Buck flavor that modifies how the target is built for WatchOS.

Asset Catalog Targets

Asset catalogs bundle app icons and images:
App/BUCK (lines 6-11)
buck_local_apple_asset_catalog(
    name = "ExampleAppAssets",
    visibility = ["//App:"],
    app_icon = "AppIcon",
    dirs = ["Assets.xcassets"],
)

Resource Targets

Resource targets include files like storyboards, strings, and other assets:
App/BUCK (lines 251-255)
apple_resource(
    name = "ExampleWatchAppResources",
    dirs = [],
    files = glob(["WatchApplication/**/*.storyboard"])
)

Test Targets

Test targets define unit and UI tests:
App/BUCK (lines 349-359)
apple_test_lib(
    name = "UnitTests",
    srcs = glob([
        "UnitTests/*.swift",
    ]),
    deps = [
        ":ExampleAppLibrary",
    ]
    + prebuilt_frameworks
    + prebuilt_dynamic_frameworks,
)
UI tests require special configuration with a test host app:
App/BUCK (lines 374-395)
apple_test_lib(
    name = "XCUITests",
    destination_specifier = {
        "name": "iPhone 8",
    },
    run_test_separately = True,
    test_host_app = ":XCUITestsHostApp",
    srcs = glob([
        "XCUITests/*.swift",
    ]),
    is_ui_test = True,
    ui_test_target_app = ":ExampleApp",
    labels = ['ui'],
    frameworks = [
        "$PLATFORM_DIR/Developer/Library/Frameworks/XCTest.framework",
        "$SDKROOT/System/Library/Frameworks/Foundation.framework",
        "$SDKROOT/System/Library/Frameworks/UIKit.framework",
    ],
)

Target Patterns

Wildcard Patterns

You can use wildcards to match multiple targets:
  • //App: - All targets in the App package
  • //App/... - All targets in App and all subpackages
  • //Libraries/... - All targets in all Libraries subpackages

Relative References

Within a BUCK file, you can reference targets using shorthand:
deps = [
    ":ExampleAppAssets",  # Same package
    "//App/Resources:StoryboardResources",  # Different package
]

App Extensions

BuckSample includes several iOS app extensions:
App/BUCK (lines 229-249)
apple_bundle(
    name = "ExampleWatchApp",
    binary = ":ExampleWatchAppBinary",
    visibility = [
        "//App:",
    ],
    extension = "app",
    info_plist = "WatchApplication/Info.plist",
    info_plist_substitutions = {
        "DEVELOPMENT_LANGUAGE": DEVELOPMENT_LANGUAGE,
        "EXECUTABLE_NAME": "ExampleWatchApp",
        "PRODUCT_BUNDLE_IDENTIFIER": bundle_identifier("ExampleApp.WatchApp"),
        "WK_COMPANION_APP_BUNDLE_IDENTIFIER": bundle_identifier("ExampleApp"),
        "PRODUCT_NAME": "ExampleWatchApp",
    },
    xcode_product_type = "com.apple.product-type.application.watchapp2",
    deps = [
        ":ExampleWatchAppExtension",
        ":ExampleWatchAppResources",
    ],
)
All extensions use special linker flags to properly set the entry point:
linker_flags = [
    "-e",
    "_NSExtensionMain",
    "-Xlinker",
    "-rpath",
    "-Xlinker",
    "@executable_path/../../Frameworks",
]

Building Specific Targets

To build a specific target:
buck build //App:ExampleApp
To build multiple targets:
buck build //App:ExampleApp //App:ExampleAppCITests

Next Steps

Dependencies

Learn how targets depend on each other

Configuration

Understand Buck configuration options

Build docs developers (and LLMs) love