Squashed 'third_party/rules_rust/' content from commit bf59038ca

git-subtree-dir: third_party/rules_rust
git-subtree-split: bf59038cac11798cbaef9f3bf965bad8182b97fa
Signed-off-by: Brian Silverman <bsilver16384@gmail.com>
Change-Id: I5a20e403203d670df467ea97dde9a4ac40339a8d
diff --git a/examples/ambiguous_deps/BUILD.bazel b/examples/ambiguous_deps/BUILD.bazel
new file mode 100644
index 0000000..0cf4b47
--- /dev/null
+++ b/examples/ambiguous_deps/BUILD.bazel
@@ -0,0 +1,40 @@
+load("@rules_cc//cc:defs.bzl", "cc_library")
+load("@rules_rust//rust:defs.bzl", "rust_binary")
+
+# A rust_binary that depends on two native libs with the same name.
+# See https://github.com/bazelbuild/rules_rust/issues/840.
+rust_binary(
+    name = "bin_with_same_name_deps",
+    srcs = ["bin.rs"],
+    deps = [
+        "//ambiguous_deps/x:exc",
+        "//ambiguous_deps/y:exc",
+    ],
+)
+
+# A rust_binary that depends on a native library with a name that doesn't
+# match the `lib<name>.a` pattern on linux.
+rust_binary(
+    name = "nonstandard_name_bin",
+    srcs = ["nonstandard_name_bin.rs"],
+    deps = [":nonstandard_name_intermediate"],
+)
+
+cc_library(
+    name = "nonstandard_name_cc_lib",
+    srcs = ["cc_library_with_func.cc"],
+)
+
+genrule(
+    name = "nonstandard_name_gen",
+    srcs = [":nonstandard_name_cc_lib"],
+    outs = ["nonstandard_name_gen.a"],
+    # Copy the first member (libnonstandard_name_cc_lib.a) from the srcs to the
+    # output nonstandard_name_gen.a.
+    cmd = "cp $$(awk '{print $$1}' <<< '$(SRCS)') $@",
+)
+
+cc_library(
+    name = "nonstandard_name_intermediate",
+    srcs = [":nonstandard_name_gen.a"],
+)
diff --git a/examples/ambiguous_deps/bin.rs b/examples/ambiguous_deps/bin.rs
new file mode 100644
index 0000000..8f69444
--- /dev/null
+++ b/examples/ambiguous_deps/bin.rs
@@ -0,0 +1,10 @@
+use std::os::raw::c_int;
+
+extern "C" {
+    pub fn cx() -> c_int;
+    pub fn cy() -> c_int;
+}
+
+fn main() {
+    println!("hi {} {}", unsafe { cx() }, unsafe { cy() });
+}
diff --git a/examples/ambiguous_deps/cc_library_with_func.cc b/examples/ambiguous_deps/cc_library_with_func.cc
new file mode 100644
index 0000000..536fa93
--- /dev/null
+++ b/examples/ambiguous_deps/cc_library_with_func.cc
@@ -0,0 +1,3 @@
+extern "C" int func() {
+  return 123;
+}
diff --git a/examples/ambiguous_deps/nonstandard_name_bin.rs b/examples/ambiguous_deps/nonstandard_name_bin.rs
new file mode 100644
index 0000000..2c07702
--- /dev/null
+++ b/examples/ambiguous_deps/nonstandard_name_bin.rs
@@ -0,0 +1,9 @@
+use std::os::raw::c_int;
+
+extern "C" {
+    pub fn func() -> c_int;
+}
+
+fn main() {
+    println!("hi {}", unsafe { func() });
+}
diff --git a/examples/ambiguous_deps/x/BUILD.bazel b/examples/ambiguous_deps/x/BUILD.bazel
new file mode 100644
index 0000000..87ae07c
--- /dev/null
+++ b/examples/ambiguous_deps/x/BUILD.bazel
@@ -0,0 +1,7 @@
+load("@rules_cc//cc:defs.bzl", "cc_library")
+
+cc_library(
+    name = "exc",
+    srcs = ["exc.cc"],
+    visibility = ["//ambiguous_deps:__subpackages__"],
+)
diff --git a/examples/ambiguous_deps/x/exc.cc b/examples/ambiguous_deps/x/exc.cc
new file mode 100644
index 0000000..2b67c34
--- /dev/null
+++ b/examples/ambiguous_deps/x/exc.cc
@@ -0,0 +1 @@
+extern "C" int cx() { return 17; }
diff --git a/examples/ambiguous_deps/y/BUILD.bazel b/examples/ambiguous_deps/y/BUILD.bazel
new file mode 100644
index 0000000..87ae07c
--- /dev/null
+++ b/examples/ambiguous_deps/y/BUILD.bazel
@@ -0,0 +1,7 @@
+load("@rules_cc//cc:defs.bzl", "cc_library")
+
+cc_library(
+    name = "exc",
+    srcs = ["exc.cc"],
+    visibility = ["//ambiguous_deps:__subpackages__"],
+)
diff --git a/examples/ambiguous_deps/y/exc.cc b/examples/ambiguous_deps/y/exc.cc
new file mode 100644
index 0000000..903ed08
--- /dev/null
+++ b/examples/ambiguous_deps/y/exc.cc
@@ -0,0 +1 @@
+extern "C" int cy() { return 113; }