Skip to content

Commit

Permalink
feat(build): add kong_cc_static_library to output only static library to
Browse files Browse the repository at this point in the history
link
  • Loading branch information
fffonion committed Sep 11, 2024
1 parent 0dd873c commit 15d9fb7
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions build/build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,39 @@ kong_install = rule(

def get_workspace_name(label):
return label.replace("@", "").split("/")[0]

def _kong_cc_static_library_impl(ctx):
linker_input = ctx.attr.src[CcInfo].linking_context.linker_inputs.to_list()[0]
libs = []
for lib in linker_input.libraries:
libs.append(cc_common.create_library_to_link(
actions = ctx.actions,
# omit dynamic_library and pic_dynamic_library fields
static_library = lib.static_library,
pic_static_library = lib.pic_static_library,
interface_library = lib.interface_library,
alwayslink = lib.alwayslink,
))

cc_info = CcInfo(
compilation_context = ctx.attr.src[CcInfo].compilation_context,
linking_context = cc_common.create_linking_context(
linker_inputs = depset(direct = [
cc_common.create_linker_input(
owner = linker_input.owner,
libraries = depset(libs),
user_link_flags = linker_input.user_link_flags,
),
]),
),
)

return [ctx.attr.src[OutputGroupInfo], cc_info]

kong_cc_static_library = rule(
implementation = _kong_cc_static_library_impl,
doc = "Filter a cc_library target to only output archive (.a) files",
attrs = {
"src": attr.label(allow_files = True, doc = "Label of a cc_library"),
},
)

0 comments on commit 15d9fb7

Please sign in to comment.