Use C++-only toolchain on darwin when BAZEL_USE_CPP_ONLY_TOOLCHAIN env var is set to "1"
By default when xcode is installed on darwin bazel will pick a toolchain that
supports both C++ and ObjC. This cl allows the user to pick C++ only
toolchain even when Xcode is installed.
Fixes #4231.
RELNOTES: None.
PiperOrigin-RevId: 178745218
diff --git a/tools/cpp/cc_configure.bzl b/tools/cpp/cc_configure.bzl
index 9d6d29f..b14b00e 100644
--- a/tools/cpp/cc_configure.bzl
+++ b/tools/cpp/cc_configure.bzl
@@ -22,6 +22,7 @@
def _impl(repository_ctx):
repository_ctx.symlink(
Label("@bazel_tools//tools/cpp:dummy_toolchain.bzl"), "dummy_toolchain.bzl")
+ env = repository_ctx.os.environ
cpu_value = get_cpu_value(repository_ctx)
if cpu_value == "freebsd":
# This is defaulting to the static crosstool, we should eventually
@@ -32,7 +33,8 @@
repository_ctx.symlink(Label("@bazel_tools//tools/cpp:BUILD.static"), "BUILD")
elif cpu_value == "x64_windows":
configure_windows_toolchain(repository_ctx)
- elif cpu_value == "darwin":
+ elif (cpu_value == "darwin" and
+ ("BAZEL_USE_CPP_ONLY_TOOLCHAIN" not in env or env["BAZEL_USE_CPP_ONLY_TOOLCHAIN"] != "1")):
configure_osx_toolchain(repository_ctx)
else:
configure_unix_toolchain(repository_ctx, cpu_value)
@@ -50,6 +52,7 @@
"BAZEL_TARGET_CPU",
"BAZEL_TARGET_LIBC",
"BAZEL_TARGET_SYSTEM",
+ "BAZEL_USE_CPP_ONLY_TOOLCHAIN",
"BAZEL_VC",
"BAZEL_VS",
"CC",