rules_xcodeproj uses a family of Bazel configs to control two distinct phases: how the project is generated, and how Xcode invokes Bazel when you press ⌘B. Understanding these configs — and which one to target for a given flag — is key to getting predictable build behavior across generation, compilation, indexing, and previews.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/MobileNativeFoundation/rules_xcodeproj/llms.txt
Use this file to discover all available pages before exploring further.
The config family
rules_xcodeproj
rules_xcodeproj is the parent of all other rules_xcodeproj_* configs. It is active whenever Bazel is invoked by Xcode as part of a build (i.e. not during project generation). All child configs inherit from it.
rules_xcodeproj_generator
rules_xcodeproj_generator is used when you run bazel run //:xcodeproj to generate the project. Flags here do not affect the build inside Xcode.
The types of flags appropriate here are non-build-affecting, such as adjusting build log output, BES upload settings, or profiling during generation.
rules_xcodeproj_indexbuild
rules_xcodeproj_indexbuild is used when Xcode performs an Index Build (also called “Prepare for Indexing”). Xcode runs an index build in the background, sometimes once per target and again every time you save a file, to keep code-completion and jump-to-definition data up to date.
Because index builds run so frequently, be conservative about what you enable here. The default config already disables BES upload. A common pattern is to clear a flag that is set globally so it does not accumulate:
.bazelrc
rules_xcodeproj_swiftuipreviews
rules_xcodeproj_swiftuipreviews is used when Xcode performs a SwiftUI Preview build. The default config already applies the build-adjusting flags required for previews to work. You should not need to modify this config in most cases.
rules_xcodeproj_coverage
rules_xcodeproj_coverage is used when Xcode builds tests with code coverage enabled. It sets the necessary features in apple_support and rules_swift to generate coverage data with absolute source paths so Xcode can map them correctly.
Code coverage in Xcode with Bazel requires apple_support 2.0.0 or later and rules_swift 3.4.1 or later.Code coverage is disabled by default for scheme test actions. You can enable it via
xcschemes.test_options(code_coverage = True) or by toggling “Gather coverage data” in the Xcode scheme editor.Project-level configs
Eachxcodeproj target can specify a custom config base name via the config attribute. For example, setting config = "projectx_xcodeproj" makes the following configs available in your .bazelrc:
projectx_xcodeprojprojectx_xcodeproj_generatorprojectx_xcodeproj_indexbuildprojectx_xcodeproj_swiftuipreviews
rules_xcodeproj{_*} counterparts, so you only need to specify the delta.
BUILD
.bazelrc
Using project-level configs adds a layer of indirection. Only add it if you genuinely have project-specific configurations that cannot be shared at the workspace level.
Extra config flags
There is one additional way to inject flags: the--@rules_xcodeproj//xcodeproj:extra_*_flags family of build flags. These are applied after all other sources and therefore override everything else, mimicking the behavior of command-line flags:
| Flag | Which config it targets |
|---|---|
--@rules_xcodeproj//xcodeproj:extra_common_flags | rules_xcodeproj (parent) |
--@rules_xcodeproj//xcodeproj:extra_generator_flags | rules_xcodeproj_generator |
--@rules_xcodeproj//xcodeproj:extra_indexbuild_flags | rules_xcodeproj_indexbuild |
--@rules_xcodeproj//xcodeproj:extra_swiftuipreviews_flags | rules_xcodeproj_swiftuipreviews |
bazel run command when generating the project:
xcodeproj_extra_flags.bazelrc file so they apply automatically on every subsequent Xcode build.
.bazelrc loading order
Understanding the loading order helps you predict which flag wins when the same flag is set in multiple places.
Project xcodeproj.bazelrc
A project-specific
xcodeproj.bazelrc is generated from a template and loaded first. It contains the default config definitions and (if used) stubs for project-level configs. You should not edit this file directly — it is regenerated each time you run bazel run //:xcodeproj.Workspace xcodeproj.bazelrc
At the end of the project
xcodeproj.bazelrc is a conditional import of a workspace-level xcodeproj.bazelrc. This file is not regenerated, making it safe to edit. Because startup flags (e.g. --host_jvm_args) cannot be applied inside a config, this is the right place to set startup flags that should only apply to rules_xcodeproj Bazel invocations.--output_base is already managed by rules_xcodeproj. Setting startup --output_base in this file has no effect.Workspace .bazelrc
The standard workspace
.bazelrc is imported next. You can further adjust the configs here.Separating the index build output base
By default, rules_xcodeproj configures Xcode to use a combined output base for both normal builds and index builds. Sharing the output base saves disk space and improves cache hit rates because both build types can reuse each other’s outputs. If you find that index builds are interfering with normal builds (for example, causing analysis-cache invalidation), you can enable a separate output base during project generation:.bazelrc