Support linking Rust code into a C++ binary

This is based on a version of my upstream PR:
https://github.com/bazelbuild/rules_rust/pull/1350

Change-Id: Ica7097c10666d2e0017336cf7d81420605238493
Signed-off-by: Brian Silverman <bsilver16384@gmail.com>
diff --git a/third_party/rules_rust/rust/toolchain.bzl b/third_party/rules_rust/rust/toolchain.bzl
index 687e0df..083991a 100644
--- a/third_party/rules_rust/rust/toolchain.bzl
+++ b/third_party/rules_rust/rust/toolchain.bzl
@@ -11,6 +11,7 @@
     core_files = []
     between_core_and_std_files = []
     std_files = []
+    memchr_files = []
     alloc_files = []
     self_contained_files = [
         file
@@ -35,13 +36,14 @@
         between_core_and_std_files = [
             f
             for f in dot_a_files
-            if "alloc" not in f.basename and "compiler_builtins" not in f.basename and "core" not in f.basename and "adler" not in f.basename and "std" not in f.basename
+            if "alloc" not in f.basename and "compiler_builtins" not in f.basename and "core" not in f.basename and "adler" not in f.basename and "std" not in f.basename and "memchr" not in f.basename
         ]
+        memchr_files = [f for f in dot_a_files if "memchr" in f.basename]
         std_files = [f for f in dot_a_files if "std" in f.basename]
 
-        partitioned_files_len = len(alloc_files) + len(between_alloc_and_core_files) + len(core_files) + len(between_core_and_std_files) + len(std_files)
+        partitioned_files_len = len(alloc_files) + len(between_alloc_and_core_files) + len(core_files) + len(between_core_and_std_files) + len(memchr_files) + len(std_files)
         if partitioned_files_len != len(dot_a_files):
-            partitioned = alloc_files + between_alloc_and_core_files + core_files + between_core_and_std_files + std_files
+            partitioned = alloc_files + between_alloc_and_core_files + core_files + between_core_and_std_files + memchr_files + std_files
             for f in sorted(partitioned):
                 # buildifier: disable=print
                 print("File partitioned: {}".format(f.basename))
@@ -58,6 +60,7 @@
             core_files = core_files,
             between_core_and_std_files = between_core_and_std_files,
             std_files = std_files,
+            memchr_files = memchr_files,
             alloc_files = alloc_files,
             self_contained_files = self_contained_files,
             srcs = ctx.attr.srcs,
@@ -168,12 +171,20 @@
                 for f in filtered_between_core_and_std_files
                 if "panic_abort" not in f.basename
             ]
+        memchr_inputs = depset(
+            [
+                _ltl(f, ctx, cc_toolchain, feature_configuration)
+                for f in rust_stdlib_info.memchr_files
+            ],
+            transitive = [core_inputs],
+            order = "topological",
+        )
         between_core_and_std_inputs = depset(
             [
                 _ltl(f, ctx, cc_toolchain, feature_configuration)
                 for f in filtered_between_core_and_std_files
             ],
-            transitive = [core_inputs],
+            transitive = [memchr_inputs],
             order = "topological",
         )
         std_inputs = depset(
@@ -185,20 +196,20 @@
             order = "topological",
         )
 
-        link_inputs = cc_common.create_linker_input(
+        link_inputs = [depset([cc_common.create_linker_input(
             owner = rust_std.label,
             libraries = std_inputs,
-        )
+        )])]
 
-        allocator_inputs = None
+        allocator_inputs = []
         if allocator_library:
-            allocator_inputs = [allocator_library[CcInfo].linking_context.linker_inputs]
+            allocator_inputs = allocator_library[CcInfo].linking_context.linker_inputs.to_list()
 
         cc_infos.append(CcInfo(
             linking_context = cc_common.create_linking_context(
                 linker_inputs = depset(
-                    [link_inputs],
-                    transitive = allocator_inputs,
+                    allocator_inputs,
+                    transitive = link_inputs,
                     order = "topological",
                 ),
             ),