Skip to content

Commit

Permalink
Removed Rust-specific "thunks" logic from upb_c_proto_library().
Browse files Browse the repository at this point in the history
Rust no longer uses these thunks, so we can remove this special-case code.

PiperOrigin-RevId: 671014796
  • Loading branch information
haberman authored and copybara-github committed Sep 4, 2024
1 parent 58259db commit 89d5822
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 44 deletions.
49 changes: 6 additions & 43 deletions bazel/private/upb_proto_library_internal/aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ GeneratedSrcsInfo = provider(
fields = {
"srcs": "list of srcs",
"hdrs": "list of hdrs",
"thunks": "Experimental, do not use. List of srcs defining C API. Incompatible with hdrs.",
},
)

Expand Down Expand Up @@ -47,7 +46,6 @@ def _merge_generated_srcs(srcs):
return GeneratedSrcsInfo(
srcs = _concat_lists([s.srcs for s in srcs]),
hdrs = _concat_lists([s.hdrs for s in srcs]),
thunks = _concat_lists([s.thunks for s in srcs]),
)

def _get_implicit_weak_field_sources(ctx, proto_info):
Expand Down Expand Up @@ -96,11 +94,10 @@ def _get_feature_configuration(ctx, cc_toolchain, proto_info):

def _generate_srcs_list(ctx, generator, proto_info):
if len(proto_info.direct_sources) == 0:
return GeneratedSrcsInfo(srcs = [], hdrs = [], thunks = [], includes = [])
return GeneratedSrcsInfo(srcs = [], hdrs = [], includes = [])

ext = "." + generator
srcs = []
thunks = []
hdrs = proto_common.declare_generated_files(
ctx.actions,
extension = ext + ".h",
Expand All @@ -115,27 +112,10 @@ def _generate_srcs_list(ctx, generator, proto_info):
extension = ext + ".c",
proto_info = proto_info,
)
if generator == "upb":
thunks = proto_common.declare_generated_files(
ctx.actions,
extension = ext + ".thunks.c",
proto_info = proto_info,
)
ctx.actions.run_shell(
inputs = hdrs,
outputs = thunks,
command = " && ".join([
"sed 's/UPB_INLINE //' {} > {}".format(hdr.path, thunk.path)
for (hdr, thunk) in zip(hdrs, thunks)
]),
progress_message = "Generating thunks for upb protos API for: " + ctx.label.name,
mnemonic = "GenUpbProtosThunks",
)

return GeneratedSrcsInfo(
srcs = srcs,
hdrs = hdrs,
thunks = thunks,
)

def _generate_upb_protos(ctx, generator, proto_info, feature_configuration):
Expand All @@ -162,9 +142,7 @@ def _generate_upb_protos(ctx, generator, proto_info, feature_configuration):

return srcs

def _generate_name(ctx, generator, thunks = False):
if thunks:
return ctx.rule.attr.name + "." + generator + ".thunks"
def _generate_name(ctx, generator):
return ctx.rule.attr.name + "." + generator

def _get_dep_cc_infos(target, ctx, generator, cc_provider, dep_cc_provider):
Expand Down Expand Up @@ -195,24 +173,9 @@ def _compile_upb_protos(ctx, files, generator, dep_ccinfos, cc_provider, proto_i
dep_ccinfos = dep_ccinfos,
)

if files.thunks:
cc_info_with_thunks = cc_library_func(
ctx = ctx,
name = _generate_name(ctx, generator, files.thunks),
hdrs = [],
srcs = files.thunks,
includes = [output_dir(ctx, proto_info)],
copts = ctx.attr._copts[UpbProtoLibraryCoptsInfo].copts,
dep_ccinfos = dep_ccinfos + [cc_info],
)
return cc_provider(
cc_info = cc_info,
cc_info_with_thunks = cc_info_with_thunks,
)
else:
return cc_provider(
cc_info = cc_info,
)
return cc_provider(
cc_info = cc_info,
)

_GENERATORS = ["upb", "upbdefs", "upb_minitable"]

Expand All @@ -223,7 +186,7 @@ def _get_hint_providers(ctx, 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)))
possible_owners.append(ctx.label.relative(_generate_name(ctx, generator)))

if hasattr(cc_common, "CcSharedLibraryHintInfo"):
return [cc_common.CcSharedLibraryHintInfo(owners = possible_owners)]
Expand Down
2 changes: 1 addition & 1 deletion bazel/upb_c_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ load("//bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl

UpbWrappedCcInfo = provider(
"Provider for cc_info for protos",
fields = ["cc_info", "cc_info_with_thunks"],
fields = ["cc_info"],
)

_UpbWrappedGeneratedSrcsInfo = provider(
Expand Down

0 comments on commit 89d5822

Please sign in to comment.