diff --git a/bindgen/private/bindgen.bzl b/bindgen/private/bindgen.bzl index 445036bab3..3be192de81 100644 --- a/bindgen/private/bindgen.bzl +++ b/bindgen/private/bindgen.bzl @@ -69,13 +69,13 @@ def rust_bindgen_library( sub_tags = tags + ([] if "manual" in tags else ["manual"]) - deps = kwargs.get("deps") or [] - if "deps" in kwargs: - kwargs.pop("deps") - bindgen_kwargs = {} - if "leak_symbols" in kwargs: - bindgen_kwargs.update({"leak_symbols": kwargs.pop("leak_symbols")}) + for shared in ( + "target_compatible_with", + "exec_compatible_with", + ): + if shared in kwargs: + bindgen_kwargs.update({shared: kwargs[shared]}) rust_bindgen( name = name + "__bindgen", @@ -88,8 +88,11 @@ def rust_bindgen_library( **bindgen_kwargs ) - for custom_tag in ["__bindgen", "no-clippy", "no-rustfmt"]: - tags = tags + ([] if custom_tag in tags else [custom_tag]) + tags = depset(tags + ["__bindgen", "no-clippy", "no-rustfmt"]).to_list() + + deps = kwargs.get("deps") or [] + if "deps" in kwargs: + kwargs.pop("deps") rust_library( name = name, @@ -281,33 +284,22 @@ def _rust_bindgen_impl(ctx): tools = tools, ) - if ctx.attr.leak_symbols: - # buildifier: disable=print - 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)) - providers = [cc_common.merge_cc_infos( - direct_cc_infos = [cc_lib[CcInfo]], - )] - else: - providers = [ - _generate_cc_link_build_info(ctx, cc_lib), - # As in https://github.com/bazelbuild/rules_rust/pull/2361, we want - # to link cc_lib to the direct parent (rlib) using `-lstatic=` rustc flag - # Hence, we do not need to provide the whole CcInfo of cc_lib because - # it will cause the downstream binary to link the cc_lib again - # (same effect as setting `leak_symbols` attribute above) - # The CcInfo here only contains the custom link flags (i.e. linkopts attribute) - # specified by users in cc_lib - CcInfo( - linking_context = cc_common.create_linking_context( - linker_inputs = depset([cc_common.create_linker_input( - owner = ctx.label, - user_link_flags = _get_user_link_flags(cc_lib), - )]), - ), + return [ + _generate_cc_link_build_info(ctx, cc_lib), + # As in https://github.com/bazelbuild/rules_rust/pull/2361, we want + # to link cc_lib to the direct parent (rlib) using `-lstatic=` + # rustc flag. Hence, we do not need to provide the whole CcInfo of + # cc_lib because it will cause the downstream binary to link the cc_lib + # again. The CcInfo here only contains the custom link flags (i.e. + # linkopts attribute) specified by users in cc_lib. + CcInfo( + linking_context = cc_common.create_linking_context( + linker_inputs = depset([cc_common.create_linker_input( + owner = ctx.label, + user_link_flags = _get_user_link_flags(cc_lib), + )]), ), - ] - - return providers + [ + ), OutputGroupInfo( bindgen_bindings = depset([output]), ), @@ -333,13 +325,6 @@ rust_bindgen = rule( allow_single_file = True, mandatory = True, ), - "leak_symbols": attr.bool( - doc = ( - "If True, `cc_lib` will be exposed and linked into all downstream consumers of the target vs. the " + - "`rust_library` directly consuming it." - ), - default = False, - ), "_cc_toolchain": attr.label( default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"), ), diff --git a/docs/flatten.md b/docs/flatten.md index 24c6baa973..8aa240be1d 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -359,7 +359,7 @@ is available under the key `dsym_folder` in `OutputGroupInfo`. ## rust_bindgen
-rust_bindgen(name, bindgen_flags, cc_lib, clang_flags, header, leak_symbols)
+rust_bindgen(name, bindgen_flags, cc_lib, clang_flags, header)
 
Generates a rust source file from a cc_library and a header. @@ -374,7 +374,6 @@ Generates a rust source file from a cc_library and a header. | cc_lib | The cc_library that contains the .h file. This is used to find the transitive includes. | Label | required | | | clang_flags | Flags to pass directly to the clang executable. | List of strings | optional | [] | | header | The .h file to generate bindings for. | Label | required | | -| leak_symbols | If True, cc_lib will be exposed and linked into all downstream consumers of the target vs. the rust_library directly consuming it. | Boolean | optional | False | diff --git a/docs/rust_bindgen.md b/docs/rust_bindgen.md index c99be3397e..aade7a3272 100644 --- a/docs/rust_bindgen.md +++ b/docs/rust_bindgen.md @@ -53,7 +53,7 @@ toolchains following the instructions for [rust_bindgen_toolchain](#rust_bindgen ## rust_bindgen
-rust_bindgen(name, bindgen_flags, cc_lib, clang_flags, header, leak_symbols)
+rust_bindgen(name, bindgen_flags, cc_lib, clang_flags, header)
 
Generates a rust source file from a cc_library and a header. @@ -68,7 +68,6 @@ Generates a rust source file from a cc_library and a header. | cc_lib | The cc_library that contains the .h file. This is used to find the transitive includes. | Label | required | | | clang_flags | Flags to pass directly to the clang executable. | List of strings | optional | [] | | header | The .h file to generate bindings for. | Label | required | | -| leak_symbols | If True, cc_lib will be exposed and linked into all downstream consumers of the target vs. the rust_library directly consuming it. | Boolean | optional | False | diff --git a/examples/bindgen/BUILD.bazel b/examples/bindgen/BUILD.bazel index 68de222119..4387173236 100644 --- a/examples/bindgen/BUILD.bazel +++ b/examples/bindgen/BUILD.bazel @@ -9,7 +9,6 @@ rust_bindgen_library( ], cc_lib = "//bindgen/simple", header = "//bindgen/simple:simple.h", - leak_symbols = False, ) rust_binary( @@ -22,25 +21,3 @@ rust_test( name = "simple_test", crate = ":simple_example", ) - -rust_bindgen_library( - name = "simple_leaked_bindgen", - bindgen_flags = [ - "--allowlist-function=simple_.*", - "--allowlist-var=SIMPLE_.*", - ], - cc_lib = "//bindgen/simple", - header = "//bindgen/simple:simple.h", - leak_symbols = True, -) - -rust_binary( - name = "simple_leaked_example", - srcs = ["main_leaked.rs"], - deps = [":simple_leaked_bindgen"], -) - -rust_test( - name = "simple_leaked_test", - crate = ":simple_leaked_example", -) diff --git a/examples/bindgen/main_leaked.rs b/examples/bindgen/main_leaked.rs deleted file mode 100644 index 8107ff8d07..0000000000 --- a/examples/bindgen/main_leaked.rs +++ /dev/null @@ -1,22 +0,0 @@ -//! rust_bindgen_library example consumer - -fn simple_function() -> i64 { - unsafe { simple_leaked_bindgen::simple_function() } -} - -fn main() { - println!( - "The values are {} and {}!", - simple_leaked_bindgen::SIMPLE_VALUE, - simple_function() - ); -} - -#[cfg(test)] -mod test { - #[test] - fn do_the_test() { - assert_eq!(42, simple_leaked_bindgen::SIMPLE_VALUE); - assert_eq!(1337, super::simple_function()); - } -}