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

Add additional_linker_inputs option to cc_library rule #18952

Closed
wants to merge 1 commit into from
Closed
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 @@ -310,6 +310,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 @@ -487,18 +499,6 @@ public static final class CcBinaryBaseRule implements RuleDefinition {
@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 @@ -148,7 +148,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 = cc_helper.linkopts(ctx, additional_make_variable_substitutions, cc_toolchain),
Expand Down Expand Up @@ -206,11 +206,12 @@ def _cc_library_impl(ctx):
else:
user_link_flags = cc_helper.linkopts(ctx, additional_make_variable_substitutions, cc_toolchain)
linker_scripts = _filter_linker_scripts(ctx.files.deps)
if len(user_link_flags) > 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(
nicholasjng marked this conversation as resolved.
Show resolved Hide resolved
owner = ctx.label,
user_link_flags = user_link_flags,
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 @@ -575,6 +576,10 @@ attrs = {
),
"linkstamp": attr.label(allow_single_file = True),
"linkopts": attr.string_list(),
"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
Loading