macos Last updated May 20, 2022

versions- os, sdk, xcode

Because the OCaml compilers may call a compiler (linker/assember), setting these Bazel switches may not be enough to eliminate those pesky "object was built for newer version.." (see below). You may also need to pass some options to the linker using -ccopt (TODO: details)

Locking Xcode versions in Bazel blog post, March 2021

"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…​ 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."

NB: xcode-locator is a Bazel tool, not a macos tool

cat bazel-$(basename $PWD)/external/local_config_xcode/BUILD

To retrieve the build number from your current Xcode version:

xcodebuild -version | tail -1 | cut -d " " -f3

better to use --macos_sdk_version? see below
  • --xcode_version=<a string>

    • If specified, uses Xcode of the given version for relevant build actions. If unspecified, uses the executor default version of Xcode.

  • --xcode_version_config=<a build target label>

    • default: "@bazel_tools//tools/cpp:host_xcodes"

    • The label of the xcode_config rule to be used for selecting the Xcode version in the build configuration.

  • xcrun --sdk macosx --show-sdk-version

  • xcrun --sdk macosx --show-sdk-path

sdk versions

  • --macos_sdk_version=<version>

    • Specifies the version of the macOS SDK to use to build macOS applications. If unspecified, uses default macOS SDK version from 'xcode_version'.

env vars

When using the cc_toolchain (e.g. to build C, C++, objc, …​):

  • SDKROOT

  • DEVELOPER_DIR

  • XCODE_VERSION_OVERRIDE

  • APPLE_SDK_PLATFORM

  • APPLE_SDK_VERSION_OVERRIDE

macos versions

<version> == a dotted version (for example '2.3' or '3.3alpha2.4')> default: see description

  • --host_macos_minimum_os=<version>

    • Minimum compatible macOS version for host targets. If unspecified, uses 'macos_sdk_version'.

  • --macos_minimum_os=<version>

    • Minimum compatible macOS version for targets. If unspecified, uses 'macos_sdk_version'.

warnings

You may see warnings like the following if your code links to external binaries not built by Bazel:

ld: warning: object file (bazel-out/darwin-fastbuild/bin/interop/ffi/case110/cclibs/liblibalpha.a(alpha.o)) was built for newer macOS version (12.3) than being linked (12.0)

In this example, we built a cc_library from source, which evidently was built differently than …​?

Adding build --macos_minimum_os=12.0 to .bazelrc eliminates the warning. Setting the version to 12.3 does not. So evidently there is some binary involved that was built with 12.0, but I have no idea what.

todo

clang wrapper etc