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
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 @@ -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();
}
Expand Down
16 changes: 9 additions & 7 deletions src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -706,16 +706,15 @@ def _get_cc_flags_make_variable(ctx, common, cc_toolchain):
cc_flags.extend(feature_config_cc_flags)
return {"CC_FLAGS": " ".join(cc_flags)}

def _expand_nested_variable(ctx, additional_vars, exp, execpath = True):
def _expand_nested_variable(ctx, additional_vars, exp, execpath = True, targets = []):
# If make variable is predefined path variable(like $(location ...))
# we will expand it first.
if exp.find(" ") != -1:
if not execpath:
if exp.startswith("location"):
exp = exp.replace("location", "rootpath", 1)
targets = []
if ctx.attr.data != None:
targets = ctx.attr.data
targets.extend(ctx.attr.data)
return ctx.expand_location("$({})".format(exp), targets = targets)

# Recursively expand nested make variables, but since there is no recursion
Expand All @@ -739,7 +738,7 @@ def _expand_nested_variable(ctx, additional_vars, exp, execpath = True):
fail("potentially unbounded recursion during expansion of {}".format(exp))
return exp

def _expand(ctx, expression, additional_make_variable_substitutions, execpath = True):
def _expand(ctx, expression, additional_make_variable_substitutions, execpath = True, targets = []):
idx = 0
last_make_var_end = 0
result = []
Expand Down Expand Up @@ -781,7 +780,7 @@ def _expand(ctx, expression, additional_make_variable_substitutions, execpath =
# last_make_var_end make_var_start make_var_end
result.append(expression[last_make_var_end:make_var_start - 1])
make_var = expression[make_var_start + 1:make_var_end]
exp = _expand_nested_variable(ctx, additional_make_variable_substitutions, make_var, execpath)
exp = _expand_nested_variable(ctx, additional_make_variable_substitutions, make_var, execpath, targets)
result.append(exp)

# Update indexes.
Expand Down Expand Up @@ -868,16 +867,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):
Expand Down
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
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
Loading