To use these rules and macros in your BUILD
files, load
them from
xcodeproj/defs.bzl
.
For example, to use the xcodeproj
rule, you would need to use
this load
statement:
load("@rules_xcodeproj//xcodeproj:defs.bzl", "xcodeproj")
xcodeproj(name, adjust_schemes_for_swiftui_previews, archived_bundles_allowed, associated_extra_files, bazel_path, build_mode, config, default_xcode_configuration, extra_files, focused_targets, install_directory, ios_device_cpus, ios_simulator_cpus, minimum_xcode_version, post_build, pre_build, project_name, project_options, scheme_autogeneration_mode, schemes, temporary_directory, top_level_targets, tvos_device_cpus, tvos_simulator_cpus, unfocused_targets, watchos_device_cpus, watchos_simulator_cpus, xcode_configurations, kwargs)
Creates an .xcodeproj
file in the workspace when run.
This is a wrapper macro for the
actual xcodeproj
rule, which
can't be used directly. All public API is documented below. The kwargs
argument will pass forward values for globally available attributes (e.g.
visibility
, features
, etc.) to the underlying rule.
EXAMPLE
xcodeproj(
name = "xcodeproj",
project_name = "App",
tags = ["manual"],
top_level_targets = [
top_level_target(":App", target_environments = ["device", "simulator"]),
":Tests",
],
)
PARAMETERS
Name | Description | Default Value |
---|---|---|
name | A unique name for this target. | none |
adjust_schemes_for_swiftui_previews | Optional. Whether to adjust schemes in BwB mode to explicitly include transitive dependencies that are able to run SwiftUI Previews. For example, this changes a scheme for an single application target to also include any app clip, app extension, framework, or watchOS app dependencies. Defaults to True . |
True |
archived_bundles_allowed | This argument is deprecated and is now a no-op. It will be removed in a future release. Adjust the setting of --define=apple.experimental.tree_artifact_outputs on build:rules_xcodeproj in your .bazelrc or xcodeproj.bazelrc file. |
None |
associated_extra_files | Optional. A dict of files to be added to the project. The key is a string value representing the label of the target the files should be associated with, and the value is a list of File s. These files won't be added to the project if the target is unfocused. |
{} |
bazel_path | Optional. The path the bazel binary or wrapper script. If the path is relative it will be resolved using the PATH environment variable (which is set to /opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin in Xcode). If you want to specify a path to a workspace-relative binary, you must prepend the path with ./ (e.g. "./bazelw" ). |
"bazel" |
build_mode | Optional. The build mode the generated project should use. If this is set to "xcode" , the project will use the Xcode build system to build targets. Generated files and unfocused targets (see the focused_targets and unfocused_targets arguments) will be built with Bazel.If this is set to "bazel" , the project will use Bazel to build targets, inside of Xcode. The Xcode build system still unavoidably orchestrates some things at a high level. |
"bazel" |
config | Optional. The Bazel config to use when generating the project or invoking bazel inside of Xcode. This is the basename of multiple configs. For example, if this is set to "projectx_xcodeproj" , then the following configs will be available for you to adjust in your .bazelrc file: projectx_xcodeproj , projectx_xcodeproj_generator , projectx_xcodeproj_indexbuild , and projectx_xcodeproj_swiftuipreviews .See the usage guide for more information on adjusting Bazel configs. |
"rules_xcodeproj" |
default_xcode_configuration | Optional. The name of the the Xcode configuration to use when building, if not overridden by custom schemes. If not set, the first Xcode configuration alphabetically will be used. Use xcode_configurations to adjust Xcode configurations. |
None |
extra_files | Optional. A list of extra File s to be added to the project. |
[] |
focused_targets | Optional. A list of target labels as string values. If specified, only these targets will be included in the generated project; all other targets will be excluded, as if they were listed explicitly in the unfocused_targets argument. The labels must match transitive dependencies of the targets specified in the top_level_targets argument. |
[] |
install_directory | Optional. The directory where the generated project will be written to. The path is relative to the workspace root. Defaults to the directory that the xcodeproj target is declared in (e.g. if the xcodeproj target is declared in //foo/bar:BUILD then the default value is "foo/bar" ). Use "" to have the project generated in the workspace root. |
None |
ios_device_cpus | Optional. The value to use for --ios_multi_cpus when building the transitive dependencies of the targets specified in the top_level_targets argument with the "device" target_environment .Warning: Changing this value will affect the Starlark transition hash of all transitive dependencies of the targets specified in the top_level_targets argument with the "device" target_environment , even if they aren't iOS targets. |
"arm64" |
ios_simulator_cpus | Optional. The value to use for --ios_multi_cpus when building the transitive dependencies of the targets specified in the top_level_targets argument with the "simulator" target_environment .If no value is specified, it defaults to the simulator cpu that goes with --host_cpu (i.e. sim_arm64 on Apple Silicon and x86_64 on Intel).Warning: Changing this value will affect the Starlark transition hash of all transitive dependencies of the targets specified in the top_level_targets argument with the "simulator" target_environment , even if they aren't iOS targets. |
None |
minimum_xcode_version | Optional. The minimum Xcode version that the generated project supports. Newer Xcode versions can support newer features, so setting this to the highest value you can will enable the most features. The value is the dot separated version number (e.g. "13.4.1", "14", "14.1"). Defaults to whichever version of Xcode that Bazel uses during project generation. | None |
post_build | The text of a script that will be run after the build. For example: ./post-build.sh , "$SRCROOT/post-build.sh" .The script will be run in Bazel's execution root, so you probably want to change to the $SRCROOT directory in the script.Currently this script will be run as part of Index Build. If you don't want that (which is probably the case), you should add a check to ensure $ACTION == build . |
None |
pre_build | The text of a script that will be run before the build. For example: ./pre-build.sh , "$SRCROOT/pre-build.sh" .The script will be run in Bazel's execution root, so you probably want to change to the $SRCROOT directory in the script.Currently this script will be run as part of Index Build. If you don't want that (which is probably the case), you should add a check to ensure $ACTION == build . |
None |
project_name | Optional. The name to use for the .xcodeproj file. If not specified, the value of the name argument is used. |
None |
project_options | Optional. A value returned by project_options . |
None |
scheme_autogeneration_mode | Optional. Specifies how Xcode schemes are automatically generated. - auto : If no custom schemes are specified, via schemes , an Xcode scheme will be created for every buildable target. If custom schemes are provided, no autogenerated schemes will be created.- none : No schemes are automatically generated.- all : A scheme is generated for every buildable target even if custom schemes are provided. |
"auto" |
schemes | Optional. A list of values returned by xcode_schemes.scheme . Target labels listed in the schemes need to be from the transitive dependencies of the targets specified in the top_level_targets argument. This and the scheme_autogeneration_mode argument together customize how schemes for those targets are generated. |
[] |
temporary_directory | This argument is deprecated and is now a no-op. It will be removed in a future release. | None |
top_level_targets | A list of a list of top-level targets. Each target can be specified as either a Label (or label-like string ), a value returned by top_level_target , or a value returned by top_level_targets . |
none |
tvos_device_cpus | Optional. The value to use for --tvos_cpus when building the transitive dependencies of the targets specified in the top_level_targets argument with the "device" target_environment .Warning: Changing this value will affect the Starlark transition hash of all transitive dependencies of the targets specified in the top_level_targets argument with the "device" target_environment , even if they aren't tvOS targets. |
"arm64" |
tvos_simulator_cpus | Optional. The value to use for --tvos_cpus when building the transitive dependencies of the targets specified in the top_level_targets argument with the "simulator" target_environment .If no value is specified, it defaults to the simulator cpu that goes with --host_cpu (i.e. sim_arm64 on Apple Silicon and x86_64 on Intel).Warning: Changing this value will affect the Starlark transition hash of all transitive dependencies of the targets specified in the top_level_targets argument with the "simulator" target_environment , even if they aren't tvOS targets. |
None |
unfocused_targets | Optional. A list of target labels as string values. Any targets in the transitive dependencies of the targets specified in the top_level_targets argument with a matching label will be excluded from the generated project. This overrides any targets specified in the focused_targets argument. |
[] |
watchos_device_cpus | Optional. The value to use for --watchos_cpus when building the transitive dependencies of the targets specified in the top_level_targets argument with the "device" target_environment .Warning: Changing this value will affect the Starlark transition hash of all transitive dependencies of the targets specified in the top_level_targets argument with the "device" target_environment , even if they aren't watchOS targets. |
"arm64_32" |
watchos_simulator_cpus | Optional. The value to use for --watchos_cpus when building the transitive dependencies of the targets specified in the top_level_targets argument with the "simulator" target_environment .If no value is specified, it defaults to the simulator cpu that goes with --host_cpu (i.e. arm64 on Apple Silicon and x86_64 on Intel).Warning: Changing this value will affect the Starlark transition hash of all transitive dependencies of the targets specified in the top_level_targets argument with the "simulator" target_environment , even if they aren't watchOS targets. |
None |
xcode_configurations | Optional. A dict mapping Xcode configuration names to transition settings dictionaries. For example, {"Dev": {"//command_line_option:compilation_mode": "dbg"}, "AppStore": {"//command_line_option:compilation_mode": "opt"}} , would create the "Dev" and "AppStore" configurations, setting --compilation_mode to dbg and opt respectively.Refer to the bazel documentation on how to define the transition settings dictionary. |
{"Debug": {}} |
kwargs | Additional arguments to pass to the underlying xcodeproj rule specified by xcodeproj_rule . |
none |
top_level_target(label, target_environments)
Constructs a top-level target for use in xcodeproj.top_level_targets
.
PARAMETERS
RETURNS
A struct
containing fields for the provided arguments.
top_level_targets(labels, target_environments)
Constructs a list of top-level target for use in xcodeproj.top_level_targets
.
PARAMETERS
Name | Description | Default Value |
---|---|---|
labels | A list of Label or label-like string for the targets. |
none |
target_environments | Optional. See top_level_target.target_environments . |
["simulator"] |
RETURNS
A list
of values returned from top_level_target
.
project_options(development_region, indent_width, organization_name, tab_width, uses_tabs)
Project options for use in xcodeproj.project_options
.
PARAMETERS
RETURNS
A struct
containing fields for the provided arguments.
To use these functions, load
the xcode_schemes
module from
xcodeproj/defs.bzl
:
load("@rules_xcodeproj//xcodeproj:defs.bzl", "xcode_schemes")
xcode_schemes.scheme(name, build_action, launch_action, profile_action, test_action)
Returns a struct
representing an Xcode scheme.
PARAMETERS
RETURNS
A struct
representing an Xcode scheme.
xcode_schemes.build_action(targets, pre_actions, post_actions)
Constructs a build action for an Xcode scheme.
PARAMETERS
RETURNS
A struct
representing a build action.
xcode_schemes.build_target(label, build_for)
Constructs a build target for an Xcode scheme's build action.
PARAMETERS
RETURNS
A struct
representing a build target.
xcode_schemes.build_for(running, testing, profiling, archiving, analyzing)
Construct a struct
representing the settings that dictate when Xcode will build a target.
PARAMETERS
RETURNS
A struct
.
xcode_schemes.launch_action(target, args, build_configuration, diagnostics, env, working_directory)
Constructs a launch action for an Xcode scheme.
PARAMETERS
RETURNS
A struct
representing a launch action.
xcode_schemes.profile_action(target, args, build_configuration, env, working_directory)
Constructs a profile action for an Xcode scheme.
PARAMETERS
RETURNS
A struct
representing a profile action.
xcode_schemes.test_action(targets, args, build_configuration, diagnostics, env, expand_variables_based_on, pre_actions, post_actions)
Constructs a test action for an Xcode scheme.
PARAMETERS
RETURNS
A struct
representing a test action.
xcode_schemes.diagnostics(sanitizers)
Constructs the scheme's diagnostics.
PARAMETERS
Name | Description | Default Value |
---|---|---|
sanitizers | Optional. A struct value as created by xcode_schemes.sanitizers . |
None |
RETURNS
A struct
representing scheme's diagnostics.
xcode_schemes.sanitizers(address, thread, undefined_behavior)
Constructs the scheme's sanitizers' default state. The state can also be modified in Xcode.
PARAMETERS
xcode_schemes.pre_post_action(name, script, expand_variables_based_on)
Constructs a pre or post action for a step of the scheme.
PARAMETERS
RETURNS
A struct
representing a scheme's step pre or post action.
Rules that provide additional information to the xcodeproj
rule,
so that it can properly determine values for various Xcode build settings.
xcode_provisioning_profile(name, managed_by_xcode, profile_name, provisioning_profile, team_id)
This rule declares a target that you can pass to the provisioning_profile
attribute of rules that require it. It wraps another provisioning profile
target, either a File
or a rule like rules_apple's
local_provisioning_profile
, and allows specifying additional information to
adjust Xcode related build settings related to code signing.
If you are already using local_provisioning_profile
, or another rule that
returns the AppleProvisioningProfileInfo
provider, you don't need to use this
rule, unless you want to enable Xcode's "Automatic Code Signing" feature. If you
are using a File
, then this rule is needed in order to set the
DEVELOPER_TEAM
build setting via the team_id
attribute.
EXAMPLE
ios_application(
...
provisioning_profile = ":xcode_profile",
...
)
xcode_provisioning_profile(
name = "xcode_profile",
managed_by_xcode = True,
provisioning_profile = ":provisioning_profile",
)
local_provisioning_profile(
name = "provisioning_profile",
profile_name = "iOS Team Provisioning Profile: com.example.app",
team_id = "A12B3CDEFG",
)
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
managed_by_xcode | Whether the provisioning profile is managed by Xcode. If True , "Automatic Code Signing" will be enabled in Xcode, and the profile name will be ignored. Xcode will add devices to profiles automatically via the currently logged in Apple Developer Account, and otherwise fully manage the profile. If False , "Manual Code Signing" will be enabled in Xcode, and the profile name will be used to determine which profile to use.If xcodeproj.build_mode != "xcode" , then Xcode will still manage the profile when this is True , but otherwise won't use it to actually sign the binary. Instead Bazel will perform the code signing with the file set to provisioning_profile . Using rules_apple's local_provisioning_profile as the target set to provisioning_profile will then allow Bazel to code sign with the Xcode managed profile. |
Boolean | required | |
profile_name | When managed_by_xcode is False , the PROVISIONING_PROFILE_SPECIFIER Xcode build setting will be set to this value. If this is None (the default), and provisioning_profile returns the AppleProvisioningProfileInfo provider (as local_provisioning_profile does), then AppleProvisioningProfileInfo.profile_name will be used instead. |
String | optional | "" |
provisioning_profile | The File that Bazel will use when code signing. If the target returns the AppleProvisioningProfileInfo provider (as local_provisioning_profile does), then it will provide default values for profile_name and team_id .When xcodeproj.build_mode = "xcode" , the actual file isn't used directly by Xcode, but in order to satisfy Bazel constraints this can't be None . |
Label | required | |
team_id | The DEVELOPER_TEAM Xcode build setting will be set to this value. If this is None (the default), and provisioning_profile returns the AppleProvisioningProfileInfo provider (as local_provisioning_profile does), then AppleProvisioningProfileInfo.team_id will be used instead. |
String | optional | "" |
Providers that are used throughout the rules in this repository.
Most users will not need to use these providers to simply create Xcode projects, but if you want to write your own custom rules that interact with these rules, then you will use these providers to communicate between them.
XcodeProjAutomaticTargetProcessingInfo(all_attrs, alternate_icons, app_icons, args, bazel_build_mode_error, bundle_id, codesignopts, deps, entitlements, env, exported_symbols_lists, hdrs, infoplists, launchdplists, link_mnemonics, non_arc_srcs, pch, provisioning_profile, should_generate_target, srcs, target_type, xcode_targets)
Provides needed information about a target to allow rules_xcodeproj to automatically process it.
If you need more control over how a target or its dependencies are processed,
return a XcodeProjInfo
provider instance instead.
Warning: This provider currently has an unstable API and may change in the future. If you are using this provider, please let us know so we can prioritize stabilizing it.
FIELDS
XcodeProjInfo(args, compilation_providers, dependencies, envs, extension_infoplists, hosted_targets, inputs, is_top_level_target, label, lldb_context, potential_target_merges, outputs, replacement_labels, resource_bundle_informations, rule_kind, search_paths, target_type, transitive_dependencies, xcode_required_targets, xcode_target, xcode_targets)
Provides information needed to generate an Xcode project.
Warning: This provider currently has an unstable API and may change in the future. If you are using this provider, please let us know so we can prioritize stabilizing it.
FIELDS