@@ -11,6 +11,7 @@ load("@rules_cc//cc:find_cc_toolchain.bzl", "use_cc_toolchain")
1111load ("@rules_cc//cc/common:cc_info.bzl" , "CcInfo" )
1212load ("//bazel/common:proto_common.bzl" , "proto_common" )
1313load ("//bazel/common:proto_info.bzl" , "ProtoInfo" )
14+ load ("//bazel/flags:flags.bzl" , "get_flag_value" )
1415load ("//bazel/private:cc_proto_support.bzl" , "cc_proto_compile_and_link" )
1516load ("//bazel/private:toolchain_helpers.bzl" , "toolchains" )
1617
@@ -48,25 +49,24 @@ def _get_strip_include_prefix(ctx, proto_info):
4849
4950def _aspect_impl (target , ctx ):
5051 proto_info = target [ProtoInfo ]
51- proto_configuration = ctx .fragments .proto
5252
5353 sources = []
5454 headers = []
5555 textual_hdrs = []
5656
57- proto_toolchain = toolchains .find_toolchain (ctx , "_aspect_cc_proto_toolchain " , _CC_PROTO_TOOLCHAIN )
57+ proto_toolchain = toolchains .find_toolchain (ctx , "proto_toolchain_for_cc " , _CC_PROTO_TOOLCHAIN )
5858 should_generate_code = proto_common .experimental_should_generate_code (proto_info , proto_toolchain , "cc_proto_library" , target .label )
5959
6060 if should_generate_code :
6161 if len (proto_info .direct_sources ) != 0 :
6262 # Bazel 7 didn't expose cc_proto_library_source_suffixes used by Kythe
6363 # gradually falling back to .pb.cc
64- if type (proto_configuration . cc_proto_library_source_suffixes ) == "builtin_function_or_method" :
64+ if type (get_flag_value ( ctx , " cc_proto_library_source_suffixes" ) ) == "builtin_function_or_method" :
6565 source_suffixes = [".pb.cc" ]
6666 header_suffixes = [".pb.h" ]
6767 else :
68- source_suffixes = proto_configuration . cc_proto_library_source_suffixes
69- header_suffixes = proto_configuration . cc_proto_library_header_suffixes
68+ source_suffixes = get_flag_value ( ctx , " cc_proto_library_source_suffixes" )
69+ header_suffixes = get_flag_value ( ctx , " cc_proto_library_header_suffixes" )
7070 sources = _get_output_files (ctx .actions , proto_info , source_suffixes )
7171 headers = _get_output_files (ctx .actions , proto_info , header_suffixes )
7272 header_provider = _ProtoCcHeaderInfo (headers = depset (headers ))
@@ -122,9 +122,22 @@ cc_proto_aspect = aspect(
122122 fragments = ["cpp" , "proto" ],
123123 required_providers = [ProtoInfo ],
124124 provides = [CcInfo ],
125- attrs = toolchains .if_legacy_toolchain ({"_aspect_cc_proto_toolchain" : attr .label (
126- default = configuration_field (fragment = "proto" , name = "proto_toolchain_for_cc" ),
127- )}),
125+ attrs = {
126+ "_cc_proto_library_header_suffixes" : attr .label (
127+ default = "//bazel/flags/cc:cc_proto_library_header_suffixes" ,
128+ ),
129+ "_cc_proto_library_source_suffixes" : attr .label (
130+ default = "//bazel/flags/cc:cc_proto_library_source_suffixes" ,
131+ ),
132+ } |
133+ toolchains .if_legacy_toolchain ({
134+ "_aspect_cc_proto_toolchain" : attr .label (
135+ default = configuration_field (fragment = "proto" , name = "proto_toolchain_for_cc" ),
136+ ),
137+ "_proto_toolchain_for_cc" : attr .label (
138+ default = Label ("//bazel/flags/cc:proto_toolchain_for_cc" ),
139+ ),
140+ }),
128141 toolchains = use_cc_toolchain () + toolchains .use_toolchain (_CC_PROTO_TOOLCHAIN ),
129142)
130143
@@ -140,7 +153,7 @@ def _cc_proto_library_impl(ctx):
140153 )
141154 dep = ctx .attr .deps [0 ]
142155
143- proto_toolchain = toolchains .find_toolchain (ctx , "_aspect_cc_proto_toolchain " , _CC_PROTO_TOOLCHAIN )
156+ proto_toolchain = toolchains .find_toolchain (ctx , "proto_toolchain_for_cc " , _CC_PROTO_TOOLCHAIN )
144157 proto_common .check_collocated (ctx .label , dep [ProtoInfo ], proto_toolchain )
145158
146159 return [DefaultInfo (files = dep [_ProtoCcFilesInfo ].files ), dep [CcInfo ], dep [OutputGroupInfo ]]
@@ -192,6 +205,9 @@ rules to generate C++ code for.""",
192205 "_aspect_cc_proto_toolchain" : attr .label (
193206 default = configuration_field (fragment = "proto" , name = "proto_toolchain_for_cc" ),
194207 ),
208+ "_proto_toolchain_for_cc" : attr .label (
209+ default = "//bazel/flags/cc:proto_toolchain_for_cc" ,
210+ ),
195211 }),
196212 provides = [CcInfo ],
197213 toolchains = toolchains .use_toolchain (_CC_PROTO_TOOLCHAIN ),
0 commit comments