Fix support for cc_shared_library in upb_proto_library.

PiperOrigin-RevId: 546851795
pull/13171/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent f1ec35071b
commit 09c19b8e1a
  1. 28
      bazel/upb_proto_library.bzl

@ -283,10 +283,12 @@ def _upb_proto_rule_impl(ctx):
cc_info, cc_info,
] ]
def _upb_proto_aspect_impl(target, ctx, generator, cc_provider, file_provider, provide_cc_shared_library_hints = True): def _generate_name(ctx, generator, thunks = False):
name = ctx.rule.attr.name + "." + generator if thunks:
owners = [ctx.label.relative(name)] return ctx.rule.attr.name + "." + generator + ".thunks"
return ctx.rule.attr.name + "." + generator
def _upb_proto_aspect_impl(target, ctx, generator, cc_provider, file_provider, provide_cc_shared_library_hints = True):
providers = [] providers = []
if not getattr(ctx.rule.attr, "srcs", []): if not getattr(ctx.rule.attr, "srcs", []):
# This target doesn't declare any sources, reexport all its deps instead. # This target doesn't declare any sources, reexport all its deps instead.
@ -340,7 +342,7 @@ def _upb_proto_aspect_impl(target, ctx, generator, cc_provider, file_provider, p
cc_info = _cc_library_func( cc_info = _cc_library_func(
ctx = ctx, ctx = ctx,
name = name, name = _generate_name(ctx, generator),
hdrs = files.hdrs, hdrs = files.hdrs,
srcs = files.srcs, srcs = files.srcs,
includes = files.includes, includes = files.includes,
@ -349,11 +351,9 @@ def _upb_proto_aspect_impl(target, ctx, generator, cc_provider, file_provider, p
) )
if files.thunks: if files.thunks:
name_thunks = ctx.rule.attr.name + "." + generator + ".thunks"
owners.append(ctx.label.relative(name_thunks))
cc_info_with_thunks = _cc_library_func( cc_info_with_thunks = _cc_library_func(
ctx = ctx, ctx = ctx,
name = name_thunks, name = _generate_name(ctx, generator, files.thunks),
hdrs = [], hdrs = [],
srcs = files.thunks, srcs = files.thunks,
includes = files.includes, includes = files.includes,
@ -373,14 +373,24 @@ def _upb_proto_aspect_impl(target, ctx, generator, cc_provider, file_provider, p
file_provider(srcs = files), file_provider(srcs = files),
] ]
if generator not in _GENERATORS:
fail("Please add new generator '{}' to _GENERATORS list".format(generator))
possible_owners = []
for generator in _GENERATORS:
possible_owners.append(ctx.label.relative(_generate_name(ctx, generator)))
possible_owners.append(ctx.label.relative(_generate_name(ctx, generator, thunks = True)))
if provide_cc_shared_library_hints: if provide_cc_shared_library_hints:
if hasattr(cc_common, "CcSharedLibraryHintInfo"): if hasattr(cc_common, "CcSharedLibraryHintInfo"):
providers.append(cc_common.CcSharedLibraryHintInfo(owners = owners)) providers.append(cc_common.CcSharedLibraryHintInfo(owners = possible_owners))
elif hasattr(cc_common, "CcSharedLibraryHintInfo_6_X_constructor_do_not_use"): elif hasattr(cc_common, "CcSharedLibraryHintInfo_6_X_constructor_do_not_use"):
# This branch can be deleted once 6.X is not supported by upb rules # This branch can be deleted once 6.X is not supported by upb rules
providers.append(cc_common.CcSharedLibraryHintInfo_6_X_constructor_do_not_use(owners = owners)) providers.append(cc_common.CcSharedLibraryHintInfo_6_X_constructor_do_not_use(owners = possible_owners))
return providers return providers
_GENERATORS = ["upb", "upbdefs"]
def upb_proto_library_aspect_impl(target, ctx): def upb_proto_library_aspect_impl(target, ctx):
return _upb_proto_aspect_impl(target, ctx, "upb", UpbWrappedCcInfo, _UpbWrappedGeneratedSrcsInfo) return _upb_proto_aspect_impl(target, ctx, "upb", UpbWrappedCcInfo, _UpbWrappedGeneratedSrcsInfo)

Loading…
Cancel
Save