diff --git a/cc/private/toolchain/cc_configure.bzl b/cc/private/toolchain/cc_configure.bzl index 1d5314489..0d5a07827 100644 --- a/cc/private/toolchain/cc_configure.bzl +++ b/cc/private/toolchain/cc_configure.bzl @@ -13,6 +13,7 @@ # limitations under the License. """Rules for configuring the C++ toolchain (experimental).""" +load("@bazel_features//:features.bzl", "bazel_features") load( ":lib_cc_configure.bzl", "get_cpu_value", @@ -24,9 +25,18 @@ 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) + if env.get("BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN") == "1": + return True + + # Keep macOS toolchain before bazel 9.x + if not bazel_features.cc.cc_common_is_in_rules_cc: + return False + + macos_legacy_support = env.get("BAZEL_USE_LEGACY_MACOS_TOOLCHAIN", "0") == "1" + if repository_ctx.os.name.startswith("mac os") and not macos_legacy_support: + return True + + return False def cc_autoconf_toolchains_impl(repository_ctx): """Generate BUILD file with 'toolchain' targets for the local host C++ toolchain. diff --git a/tests/integration/cc_tests.sh b/tests/integration/cc_tests.sh index f13ad7aa2..5bd89d06b 100755 --- a/tests/integration/cc_tests.sh +++ b/tests/integration/cc_tests.sh @@ -203,6 +203,7 @@ def _cc_aspect_impl(target, ctx): feature_configuration = feature_configuration, name = ctx.label.name + "_aspect", cc_toolchain = toolchain, + disallow_dynamic_library = True, compilation_outputs = compilation_outputs, ) ) @@ -240,6 +241,7 @@ def _cc_skylark_library_impl(ctx): feature_configuration=feature_configuration, linking_contexts = dep_linking_contexts, name = ctx.label.name, + disallow_dynamic_library = True, compilation_outputs=compilation_outputs) ) return [CcInfo(