Skip to content

Commit 706b41d

Browse files
Googlercopybara-github
authored andcommitted
Add cc_support_deps on additional_rust_srcs_for_crubit_bindings.
PiperOrigin-RevId: 871940500
1 parent 8677b01 commit 706b41d

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

rs_bindings_from_cc/bazel_support/additional_rust_srcs_for_crubit_bindings_aspect_hint.bzl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,16 @@ visibility([
6767
# <internal link> end
6868
])
6969

70-
def make_additional_rust_srcs_provider(srcs, namespace_path, deps, cc_deps):
70+
def make_additional_rust_srcs_provider(srcs, namespace_path, deps, cc_deps, cc_support_deps = []):
7171
return AdditionalRustSrcsProviderInfo(
7272
srcs = srcs,
7373
namespace_path = namespace_path,
7474
deps = _get_additional_rust_deps_variant_info(deps),
7575
cc_deps = _get_additional_cc_deps_variant_info(cc_deps),
76+
cc_support_deps = [
77+
dep[CcInfo]
78+
for dep in cc_support_deps
79+
],
7680
)
7781

7882
def _additional_rust_srcs_for_crubit_bindings_impl(ctx):
@@ -81,6 +85,7 @@ def _additional_rust_srcs_for_crubit_bindings_impl(ctx):
8185
ctx.attr.namespace_path,
8286
ctx.attr.deps,
8387
ctx.attr.cc_deps,
88+
ctx.attr.cc_support_deps,
8489
)]
8590

8691
_additional_rust_srcs_for_crubit_bindings_rule = rule(
@@ -102,6 +107,10 @@ _additional_rust_srcs_for_crubit_bindings_rule = rule(
102107
default = [],
103108
aspects = [rust_bindings_from_cc_aspect],
104109
),
110+
"cc_support_deps": attr.label_list(
111+
mandatory = False,
112+
default = [],
113+
),
105114
},
106115
implementation = _additional_rust_srcs_for_crubit_bindings_impl,
107116
)
@@ -112,6 +121,7 @@ def additional_rust_srcs_for_crubit_bindings(
112121
namespace_path = "",
113122
deps = [],
114123
cc_deps = [],
124+
cc_support_deps = [],
115125
**kwargs):
116126
"""
117127
Defines an aspect hint that is used to pass extra Rust source files to `rs_bindings_from_cc` tool's `extra_rs_srcs` CLI argument.
@@ -131,6 +141,10 @@ def additional_rust_srcs_for_crubit_bindings(
131141
deps as rust_library.
132142
cc_deps: List of cc_library targets whose crubit-generated bindings will be made available
133143
to this library target.
144+
cc_support_deps: List of cc_library targets of support libraries for generated C++ code.
145+
For example, C++ types that have composable bridging should define their supporting
146+
Crubit ABI types here so they're available to generated code without being exposed to
147+
Crubit.
134148
**kwargs: Args passed through to the underlying rule (visibility, etc.).
135149
"""
136150

@@ -140,6 +154,7 @@ def additional_rust_srcs_for_crubit_bindings(
140154
namespace_path = namespace_path,
141155
deps = deps,
142156
cc_deps = cc_deps,
157+
cc_support_deps = cc_support_deps,
143158
**kwargs
144159
)
145160

rs_bindings_from_cc/bazel_support/providers.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ generated Rust bindings of this C++ target.
1717
"linking a native library.",
1818
"cc_deps": "List of DepVariantInfo of cc_library targets whose crubit-generated bindings " +
1919
"will be linked to this library target.",
20+
"cc_support_deps": "List of CcInfo of support libraries for generated C++ code.",
2021
},
2122
)
2223

rs_bindings_from_cc/bazel_support/rust_bindings_from_cc_aspect.bzl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ def _get_additional_rust_deps(aspect_ctx):
117117
)
118118
return collections.uniq(additional_rust_deps)
119119

120+
def _get_cc_support_deps(aspect_ctx):
121+
cc_support_deps = []
122+
for hint in aspect_ctx.rule.attr.aspect_hints:
123+
if AdditionalRustSrcsProviderInfo in hint:
124+
cc_support_deps.extend(
125+
hint[AdditionalRustSrcsProviderInfo].cc_support_deps,
126+
)
127+
return collections.uniq(cc_support_deps)
128+
120129
def _collect_hdrs(ctx, crubit_features):
121130
public_hdrs = _filter_hdrs(ctx.rule.files.hdrs)
122131
label = str(ctx.label)
@@ -282,6 +291,8 @@ def _rust_bindings_from_cc_aspect_impl(target, ctx):
282291
extra_rs_srcs = []
283292
extra_deps = []
284293

294+
cc_support_deps = _get_cc_support_deps(ctx)
295+
285296
# Headers for which we will produce bindings.
286297
public_hdrs = []
287298

@@ -371,7 +382,7 @@ def _rust_bindings_from_cc_aspect_impl(target, ctx):
371382
d.cc_info
372383
for d in binding_infos
373384
if d.cc_info
374-
] + ctx.attr._deps_for_bindings[DepsForBindingsInfo].deps_for_cc_file,
385+
] + ctx.attr._deps_for_bindings[DepsForBindingsInfo].deps_for_cc_file + cc_support_deps,
375386
deps_for_rs_file = depset(
376387
direct = [
377388
d.dep_variant_info

0 commit comments

Comments
 (0)