Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
391 lines (360 sloc) 12.5 KB

General Apple build rules

apple_bundle_version

apple_bundle_version(name, build_label_pattern, build_version, capture_groups,
fallback_build_label, short_version_string)

Produces a target that contains versioning information for an Apple bundle.

This rule allows version numbers to be hard-coded into the BUILD file or extracted from the build label passed into Bazel using the --embed_label command line flag.

Targets created by this rule do not generate outputs themselves, but instead should be used in the version attribute of an Apple application or extension bundle target to set the version keys in that bundle's Info.plist file.

Examples

# A version scheme that uses hard-coded versions checked into your
# BUILD files.
apple_bundle_version(
    name = "simple",
    build_version = "1.0.134",
    short_version_string = "1.0",
)

ios_application(
    name = "foo_app",
    ...,
    version = ":simple",
)

# A version scheme that parses version information out of the build
# label and uses a fallback for developers' builds. For example, the
# following command
#
#    bazel build //myapp:myapp --embed_label=MyApp_1.2_build_345
#
# would yield the Info.plist values:
#
#    CFBundleVersion = "1.2.345"
#    CFBundleShortVersionString = "1.2"
#
# and the development builds using the command:
#
#    bazel build //myapp:myapp
#
# would yield the values:
#
#    CFBundleVersion = "99.99.99"
#    CFBundleShortVersionString = "99.99"
#
apple_bundle_version(
    name = "build_label_version",
    build_label_pattern = "MyApp_{version}_build_{build}",
    build_version = "{version}.{build}",
    capture_groups = {
        "version": "\d+\.\d+",
        "build": "\d+",
    },
    short_version_string = "{version}",
    fallback_build_label = "MyApp_99.99_build_99",
)

ios_application(
    name = "bar_app",
    ...,
    version = ":build_label_version",
)
Attributes
name

Name, required

A unique name for the target.

build_label_pattern

String; optional

A pattern that should contain placeholders inside curly braces (e.g., "foo_{version}_bar") that is used to parse the build label passed into Bazel using the --embed_label command line flag. Each of the placeholders is expected to match one of the keys in the capture_groups attribute.

NOTE: When using build_label_pattern, if a build is done without a --embed_label=... argument and there is no fallback_build_label, then no version info will be set.

build_version

String; required

A string that will be used as the value for the CFBundleVersion key in a depending bundle's Info.plist. If this string contains placeholders, then they will be replaced by strings captured out of build_label_pattern.

capture_groups

Dictionary of strings to strings; optional

A dictionary where each key is the name of a placeholder found in build_label_pattern and the corresponding value is the regular expression that should match that placeholder. If this attribute is provided, then build_label_pattern must also be provided.

fallback_build_label

String; optional

A string that will be used as the value for the build label if the build was done without --embed_label. This is only needed when also using build_label_pattern. This allows a version label to be used for version extraction during development when a label isn't normally provided. Some teams use the convention of having a version like 99.99.99 so it is clear it isn't being released to customers.

NOTE: This is a build label and not a raw version number. It must match build_label_pattern so the values can be extracted and then have the build_version and short_version_string templates applied.

short_version_string

String; optional

A string that will be used as the value for the CFBundleShortVersionString key in a depending bundle's Info.plist. If this string contains placeholders, then they will be replaced by strings captured out of build_label_pattern. This attribute is optional; if it is omitted, then the value of build_version will be used for this key as well.

apple_dynamic_framework_import

apple_dynamic_framework_import(name, framework_imports, deps)

This rule encapsulates an already-built dynamic framework. It is defined by a list of files in exactly one .framework directory. apple_dynamic_framework_import targets need to be added to library targets through the deps attribute.

Examples

apple_dynamic_framework_import(
    name = "my_dynamic_framework",
    framework_imports = glob(["my_dynamic_framework.framework/**"]),
)

objc_library(
    name = "foo_lib",
    ...,
    deps = [
        ":my_dynamic_framework",
    ],
)
Attributes
name

Name, required

A unique name for the target.

framework_imports

List of labels; required

The list of files under a .framework directory which are provided to Apple based targets that depend on this target.

deps

List of labels; optional

A list of targets that are dependencies of the target being built, which will be linked into that target.

apple_static_framework_import

apple_static_framework_import(name, framework_imports, alwayslink, sdk_dylibs,
sdk_frameworks, weak_sdk_frameworks, deps)

This rule encapsulates an already-built static framework. It is defined by a list of files in exactly one .framework directory. apple_static_framework_import targets need to be added to library targets through the deps attribute.

Examples

apple_static_framework_import(
    name = "my_static_framework",
    framework_imports = glob(["my_static_framework.framework/**"]),
)

objc_library(
    name = "foo_lib",
    ...,
    deps = [
        ":my_static_framework",
    ],
)
Attributes
name

Name, required

A unique name for the target.

framework_imports

List of labels; required

The list of files under a .framework directory which are provided to Apple based targets that depend on this target.

alwayslink

Bool; optional

If true, any binary that depends (directly or indirectly) on this framework will link in all the object files for the framework file, even if some contain no symbols referenced by the binary. This is useful if your code isn't explicitly called by code in the binary; for example, if you rely on runtime checks for protocol conformances added in extensions in the library but do not directly reference any other symbols in the object file that adds that conformance.

sdk_dylibs

List of strings; optional

Names of SDK .dylib libraries to link with. For instance, libz or libarchive. libc++ is included automatically if the binary has any C++ or Objective-C++ sources in its dependency tree. When linking a binary, all libraries named in that binary's transitive dependency graph are used.

sdk_frameworks

List of strings; optional

Names of SDK frameworks to link with (e.g. AddressBook, QuartzCore). UIKit and Foundation are always included when building for the iOS, tvOS and watchOS platforms. For macOS, only Foundation is always included. When linking a top level binary, all SDK frameworks listed in that binary's transitive dependency graph are linked.

weak_sdk_frameworks

List of strings; optional

Names of SDK frameworks to weakly link with. For instance, MediaAccessibility. In difference to regularly linked SDK frameworks, symbols from weakly linked frameworks do not cause an error if they are not present at runtime.

deps

List of labels; optional

A list of targets that are dependencies of the target being built, which will be linked into that target.

dtrace_compile

dtrace_compile(name, srcs)

Compiles dtrace files with probes to generate header files to use those probes in C languages. The header files generated will have the same name as the source files but with a .h extension. Headers will be generated in a label scoped workspace relative file structure. For example with a directory structure of

  Workspace
  foo/
    bar.d

and a target named dtrace_gen the header path would be <GENFILES>/dtrace_gen/foo/bar.h.

Attributes
name

Name, required

A unique name for the target.

srcs

List of labels; required

dtrace source files to be compiled.

You can’t perform that action at this time.