Add cc toolchain files to rustc dependencies (for linker) (#217)


diff --git a/proto/proto.bzl b/proto/proto.bzl
index 2817188..23a1113 100644
--- a/proto/proto.bzl
+++ b/proto/proto.bzl
@@ -216,6 +216,7 @@
     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 @@
     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 2cdcf98..f96bcde 100644
--- a/rust/private/rust.bzl
+++ b/rust/private/rust.bzl
@@ -334,7 +334,10 @@
                  _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 @@
     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 @@
     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 @@
     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 7a8b900..8c538e1 100644
--- a/rust/private/rustc.bzl
+++ b/rust/private/rustc.bzl
@@ -188,6 +188,14 @@
 
     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 @@
         transitive = [
             toolchain.rustc_lib.files,
             toolchain.rust_lib.files,
+            linker_depset,
         ],
     )