Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.4.0] Add additional_linker_inputs option to cc_library rule #19264

Merged
merged 3 commits into from
Aug 22, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,18 @@ public RuleClass build(RuleClass.Builder builder, final RuleDefinitionEnvironmen
</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(attr("linkopts", STRING_LIST))
/*<!-- #BLAZE_RULE($cc_rule).ATTRIBUTE(additional_linker_inputs) -->
Pass these files to the C++ linker command.
<p>
For example, compiled Windows .res files can be provided here to be embedded in
the binary target.
</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(
attr("additional_linker_inputs", LABEL_LIST)
.orderIndependent()
.direct_compile_time_input()
.allowedFileTypes(FileTypeSet.ANY_FILE))
/*<!-- #BLAZE_RULE($cc_rule).ATTRIBUTE(nocopts) -->
Remove matching options from the C++ compilation command.
Subject to <a href="${link make-variables}">"Make" variable</a> substitution.
Expand Down Expand Up @@ -496,18 +508,6 @@ public CcBinaryBaseRule(GraphNodeAspect graphNodeAspect) {
@Override
public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
return builder
/*<!-- #BLAZE_RULE($cc_binary_base).ATTRIBUTE(additional_linker_inputs) -->
Pass these files to the C++ linker command.
<p>
For example, compiled Windows .res files can be provided here to be embedded in
the binary target.
</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(
attr("additional_linker_inputs", LABEL_LIST)
.orderIndependent()
.direct_compile_time_input()
.allowedFileTypes(FileTypeSet.ANY_FILE))
.override(
attr("deps", LABEL_LIST)
.allowedRuleClasses(DEPS_ALLOWED_RULES)
Expand Down
11 changes: 8 additions & 3 deletions src/main/starlark/builtins_bzl/common/cc/cc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _cc_library_impl(ctx):
compilation_outputs = compilation_outputs,
cc_toolchain = cc_toolchain,
feature_configuration = feature_configuration,
additional_inputs = _filter_linker_scripts(ctx.files.deps),
additional_inputs = _filter_linker_scripts(ctx.files.deps) + ctx.files.additional_linker_inputs,
linking_contexts = linking_contexts,
grep_includes = ctx.executable._grep_includes,
user_link_flags = common.linkopts,
Expand Down Expand Up @@ -209,11 +209,12 @@ def _cc_library_impl(ctx):
else:
user_link_flags = common.linkopts
linker_scripts = _filter_linker_scripts(ctx.files.deps)
if len(common.linkopts) > 0 or len(linker_scripts) > 0 or not semantics.should_create_empty_archive():
additional_linker_inputs = ctx.files.additional_linker_inputs
if len(user_link_flags) > 0 or len(linker_scripts) > 0 or len(additional_linker_inputs) > 0 or not semantics.should_create_empty_archive():
linker_input = cc_common.create_linker_input(
owner = ctx.label,
user_link_flags = common.linkopts,
additional_inputs = depset(linker_scripts),
additional_inputs = depset(linker_scripts + additional_linker_inputs),
)
contexts_to_merge.append(cc_common.create_linking_context(linker_inputs = depset([linker_input])))

Expand Down Expand Up @@ -583,6 +584,10 @@ attrs = {
"linkstamp": attr.label(allow_single_file = True),
"linkopts": attr.string_list(),
"nocopts": attr.string(),
"additional_linker_inputs": attr.label_list(
allow_files = True,
flags = ["ORDER_INDEPENDENT", "DIRECT_COMPILE_TIME_INPUT"],
),
"includes": attr.string_list(),
"defines": attr.string_list(),
"copts": attr.string_list(),
Expand Down