# Locking Xcode versions in bazel

DevFeed: [Locking Xcode versions in bazel](<https://devfeed.tech/articles/locking-xcode-versions-in-bazel-25403.md>)

Original publisher: [Read original article](<https://smileykeith.com/2021/03/08/locking-xcode-in-bazel/>)

Author: Keith Smiley

Published: 2021-03-08T16:40:00Z

Content type: article

Language: en

Sources: [Keith Smiley](<https://devfeed.tech/sources/keith-smiley.md>)

Topics: [Xcode](<https://devfeed.tech/topics/xcode.md>), [Cache](<https://devfeed.tech/topics/cache.md>), [macOS](<https://devfeed.tech/topics/macos.md>), [iOS](<https://devfeed.tech/topics/ios.md>), [SDK](<https://devfeed.tech/topics/sdk.md>)

Tags: [bazel](<https://devfeed.tech/tags/bazel.md>), [cache](<https://devfeed.tech/tags/cache.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [cycles](<https://devfeed.tech/tags/cycles.md>), [ios](<https://devfeed.tech/tags/ios.md>), [macos](<https://devfeed.tech/tags/macos.md>), [sdk](<https://devfeed.tech/tags/sdk.md>), [watchos](<https://devfeed.tech/tags/watchos.md>), [xcode](<https://devfeed.tech/tags/xcode.md>)

## AI overview

This article explains how to lock supported Xcode versions in Bazel so team members can share remote build-cache artifacts reliably. It describes replacing Bazel's automatic Xcode discovery with a project-managed configuration and supporting multiple Xcode versions using build numbers.

## Source excerpt

When using bazel on a team, one of the things you quickly want to do is stand up a remote cache. This allows bazel to download build artifacts instead of spending CPU cycles reproducing things that have already been built by someone else. In order for bazel to guarantee that downloading the artifacts instead of building them will produce the same results, it must ensure that all the inputs of your build are the same as a previous build.1 For macOS and iOS builds bazel's inputs include the version of Xcode you're using. This means if developers on your team use different versions of Xcode, they cannot share the same build cache. Bazel discovers your currently installed Xcode versions by running xcode_locator, and then generating a BUILD file that contains an entry for every version you currently have installed. The result looks something like this:2 load("@apple_support//xcode:xcode_config.bzl", "xcode_config") load("@apple_support//xcode:xcode_version.bzl", "xcode_version") xcode_version( name = "version12_4_0_12D4e", version = "12.4.0.12D4e", aliases = ["12.4.0", "12.4", "12.4.0.12D4e"], default_ios_sdk_version = "14.4", default_tvos_sdk_version = "14.3", default_macos_sdk_version = "11.1", default_watchos_sdk_version = "7.2", ) xcode_version( name = "version12_2_0_12B45b", version = "12.2.0.12B45b", aliases = ["12.2.0", "12", "12.2", "12.2.0.12B45b"], default_ios_sdk_version = "14.2", default_tvos_sdk_version = "14.2", default_macos_sdk_version = "11.0", default_watchos_sdk_version = "7.1", ) xcode_config( name = "host_xcodes", versions = [":version12_4_0_12D4e", ":version12_2_0_12B45b"], default = ":version12_4_0_12D4e", ) To fetch the contents of this file on your machine you can run: cat bazel-$(basename $PWD)/external/local_config_xcode/BUILD In order to enforce developers use the same version, you can short circuit bazel's Xcode discovery and instead reference a local target that you provide.3 To do this, you can setup your target in the BUILD file at the roo