Add an example of malloc/custom_malloc attrs for cc_api_rules
With a comment that notes that exposing the --custom_malloc flag is just for when you need to match the behavior of native.cc_binary.
RELNOTES: None.
@@ -131,6 +131,9 @@ def _cc_bin_impl(ctx):
for user_link_flag in ctx.attr.user_link_flags:
user_link_flags.append(ctx.expand_location(user_link_flag, targets = ctx.attr.additional_linker_inputs))
+ malloc = ctx.attr._custom_malloc or ctx.attr.malloc
+ linking_contexts.append(malloc[CcInfo].linking_context)
+
linking_outputs = cc_common.link(
name = ctx.label.name,
actions = ctx.actions,
@@ -179,6 +182,19 @@ cc_bin = rule(
"linkstatic": attr.bool(default = True),
"linkshared": attr.bool(default = False),
"stamp": attr.int(default = -1),
+ "malloc": attr.label(
+ default = "@bazel_tools//tools/cpp:malloc",
+ providers = [CcInfo],
+ ),
+ # Exposes --custom_malloc flag, if you really need behavior to match
+ # native.cc_binary and have that override the malloc attr.
+ "_custom_malloc": attr.label(
+ default = configuration_field(
+ fragment = "cpp",
+ name = "custom_malloc",
+ ),
+ providers = [CcInfo],
+ ),
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"),
},
fragments = ["cpp"],
