From 25152f7f6b8b3052d8636813b4f93cb5568f8be9 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Wed, 10 Jun 2026 16:32:13 -0700 Subject: [PATCH 1/8] Disable macOS toolchain by default Since this toolchain moved out of bazel, and bazel directly depends on apple_support, there's no reason to have a separate toolchain supporting the same platform. On top of that the macOS support in this toolchain isn't fully hermetic, and would require a lot of copy pasting from the apple_support toolchain to get there, for seemingly no benefit. This flips it off by default, with a temporary `--repo_env=BAZEL_USE_LEGACY_MACOS_TOOLCHAIN=1` to keep the existing behavior, but will be removed in a subsequent release. Technically there are flag differences between this and what's in apple_support but apple_support isn't very opinionated so anything major should be fixable. --- cc/private/toolchain/cc_configure.bzl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cc/private/toolchain/cc_configure.bzl b/cc/private/toolchain/cc_configure.bzl index e232423c4..6f8d96af7 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 = "BAZEL_USE_LEGACY_MACOS_TOOLCHAIN" in env and env["BAZEL_USE_LEGACY_MACOS_TOOLCHAIN"] == "1" + return disabled_via_env or (repository_ctx.os.name.startswith("mac os") and 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,7 +49,7 @@ 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 env variable or because you're on macOS, use apple_support instead or set BAZEL_USE_LEGACY_MACOS_TOOLCHAIN=1 temporarily.") cc_autoconf_toolchains = repository_rule( environ = [ @@ -64,10 +66,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", From cdba71f840b27057bc7444c742740683b1d383d0 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Wed, 10 Jun 2026 16:39:22 -0700 Subject: [PATCH 2/8] flip --- cc/private/toolchain/cc_configure.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cc/private/toolchain/cc_configure.bzl b/cc/private/toolchain/cc_configure.bzl index 6f8d96af7..ac3473513 100644 --- a/cc/private/toolchain/cc_configure.bzl +++ b/cc/private/toolchain/cc_configure.bzl @@ -26,7 +26,7 @@ def _should_disable_toolchain(repository_ctx): 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 = "BAZEL_USE_LEGACY_MACOS_TOOLCHAIN" in env and env["BAZEL_USE_LEGACY_MACOS_TOOLCHAIN"] == "1" - return disabled_via_env or (repository_ctx.os.name.startswith("mac os") and macos_legacy_support) + 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. From ef4db8237a49de96f9450af382543356cee7321a Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Wed, 10 Jun 2026 17:03:19 -0700 Subject: [PATCH 3/8] try this for testing --- MODULE.bazel | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MODULE.bazel b/MODULE.bazel index 831b52f0d..6ff2c8716 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -47,6 +47,9 @@ archive_override( bazel_dep(name = "stardoc", version = "0.8.0", dev_dependency = True) +# Here for running basic cc tests on macOS, the behavior of this specific toolchain shouldn't be tested directly +bazel_dep(name = "apple_support", version = "2.6.1", dev_dependency = True) + # Compatibility layer compat = use_extension("//cc:extensions.bzl", "compatibility_proxy") use_repo(compat, "cc_compatibility_proxy") From c0f1e71ac297b3917d569a5abb0d51c00c931bc0 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Wed, 10 Jun 2026 17:39:02 -0700 Subject: [PATCH 4/8] disable nodeps in test --- tests/integration/cc_tests.sh | 2 ++ 1 file changed, 2 insertions(+) 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( From 4f90f6c80459559218e96fcd399c936870f1a908 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 11 Jun 2026 16:50:17 -0700 Subject: [PATCH 5/8] fix more --- tests/integration/test_launcher.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/integration/test_launcher.sh b/tests/integration/test_launcher.sh index 563cc6f1a..096605900 100755 --- a/tests/integration/test_launcher.sh +++ b/tests/integration/test_launcher.sh @@ -59,11 +59,16 @@ cd "$scratch_workspace" cat > MODULE.bazel << EOF module(name = "test_module") +bazel_dep(name = "apple_support", version = "2.6.1") bazel_dep(name = "rules_cc", version = "0.0.0") local_path_override( module_name = "rules_cc", path = "$rules_cc_dir" ) + +cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension") +use_repo(cc_configure, "local_config_cc", "local_config_cc_toolchains") +register_toolchains("@local_config_cc_toolchains//:all") EOF test_runner_path="$(rlocation "$TEST_RUNNER")" || (echo >&2 "FAILED TO LOAD TEST RUNNER" && exit 1) From 3036bbbb8ed03071379f0e305863a68646a0d893 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Tue, 16 Jun 2026 16:37:58 -0700 Subject: [PATCH 6/8] flip default to enabled --- cc/private/toolchain/cc_configure.bzl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cc/private/toolchain/cc_configure.bzl b/cc/private/toolchain/cc_configure.bzl index ac3473513..1d5314489 100644 --- a/cc/private/toolchain/cc_configure.bzl +++ b/cc/private/toolchain/cc_configure.bzl @@ -25,7 +25,7 @@ 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 = "BAZEL_USE_LEGACY_MACOS_TOOLCHAIN" in env and env["BAZEL_USE_LEGACY_MACOS_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): @@ -49,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 or because you're on macOS, use apple_support instead or set BAZEL_USE_LEGACY_MACOS_TOOLCHAIN=1 temporarily.") + 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, @@ -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", From f8eeea64b62e6c22daebcd7dbdabe1a9a1299fa1 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Tue, 16 Jun 2026 16:39:50 -0700 Subject: [PATCH 7/8] drop for now --- MODULE.bazel | 3 --- tests/integration/test_launcher.sh | 5 ----- 2 files changed, 8 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 6ff2c8716..831b52f0d 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -47,9 +47,6 @@ archive_override( bazel_dep(name = "stardoc", version = "0.8.0", dev_dependency = True) -# Here for running basic cc tests on macOS, the behavior of this specific toolchain shouldn't be tested directly -bazel_dep(name = "apple_support", version = "2.6.1", dev_dependency = True) - # Compatibility layer compat = use_extension("//cc:extensions.bzl", "compatibility_proxy") use_repo(compat, "cc_compatibility_proxy") diff --git a/tests/integration/test_launcher.sh b/tests/integration/test_launcher.sh index 096605900..563cc6f1a 100755 --- a/tests/integration/test_launcher.sh +++ b/tests/integration/test_launcher.sh @@ -59,16 +59,11 @@ cd "$scratch_workspace" cat > MODULE.bazel << EOF module(name = "test_module") -bazel_dep(name = "apple_support", version = "2.6.1") bazel_dep(name = "rules_cc", version = "0.0.0") local_path_override( module_name = "rules_cc", path = "$rules_cc_dir" ) - -cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension") -use_repo(cc_configure, "local_config_cc", "local_config_cc_toolchains") -register_toolchains("@local_config_cc_toolchains//:all") EOF test_runner_path="$(rlocation "$TEST_RUNNER")" || (echo >&2 "FAILED TO LOAD TEST RUNNER" && exit 1) From d1df3e0f2058553c041a5403630475adb817f239 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Tue, 16 Jun 2026 16:40:55 -0700 Subject: [PATCH 8/8] revert for now --- tests/integration/cc_tests.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/integration/cc_tests.sh b/tests/integration/cc_tests.sh index 5bd89d06b..f13ad7aa2 100755 --- a/tests/integration/cc_tests.sh +++ b/tests/integration/cc_tests.sh @@ -203,7 +203,6 @@ 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, ) ) @@ -241,7 +240,6 @@ 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(