Skip to content

Commit 5b81ce5

Browse files
Googlerbrentleyjones
authored andcommitted
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)
1 parent 273d3f7 commit 5b81ce5

File tree

4 files changed

+114
-85
lines changed

4 files changed

+114
-85
lines changed

src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcLibraryRule.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
6363
attr("implementation_deps", LABEL_LIST)
6464
.allowedFileTypes(FileTypeSet.NO_FILE)
6565
.mandatoryProviders(CcInfo.PROVIDER.id()))
66+
/*<!-- #BLAZE_RULE(cc_library).ATTRIBUTE(additional_compiler_inputs) -->
67+
Any additional files you might want to pass to the compiler command line, such as sanitizer
68+
ignorelists, for example. Files specified here can then be used in copts with the
69+
$(location) function.
70+
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
71+
.add(attr("additional_compiler_inputs", LABEL_LIST).allowedFileTypes(FileTypeSet.ANY_FILE))
6672
.advertiseStarlarkProvider(CcInfo.PROVIDER.id())
6773
.build();
6874
}

src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,16 +868,19 @@ def _expand_single_make_variable(ctx, token, additional_make_variable_substituti
868868

869869
def _expand_make_variables_for_copts(ctx, tokenization, unexpanded_tokens, additional_make_variable_substitutions):
870870
tokens = []
871+
targets = []
872+
for additional_compiler_input in getattr(ctx.attr, "additional_compiler_inputs", []):
873+
targets.append(additional_compiler_input)
871874
for token in unexpanded_tokens:
872875
if tokenization:
873-
expanded_token = _expand(ctx, token, additional_make_variable_substitutions)
876+
expanded_token = _expand(ctx, token, additional_make_variable_substitutions, targets = targets)
874877
_tokenize(tokens, expanded_token)
875878
else:
876879
exp = _expand_single_make_variable(ctx, token, additional_make_variable_substitutions)
877880
if exp != None:
878881
_tokenize(tokens, exp)
879882
else:
880-
tokens.append(_expand(ctx, token, additional_make_variable_substitutions))
883+
tokens.append(_expand(ctx, token, additional_make_variable_substitutions, targets = targets))
881884
return tokens
882885

883886
def _get_copts(ctx, common, feature_configuration, additional_make_variable_substitutions):

src/main/starlark/builtins_bzl/common/cc/cc_library.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def _cc_library_impl(ctx):
7272
textual_hdrs = ctx.files.textual_hdrs,
7373
include_prefix = ctx.attr.include_prefix,
7474
strip_include_prefix = ctx.attr.strip_include_prefix,
75+
additional_inputs = ctx.files.additional_compiler_inputs,
7576
)
7677

7778
precompiled_objects = cc_common.create_compilation_outputs(
@@ -600,6 +601,10 @@ attrs = {
600601
),
601602
"win_def_file": attr.label(allow_single_file = [".def"]),
602603
"licenses": attr.license() if hasattr(attr, "license") else attr.string_list(),
604+
"additional_compiler_inputs": attr.label_list(
605+
allow_files = True,
606+
flags = ["ORDER_INDEPENDENT", "DIRECT_COMPILE_TIME_INPUT"],
607+
),
603608
"_stl": semantics.get_stl(),
604609
"_grep_includes": attr.label(
605610
allow_files = True,

0 commit comments

Comments
 (0)