Skip to content

Commit cb5d526

Browse files
committed
Deprecated rust_bindgen.leak_symbols
1 parent 63fbedb commit cb5d526

File tree

3 files changed

+26
-86
lines changed

3 files changed

+26
-86
lines changed

bindgen/private/bindgen.bzl

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ def rust_bindgen_library(
6969

7070
sub_tags = tags + ([] if "manual" in tags else ["manual"])
7171

72-
deps = kwargs.get("deps") or []
73-
if "deps" in kwargs:
74-
kwargs.pop("deps")
75-
7672
bindgen_kwargs = {}
77-
if "leak_symbols" in kwargs:
78-
bindgen_kwargs.update({"leak_symbols": kwargs.pop("leak_symbols")})
73+
for shared in (
74+
"target_compatible_with",
75+
"exec_compatible_with",
76+
):
77+
if shared in kwargs:
78+
bindgen_kwargs.update({shared: kwargs[shared]})
7979

8080
rust_bindgen(
8181
name = name + "__bindgen",
@@ -88,8 +88,11 @@ def rust_bindgen_library(
8888
**bindgen_kwargs
8989
)
9090

91-
for custom_tag in ["__bindgen", "no-clippy", "no-rustfmt"]:
92-
tags = tags + ([] if custom_tag in tags else [custom_tag])
91+
tags = depset(tags + ["__bindgen", "no-clippy", "no-rustfmt"]).to_list()
92+
93+
deps = kwargs.get("deps") or []
94+
if "deps" in kwargs:
95+
kwargs.pop("deps")
9396

9497
rust_library(
9598
name = name,
@@ -281,33 +284,22 @@ def _rust_bindgen_impl(ctx):
281284
tools = tools,
282285
)
283286

284-
if ctx.attr.leak_symbols:
285-
# buildifier: disable=print
286-
print("WARN: rust_bindgen.leak_symbols is set to True for {} - please file an issue at https://github.com/bazelbuild/rules_rust/issues explaining why this was necessary, as this support will be removed soon.".format(ctx.label))
287-
providers = [cc_common.merge_cc_infos(
288-
direct_cc_infos = [cc_lib[CcInfo]],
289-
)]
290-
else:
291-
providers = [
292-
_generate_cc_link_build_info(ctx, cc_lib),
293-
# As in https://github.com/bazelbuild/rules_rust/pull/2361, we want
294-
# to link cc_lib to the direct parent (rlib) using `-lstatic=<cc_lib>` rustc flag
295-
# Hence, we do not need to provide the whole CcInfo of cc_lib because
296-
# it will cause the downstream binary to link the cc_lib again
297-
# (same effect as setting `leak_symbols` attribute above)
298-
# The CcInfo here only contains the custom link flags (i.e. linkopts attribute)
299-
# specified by users in cc_lib
300-
CcInfo(
301-
linking_context = cc_common.create_linking_context(
302-
linker_inputs = depset([cc_common.create_linker_input(
303-
owner = ctx.label,
304-
user_link_flags = _get_user_link_flags(cc_lib),
305-
)]),
306-
),
287+
return [
288+
_generate_cc_link_build_info(ctx, cc_lib),
289+
# As in https://github.com/bazelbuild/rules_rust/pull/2361, we want
290+
# to link cc_lib to the direct parent (rlib) using `-lstatic=<cc_lib>`
291+
# rustc flag. Hence, we do not need to provide the whole CcInfo of
292+
# cc_lib because it will cause the downstream binary to link the cc_lib
293+
# again. The CcInfo here only contains the custom link flags (i.e.
294+
# linkopts attribute) specified by users in cc_lib.
295+
CcInfo(
296+
linking_context = cc_common.create_linking_context(
297+
linker_inputs = depset([cc_common.create_linker_input(
298+
owner = ctx.label,
299+
user_link_flags = _get_user_link_flags(cc_lib),
300+
)]),
307301
),
308-
]
309-
310-
return providers + [
302+
),
311303
OutputGroupInfo(
312304
bindgen_bindings = depset([output]),
313305
),
@@ -333,13 +325,6 @@ rust_bindgen = rule(
333325
allow_single_file = True,
334326
mandatory = True,
335327
),
336-
"leak_symbols": attr.bool(
337-
doc = (
338-
"If True, `cc_lib` will be exposed and linked into all downstream consumers of the target vs. the " +
339-
"`rust_library` directly consuming it."
340-
),
341-
default = False,
342-
),
343328
"_cc_toolchain": attr.label(
344329
default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
345330
),

examples/bindgen/BUILD.bazel

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ rust_bindgen_library(
99
],
1010
cc_lib = "//bindgen/simple",
1111
header = "//bindgen/simple:simple.h",
12-
leak_symbols = False,
1312
)
1413

1514
rust_binary(
@@ -22,25 +21,3 @@ rust_test(
2221
name = "simple_test",
2322
crate = ":simple_example",
2423
)
25-
26-
rust_bindgen_library(
27-
name = "simple_leaked_bindgen",
28-
bindgen_flags = [
29-
"--allowlist-function=simple_.*",
30-
"--allowlist-var=SIMPLE_.*",
31-
],
32-
cc_lib = "//bindgen/simple",
33-
header = "//bindgen/simple:simple.h",
34-
leak_symbols = True,
35-
)
36-
37-
rust_binary(
38-
name = "simple_leaked_example",
39-
srcs = ["main_leaked.rs"],
40-
deps = [":simple_leaked_bindgen"],
41-
)
42-
43-
rust_test(
44-
name = "simple_leaked_test",
45-
crate = ":simple_leaked_example",
46-
)

examples/bindgen/main_leaked.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)