Apple Rules for Bazel
⚠️ NOTE: At the time of this writing, the most recent Bazel release is 0.4.5. These rules are not compatible with that release; they are only compatible with Bazel at master. Until the next release of Bazel, you will need to build Bazel from source if you wish to use them.
This repository contains rules for Bazel that can be
used to bundle applications for Apple platforms. They replace the bundling
rules defined in Bazel itself (such as ios_application
, ios_extension
, and
apple_watch2_extension
).
These rules handle the linking and bundling of applications and extensions
(that is, the formation of an .app
with an executable and resources,
archived in an .ipa
). Compilation is still performed by the existing
objc_library
rule
in Bazel; to link those dependencies, these bundling rules use Bazel's
apple_binary
rule
under the hood.
- ios_application
- ios_extension
- ios_framework (experimental)
- tvos_application
- tvos_extension
- watchos_application
- watchos_extension
- swift_library
Add the following to your WORKSPACE
file to add the external repositories,
replacing the version number in the tag
attribute with the version of the
rules you wish to depend on:
git_repository(
name = "build_bazel_rules_apple",
remote = "https://github.com/bazelbuild/rules_apple.git",
tag = "0.0.1",
)
Minimal example:
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application")
objc_library(
name = "Lib",
srcs = glob([
"**/*.h",
"**/*.m",
]),
resources = [
":Main.storyboard",
],
)
# Links code from "deps" into an executable, collects and compiles resources
# from "deps" and places them with the executable in an .app bundle, and then
# outputs an .ipa with the bundle in its Payload directory.
ios_application(
name = "App",
bundle_id = "com.example.app",
families = ["iphone", "ipad"],
infoplists = [":Info.plist"],
deps = [":Lib"],
)
See the examples directory for sample applications.
Even though the rules in this repository have the same names as their built-in
counterparts, they cannot be intermixed; for example, an ios_application
from
this repository cannot have an extension that is a built-in ios_extension
or
vice versa.
The wiki for this repository contains a migration guide describing in detail the differences between the old and new rules and how to update your build targets.
- macOS support
- Support for compiling texture atlases
- Improved rules for creating resource bundles
ios_application(name, app_icons, bundle_id, entitlements, extensions, families,
frameworks, infoplists, ipa_post_processor, launch_images, launch_storyboard,
linkopts, product_type, provisioning_profile, settings_bundle, strings, deps)
Builds and bundles an iOS application.
The named target produced by this macro is an IPA file. This macro also creates
a target named {name}.apple_binary
that represents the linked executable
inside the application bundle.
Attributes | |
---|---|
name |
A unique name for the target. |
app_icons |
Files that comprise the app icons for the application. Each file
must have a containing directory named |
bundle_id |
The bundle ID (reverse-DNS path followed by app name) of the application. |
entitlements |
The entitlements file required for device builds of the application. If absent, the default entitlements from the provisioning profile will be used. The following variables are substituted in the entitlements file:
|
extensions |
A list of extensions (see |
families |
A list of device families supported by this application. Valid values
are |
frameworks |
A list of framework targets (see |
infoplists |
A list of |
ipa_post_processor |
A tool that edits this target's IPA output after it is assembled but
before it is signed. The tool is invoked with a single command-line
argument that denotes the path to a directory containing the unzipped
contents of the IPA (that is, the Any changes made by the tool must be made in this directory, and the tool's execution must be hermetic given these inputs to ensure that the result can be safely cached. |
launch_images |
Files that comprise the launch images for the application. Each file
must have a containing directory named It is recommended that you use a |
launch_storyboard |
The |
linkopts |
A list of strings representing extra flags that the underlying
|
product_type |
An optional string denoting a special type of application, such as
a Messages Application in iOS 10 and higher. See
|
provisioning_profile |
The provisioning profile ( |
settings_bundle |
An |
strings |
A list of |
watch_application |
A |
deps |
A list of dependencies targets that are passed into the
|
ios_extension(name, app_icons, bundle_id, entitlements, families, frameworks,
infoplists, ipa_post_processor, linkopts, product_type, provisioning_profile,
strings, deps)
Builds and bundles an iOS application extension.
The named target produced by this macro is a ZIP file. This macro also creates a
target named {name}.apple_binary
that represents the linked binary
executable inside the extension bundle.
Attributes | |
---|---|
name |
A unique name for the target. |
app_icons |
Files that comprise the app icons for the extension. Each file
must have a containing directory named |
bundle_id |
The bundle ID (reverse-DNS path followed by app name) of the extension. |
entitlements |
The entitlements file required for device builds of the extension. If absent, the default entitlements from the provisioning profile will be used. The following variables are substituted in the entitlements file:
|
families |
A list of device families supported by this extension. Valid values
are |
frameworks |
A list of framework targets (see |
infoplists |
A list of |
ipa_post_processor |
A tool that edits this target's archive after it is assembled but
before it is signed. The tool is invoked with a single command-line
argument that denotes the path to a directory containing the unzipped
contents of the archive; the Any changes made by the tool must be made in this directory, and the tool's execution must be hermetic given these inputs to ensure that the result can be safely cached. |
linkopts |
A list of strings representing extra flags that the underlying
|
product_type |
An optional string denoting a special type of extension, such as
a Messages Extension in iOS 10 and higher. See
|
provisioning_profile |
The provisioning profile ( |
strings |
A list of |
deps |
A list of dependencies targets that are passed into the
|
ios_framework(name, bundle_id, families, infoplists, ipa_post_processor,
linkopts, strings, deps)
Builds and bundles an iOS dynamic framework.
The named target produced by this macro is a ZIP file. This macro also creates a
target named {name}.apple_binary
that represents the linked dynamic library
inside the framework bundle.
Attributes | |
---|---|
name |
A unique name for the target. |
bundle_id |
The bundle ID (reverse-DNS path followed by app name) of the framework. |
families |
A list of device families supported by this framework. Valid values
are |
infoplists |
A list of |
ipa_post_processor |
A tool that edits this target's archive after it is assembled but
before it is signed. The tool is invoked with a single command-line
argument that denotes the path to a directory containing the unzipped
contents of the archive; the Any changes made by the tool must be made in this directory, and the tool's execution must be hermetic given these inputs to ensure that the result can be safely cached. |
linkopts |
A list of strings representing extra flags that the underlying
|
strings |
A list of |
deps |
A list of dependencies targets that are passed into the
|
tvos_application(name, app_icons, bundle_id, entitlements, extensions,
infoplists, ipa_post_processor, launch_images, launch_storyboard, linkopts,
provisioning_profile, settings_bundle, strings, deps)
Builds and bundles a tvOS application.
The named target produced by this macro is an IPA file. This macro also creates
a target named {name}.apple_binary
that represents the linked executable
inside the application bundle.
Attributes | |
---|---|
name |
A unique name for the target. |
app_icons |
Files that comprise the app icons for the application. Each file
must have a containing directory named |
bundle_id |
The bundle ID (reverse-DNS path followed by app name) of the application. |
entitlements |
The entitlements file required for device builds of the application. If absent, the default entitlements from the provisioning profile will be used. The following variables are substituted in the entitlements file:
|
extensions |
A list of extensions (see |
infoplists |
A list of |
ipa_post_processor |
A tool that edits this target's IPA output after it is assembled but
before it is signed. The tool is invoked with a single command-line
argument that denotes the path to a directory containing the unzipped
contents of the IPA (that is, the Any changes made by the tool must be made in this directory, and the tool's execution must be hermetic given these inputs to ensure that the result can be safely cached. |
launch_images |
Files that comprise the launch images for the application. Each file
must have a containing directory named It is recommended that you use a |
launch_storyboard |
The |
linkopts |
A list of strings representing extra flags that the underlying
|
provisioning_profile |
The provisioning profile ( |
settings_bundle |
An |
strings |
A list of |
deps |
A list of dependencies targets that are passed into the
|
tvos_extension(name, bundle_id, entitlements, infoplists, ipa_post_processor,
linkopts, strings, deps)
Builds and bundles a tvOS extension.
The named target produced by this macro is a ZIP file. This macro also creates a
target named {name}.apple_binary
that represents the linked binary
executable inside the extension bundle.
Attributes | |
---|---|
name |
A unique name for the target. |
bundle_id |
The bundle ID (reverse-DNS path followed by app name) of the extension. |
entitlements |
The entitlements file required for device builds of the extension. If absent, the default entitlements from the provisioning profile will be used. The following variables are substituted in the entitlements file:
|
infoplists |
A list of |
ipa_post_processor |
A tool that edits this target's archive after it is assembled but
before it is signed. The tool is invoked with a single command-line
argument that denotes the path to a directory containing the unzipped
contents of the archive; the Any changes made by the tool must be made in this directory, and the tool's execution must be hermetic given these inputs to ensure that the result can be safely cached. |
linkopts |
A list of strings representing extra flags that the underlying
|
provisioning_profile |
The provisioning profile ( |
strings |
A list of |
deps |
A list of dependencies targets that are passed into the
|
watchos_application(name, app_icons, bundle_id, entitlements, extension,
infoplists, ipa_post_processor, provisioning_profile, storyboards, strings,
deps)
Builds and bundles a watchOS application.
This rule only supports watchOS 2.0 and higher. Apple no longer supports or accepts submissions of apps written for watchOS 1.x, so these bundling rules do not support that version of the platform.
The named target produced by this macro is a ZIP file. The watch application is
not executable or installable by itself; the target must be added to a
companion ios_application
using the watch_application
attribute on that
rule.
Attributes | |
---|---|
name |
A unique name for the target. |
app_icons |
Files that comprise the app icons for the application. Each file
must have a containing directory named |
bundle_id |
The bundle ID (reverse-DNS path followed by app name) of the application. |
entitlements |
The entitlements file required for device builds of the application. If absent, the default entitlements from the provisioning profile will be used. The following variables are substituted in the entitlements file:
|
extension |
The |
infoplists |
A list of |
ipa_post_processor |
A tool that edits this target's IPA output after it is assembled but
before it is signed. The tool is invoked with a single command-line
argument that denotes the path to a directory containing the unzipped
contents of the IPA (that is, the Any changes made by the tool must be made in this directory, and the tool's execution must be hermetic given these inputs to ensure that the result can be safely cached. |
provisioning_profile |
The provisioning profile ( |
storyboards |
A list of |
strings |
A list of |
deps |
A list of targets whose resources will be included in the final application. Since a watchOS application does not contain any code of its own, any code in the dependent libraries will be ignored. |
watchos_extension(name, app_icons, bundle_id, entitlements, infoplists,
ipa_post_processor, linkopts, provisioning_profile, strings, deps)
Builds and bundles a watchOS extension.
This rule only supports watchOS 2.0 and higher. Apple no longer supports or accepts submissions of apps written for watchOS 1.x, so these bundling rules do not support that version of the platform.
The named target produced by this macro is a ZIP file. This macro also creates a
target named {name}.apple_binary
that represents the linked binary
executable inside the extension bundle.
Attributes | |
---|---|
name |
A unique name for the target. |
app_icons |
Files that comprise the app icons for the extension. Each file
must have a containing directory named |
bundle_id |
The bundle ID (reverse-DNS path followed by app name) of the extension. |
entitlements |
The entitlements file required for device builds of the extension. If absent, the default entitlements from the provisioning profile will be used. The following variables are substituted in the entitlements file:
|
infoplists |
A list of |
ipa_post_processor |
A tool that edits this target's archive after it is assembled but
before it is signed. The tool is invoked with a single command-line
argument that denotes the path to a directory containing the unzipped
contents of the archive; the Any changes made by the tool must be made in this directory, and the tool's execution must be hermetic given these inputs to ensure that the result can be safely cached. |
linkopts |
A list of strings representing extra flags that the underlying
|
provisioning_profile |
The provisioning profile ( |
strings |
A list of |
deps |
A list of dependencies targets that are passed into the
|
swift_library(name, srcs, deps, module_name, defines, copts)
Produces a static library from Swift sources. The output is a pair of .a and .swiftmodule files.
Attributes | |
---|---|
name |
A unique name for the target. |
srcs |
Sources to compile into this library. Only |
deps |
A list of Swift or Objective-C libraries to link together. |
module_name |
Sets the Swift module name for this target. By default
the module name is the target path with all special symbols replaced
by |
defines |
Values to be passed with |
copts |
Additional compiler flags. Passed to the compile actions of this target only. |
A struct
containing product type identifiers used by special application and
extension types.
Some applications and extensions, such as Messages Extensions and Sticker Packs in iOS 10, receive special treatment when building (for example, some product types bundle a stub executable instead of a user-defined binary, and some pass extra arguments to tools like the asset compiler). These behaviors are captured in the product type identifier. The product types currently supported are:
Product types | |
---|---|
messages_application |
Applies to A "stub" application used to distribute a standalone Messages
Extension or Sticker Pack. This application must
include an This product type does not contain a user-provided binary; any code
in its This stub application is not displayed on the home screen and its features are only accessible through the Messages user interface. If you are building a Messages Extension or Sticker Pack as part of a larger application that is launchable, do not use this product type; simply add those extensions to the existing application. |
messages_extension |
Applies to An extension that integrates custom behavior into the Apple Messages application. Such extensions can present a custom user interface in the keyboard area of the app and interact with users' conversations. |
messages_sticker_pack_extension |
Applies to An extension that defines custom sticker packs for the Apple
Messages app. Stickers are provided by including an asset catalog
named This product type does not contain a user-provided binary; any
code in its |
Example usage:
load("@build_bazel_rules_apple//apple:ios.bzl",
"apple_product_type", "ios_application", "ios_extension")
ios_application(
name = "StickerPackApp",
extensions = [":StickerPackExtension"],
product_type = apple_product_type.messages_application,
# other attributes...
)
ios_extension(
name = "StickerPackExtension",
product_type = apple_product_type.messages_sticker_pack_extension,
# other attributes...
)