diff --git a/cc/private/toolchain/cc_configure.bzl b/cc/private/toolchain/cc_configure.bzl index e232423c4..1d5314489 100644 --- a/cc/private/toolchain/cc_configure.bzl +++ b/cc/private/toolchain/cc_configure.bzl @@ -21,18 +21,20 @@ load( load(":unix_cc_configure.bzl", "configure_unix_toolchain") load(":windows_cc_configure.bzl", "configure_windows_toolchain") +def _should_disable_toolchain(repository_ctx): + """Returns true if the toolchain should be disabled based on environment variables.""" + env = repository_ctx.os.environ + disabled_via_env = "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN" in env and env["BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN"] == "1" + macos_legacy_support = env.get("BAZEL_USE_LEGACY_MACOS_TOOLCHAIN", "1") == "1" + return disabled_via_env or (repository_ctx.os.name.startswith("mac os") and not macos_legacy_support) + def cc_autoconf_toolchains_impl(repository_ctx): """Generate BUILD file with 'toolchain' targets for the local host C++ toolchain. Args: repository_ctx: repository context """ - env = repository_ctx.os.environ - - # Should we try to find C++ toolchain at all? If not, we don't have to generate toolchains for C++ at all. - should_detect_cpp_toolchain = "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN" not in env or env["BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN"] != "1" - - if should_detect_cpp_toolchain: + if not _should_disable_toolchain(repository_ctx): if repository_ctx.os.name.lower().find("windows") != -1: build_path = "@rules_cc//cc/private/toolchain:BUILD.windows_toolchains.tpl" else: @@ -47,11 +49,12 @@ def cc_autoconf_toolchains_impl(repository_ctx): {"%{name}": get_cpu_value(repository_ctx)}, ) else: - repository_ctx.file("BUILD", "# C++ toolchain autoconfiguration was disabled by BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN env variable.") + repository_ctx.file("BUILD", "# C++ toolchain autoconfiguration was disabled by BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 or BAZEL_USE_LEGACY_MACOS_TOOLCHAIN=0.") cc_autoconf_toolchains = repository_rule( environ = [ "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN", + "BAZEL_USE_LEGACY_MACOS_TOOLCHAIN", ], implementation = cc_autoconf_toolchains_impl, configure = True, @@ -64,10 +67,8 @@ def cc_autoconf_impl(repository_ctx, overriden_tools = dict()): repository_ctx: repository context overriden_tools: dict of tool paths to use instead of autoconfigured tools """ - - env = repository_ctx.os.environ cpu_value = get_cpu_value(repository_ctx) - if "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN" in env and env["BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN"] == "1": + if _should_disable_toolchain(repository_ctx): paths = resolve_labels(repository_ctx, [ "@rules_cc//cc/private/toolchain:BUILD.empty.tpl", "@rules_cc//cc/private/toolchain:empty_cc_toolchain_config.bzl", @@ -130,6 +131,7 @@ cc_autoconf = repository_rule( "BAZEL_TARGET_LIBC", "BAZEL_TARGET_SYSTEM", "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN", + "BAZEL_USE_LEGACY_MACOS_TOOLCHAIN", "BAZEL_USE_LLVM_NATIVE_COVERAGE", "BAZEL_WIN32_WINNT", "BAZEL_LLVM",