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.3.0] Add additional_compiler_inputs attribute for cc_library. #18882

Merged
Changes from 1 commit
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
Next Next commit
Add additional_compiler_inputs attribute for cc_library.
Also, ensure that location function expansion works with these inputs as
expected.

RELNOTES: Additional source inputs can now be specified for compilation in cc_library targets using the additional_compiler_inputs attribute, and these inputs can be used in the $(location) function.

Fixes #18766.

PiperOrigin-RevId: 545766084
Change-Id: I2d9f195d81a1358c696601873e60d3cad810a150
(cherry picked from commit ade32e6)
Signed-off-by: Brentley Jones <[email protected]>
brentleyjones committed Jul 10, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
addaleax Anna Henningsen
commit 993b2068f0ae7bf824d7310078ae866dd7979ccc
Original file line number Diff line number Diff line change
@@ -63,6 +63,12 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
attr("implementation_deps", LABEL_LIST)
.allowedFileTypes(FileTypeSet.NO_FILE)
.mandatoryProviders(CcInfo.PROVIDER.id()))
/*<!-- #BLAZE_RULE(cc_library).ATTRIBUTE(additional_compiler_inputs) -->
Any additional files you might want to pass to the compiler command line, such as sanitizer
ignorelists, for example. Files specified here can then be used in copts with the
$(location) function.
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(attr("additional_compiler_inputs", LABEL_LIST).allowedFileTypes(FileTypeSet.ANY_FILE))
.advertiseStarlarkProvider(CcInfo.PROVIDER.id())
.build();
}
7 changes: 5 additions & 2 deletions src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl
Original file line number Diff line number Diff line change
@@ -868,16 +868,19 @@ def _expand_single_make_variable(ctx, token, additional_make_variable_substituti

def _expand_make_variables_for_copts(ctx, tokenization, unexpanded_tokens, additional_make_variable_substitutions):
tokens = []
targets = []
for additional_compiler_input in getattr(ctx.attr, "additional_compiler_inputs", []):
targets.append(additional_compiler_input)
for token in unexpanded_tokens:
if tokenization:
expanded_token = _expand(ctx, token, additional_make_variable_substitutions)
expanded_token = _expand(ctx, token, additional_make_variable_substitutions, targets = targets)
_tokenize(tokens, expanded_token)
else:
exp = _expand_single_make_variable(ctx, token, additional_make_variable_substitutions)
if exp != None:
_tokenize(tokens, exp)
else:
tokens.append(_expand(ctx, token, additional_make_variable_substitutions))
tokens.append(_expand(ctx, token, additional_make_variable_substitutions, targets = targets))
return tokens

def _get_copts(ctx, common, feature_configuration, additional_make_variable_substitutions):
5 changes: 5 additions & 0 deletions src/main/starlark/builtins_bzl/common/cc/cc_library.bzl
Original file line number Diff line number Diff line change
@@ -72,6 +72,7 @@ def _cc_library_impl(ctx):
textual_hdrs = ctx.files.textual_hdrs,
include_prefix = ctx.attr.include_prefix,
strip_include_prefix = ctx.attr.strip_include_prefix,
additional_inputs = ctx.files.additional_compiler_inputs,
)

precompiled_objects = cc_common.create_compilation_outputs(
@@ -600,6 +601,10 @@ attrs = {
),
"win_def_file": attr.label(allow_single_file = [".def"]),
"licenses": attr.license() if hasattr(attr, "license") else attr.string_list(),
"additional_compiler_inputs": attr.label_list(
allow_files = True,
flags = ["ORDER_INDEPENDENT", "DIRECT_COMPILE_TIME_INPUT"],
),
"_stl": semantics.get_stl(),
"_grep_includes": attr.label(
allow_files = True,
Loading