Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cc/private/toolchain/unix_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ load(
)
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
load("@rules_cc//cc/toolchains:cc_toolchain_config_info.bzl", "CcToolchainConfigInfo")
load("@rules_cc//cc/toolchains:feature_injection.bzl", "FeatureInfo", "convert_feature")

def _target_os_version(ctx):
platform_type = ctx.fragments.apple.single_arch_platform.platform_type
Expand Down Expand Up @@ -1950,6 +1951,8 @@ def _impl(ctx):
if symbol_check:
features.append(symbol_check)

features.extend([convert_feature(extra_feature[FeatureInfo]) for extra_feature in ctx.attr.extra_features])

return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
features = features,
Expand Down Expand Up @@ -1985,6 +1988,7 @@ cc_toolchain_config = rule(
"cxx_builtin_include_directories": attr.string_list(),
"cxx_flags": attr.string_list(),
"dbg_compile_flags": attr.string_list(),
"extra_features": attr.label_list(providers = [FeatureInfo], default = []),
"extra_flags_per_feature": attr.string_list_dict(),
"fastbuild_compile_flags": attr.string_list(),
"host_system_name": attr.string(mandatory = True),
Expand Down
7 changes: 6 additions & 1 deletion cc/private/toolchain/windows_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ load(
)
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
load("@rules_cc//cc/toolchains:cc_toolchain_config_info.bzl", "CcToolchainConfigInfo")
load("@rules_cc//cc/toolchains:feature_injection.bzl", "FeatureInfo", "convert_feature")

all_compile_actions = [
ACTION_NAMES.c_compile,
Expand Down Expand Up @@ -1703,9 +1704,12 @@ def _impl(ctx):
],
enabled = True,
)
features.extend([cpp_modules_feature, cpp_module_modmap_file_feature, cpp20_module_compile_flags_feature])
features.extend([convert_feature(extra_feature[FeatureInfo]) for extra_feature in ctx.attr.extra_features])

return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
features = features + [cpp_modules_feature, cpp_module_modmap_file_feature, cpp20_module_compile_flags_feature],
features = features,
action_configs = action_configs,
artifact_name_patterns = artifact_name_patterns,
cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories,
Expand Down Expand Up @@ -1736,6 +1740,7 @@ cc_toolchain_config = rule(
"dbg_mode_debug_flag": attr.string(default = ""),
"default_compile_flags": attr.string_list(default = []),
"default_link_flags": attr.string_list(default = []),
"extra_features": attr.label_list(providers = [FeatureInfo], default = []),
"fastbuild_mode_debug_flag": attr.string(default = ""),
"host_system_name": attr.string(),
"link_flags": attr.string_list(),
Expand Down
20 changes: 20 additions & 0 deletions cc/toolchains/feature_injection.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2026 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Provides necessary tools to inject rules-based features to legacy toolchains"""

load("@rules_cc//cc/toolchains:cc_toolchain_info.bzl", _FeatureInfo = "FeatureInfo")
load("@rules_cc//cc/toolchains/impl:legacy_converter.bzl", _convert_feature = "convert_feature")

convert_feature = _convert_feature
FeatureInfo = _FeatureInfo