From f4bcd6ee8e6be7dd76e8b24a4aceff8272746f4f Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Wed, 25 Mar 2026 13:09:17 -0700 Subject: [PATCH 1/2] Set target_libc to macosx for Apple platforms This is read by the legacy features logic to determine how to pass Apple specific flags. Theoretically this is readable by anyone as well, similar to the other ones, but I don't think it's widely used. --- cc/toolchains/impl/toolchain_config.bzl | 3 ++- cc/toolchains/toolchain.bzl | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cc/toolchains/impl/toolchain_config.bzl b/cc/toolchains/impl/toolchain_config.bzl index 4300c1db8..69e0b6720 100644 --- a/cc/toolchains/impl/toolchain_config.bzl +++ b/cc/toolchains/impl/toolchain_config.bzl @@ -95,9 +95,9 @@ def cc_toolchain_config_impl_helper(ctx): # compiler compiler = ctx.attr.compiler, target_cpu = ctx.attr.cpu, + target_libc = ctx.attr.target_libc, # Used by legacy features to determine if we're building for Apple platfroms or not target_system_name = ctx.expand_make_variables("target_system_name", ctx.attr.target_system_name, {}), # These fields are only relevant for legacy toolchain resolution. - target_libc = "", abi_version = "", abi_libc_version = "", ), @@ -120,6 +120,7 @@ CC_TOOLCHAIN_CONFIG_PUBLIC_ATTRS = { # Attributes new to this rule. "compiler": attr.string(default = ""), "cpu": attr.string(default = ""), + "target_libc": attr.string(default = ""), "target_system_name": attr.string(default = ""), "tool_map": attr.label(providers = [ToolConfigInfo], mandatory = True), "args": attr.label_list(providers = [ArgsListInfo]), diff --git a/cc/toolchains/toolchain.bzl b/cc/toolchains/toolchain.bzl index 06603b644..b8d91deac 100644 --- a/cc/toolchains/toolchain.bzl +++ b/cc/toolchains/toolchain.bzl @@ -163,6 +163,11 @@ def cc_toolchain( "//conditions:default": "", }) + target_libc = select({ + Label("//cc/settings:apple_constraint"): "macosx", + "//conditions:default": "", + }) + if bazel_features.cc.supports_starlarkified_toolchains: _cc_toolchain( name = name, @@ -174,6 +179,7 @@ def cc_toolchain( enabled_features = enabled_features, compiler = compiler, cpu = _CPU, + target_libc = target_libc, target_system_name = target_system_name, dynamic_runtime_lib = dynamic_runtime_lib, libc_top = libc_top, @@ -202,6 +208,7 @@ def cc_toolchain( enabled_features = enabled_features, compiler = compiler, cpu = _CPU, + target_libc = target_libc, target_system_name = target_system_name, visibility = ["//visibility:private"], **kwargs From f95dd156f3ac450b676a9458895e87fad61529a7 Mon Sep 17 00:00:00 2001 From: Lily Gorsheneva Date: Tue, 12 May 2026 12:20:31 -0600 Subject: [PATCH 2/2] Update toolchain.bzl fix previous merge --- cc/toolchains/toolchain.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cc/toolchains/toolchain.bzl b/cc/toolchains/toolchain.bzl index 32d4f2220..6637d4481 100644 --- a/cc/toolchains/toolchain.bzl +++ b/cc/toolchains/toolchain.bzl @@ -213,7 +213,7 @@ def cc_toolchain( known_features = known_features, enabled_features = enabled_features, compiler = compiler, - cpu = _CPU, + cpu = cpu or _CPU, target_libc = target_libc, target_system_name = target_system_name, visibility = ["//visibility:private"],