diff --git a/proto/proto.bzl b/proto/proto.bzl index 281718888a..23a1113de3 100644 --- a/proto/proto.bzl +++ b/proto/proto.bzl @@ -216,6 +216,7 @@ rust_proto_library = rule( toolchains = [ "@io_bazel_rules_rust//proto:toolchain", "@io_bazel_rules_rust//rust:toolchain", + "@bazel_tools//tools/cpp:toolchain_type", ], doc = """ Builds a Rust library crate from a set of `proto_library`s. @@ -275,6 +276,7 @@ rust_grpc_library = rule( toolchains = [ "@io_bazel_rules_rust//proto:toolchain", "@io_bazel_rules_rust//rust:toolchain", + "@bazel_tools//tools/cpp:toolchain_type", ], doc = """ Builds a Rust library crate from a set of `proto_library`s suitable for gRPC. diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl index 2cdcf98ff6..f96bcde65d 100644 --- a/rust/private/rust.bzl +++ b/rust/private/rust.bzl @@ -334,7 +334,10 @@ rust_library = rule( _rust_library_attrs.items()), fragments = ["cpp"], host_fragments = ["cpp"], - toolchains = ["@io_bazel_rules_rust//rust:toolchain"], + toolchains = [ + "@io_bazel_rules_rust//rust:toolchain", + "@bazel_tools//tools/cpp:toolchain_type" + ], doc = """ Builds a Rust library crate. @@ -417,7 +420,10 @@ rust_binary = rule( executable = True, fragments = ["cpp"], host_fragments = ["cpp"], - toolchains = ["@io_bazel_rules_rust//rust:toolchain"], + toolchains = [ + "@io_bazel_rules_rust//rust:toolchain", + "@bazel_tools//tools/cpp:toolchain_type" + ], doc = """ Builds a Rust binary crate. @@ -512,7 +518,10 @@ rust_test = rule( fragments = ["cpp"], host_fragments = ["cpp"], test = True, - toolchains = ["@io_bazel_rules_rust//rust:toolchain"], + toolchains = [ + "@io_bazel_rules_rust//rust:toolchain", + "@bazel_tools//tools/cpp:toolchain_type" + ], doc = """ Builds a Rust test crate. @@ -656,7 +665,10 @@ rust_benchmark = rule( executable = True, fragments = ["cpp"], host_fragments = ["cpp"], - toolchains = ["@io_bazel_rules_rust//rust:toolchain"], + toolchains = [ + "@io_bazel_rules_rust//rust:toolchain", + "@bazel_tools//tools/cpp:toolchain_type" + ], doc = """ Builds a Rust benchmark test. diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 7a8b900db7..8c538e1b8f 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -188,6 +188,14 @@ def rustc_compile_action( linker_script = getattr(ctx.file, "linker_script") if hasattr(ctx.file, "linker_script") else None + cc_toolchain = find_cpp_toolchain(ctx) + + if (len(BAZEL_VERSION) == 0 or + versions.is_at_least("0.25.0", BAZEL_VERSION)): + linker_depset = find_cpp_toolchain(ctx).all_files + else: + linker_depset = depset(ctx.files._cc_toolchain) + compile_inputs = depset( crate_info.srcs + getattr(ctx.files, "data", []) + @@ -198,6 +206,7 @@ def rustc_compile_action( transitive = [ toolchain.rustc_lib.files, toolchain.rust_lib.files, + linker_depset, ], )