Disable force_all_deps_direct completely in cc_bindings_from_rs.
Previously we disable it when we generate the bindings but not when we try to compile the bindings, which is an inconsistency.
PiperOrigin-RevId: 666913676
Change-Id: Iccb051badfead48dd5c6cc5736411372ac21adda
diff --git a/cc_bindings_from_rs/bazel_support/cc_bindings_from_rust_rule.bzl b/cc_bindings_from_rs/bazel_support/cc_bindings_from_rust_rule.bzl
index 80a82e4..213eb7b 100644
--- a/cc_bindings_from_rs/bazel_support/cc_bindings_from_rust_rule.bzl
+++ b/cc_bindings_from_rs/bazel_support/cc_bindings_from_rust_rule.bzl
@@ -217,6 +217,9 @@
)
for dep in ctx.attr._rs_deps_for_bindings + [target]
]
+
+ # The `..._cc_api_impl.rs` file needs to depend on all the deps of the target crate.
+ deps += target[CrateInfo].deps.to_list()
dep_variant_info = compile_rust(
ctx,
attr = ctx.rule.attr,
@@ -225,6 +228,7 @@
deps = deps,
crate_name = target[CrateInfo].name + "_cc_api_impl",
include_coverage = True,
+ force_all_deps_direct = False,
)
return dep_variant_info.cc_info
diff --git a/rs_bindings_from_cc/bazel_support/compile_rust.bzl b/rs_bindings_from_cc/bazel_support/compile_rust.bzl
index 850a7ca..2109237 100644
--- a/rs_bindings_from_cc/bazel_support/compile_rust.bzl
+++ b/rs_bindings_from_cc/bazel_support/compile_rust.bzl
@@ -33,7 +33,7 @@
return provider
fail("Couldn't find a CcInfo in the list of providers")
-def compile_rust(ctx, attr, src, extra_srcs, deps, crate_name, include_coverage):
+def compile_rust(ctx, attr, src, extra_srcs, deps, crate_name, include_coverage, force_all_deps_direct):
"""Compiles a Rust source file.
Args:
@@ -44,6 +44,7 @@
deps: List[DepVariantInfo]: A list of dependencies needed.
crate_name: (string) crate name for naming the output files (.rlib, .rmeta...))
include_coverage: (bool) Whether or not coverage information should be generated.
+ force_all_deps_direct: (bool) Whether or not to force all deps to be direct.
Returns:
A DepVariantInfo provider.
@@ -98,7 +99,7 @@
# TODO(b/349776381): remove.
["-Adead_code"],
output_hash = output_hash,
- force_all_deps_direct = True,
+ force_all_deps_direct = force_all_deps_direct,
include_coverage = include_coverage,
)
diff --git a/rs_bindings_from_cc/bazel_support/rust_bindings_from_cc_utils.bzl b/rs_bindings_from_cc/bazel_support/rust_bindings_from_cc_utils.bzl
index 86043d1..42a5394 100644
--- a/rs_bindings_from_cc/bazel_support/rust_bindings_from_cc_utils.bzl
+++ b/rs_bindings_from_cc/bazel_support/rust_bindings_from_cc_utils.bzl
@@ -124,6 +124,7 @@
# the .dat file with the underlying cc_library. Once bazel supports baseline_coverage.dat
# for aspects, we can remove this option.
include_coverage = False,
+ force_all_deps_direct = True,
)
return [