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/ffi/rust_calling_c/BUILD.bazel b/examples/ffi/rust_calling_c/BUILD.bazel
new file mode 100644
index 0000000..041d1da
--- /dev/null
+++ b/examples/ffi/rust_calling_c/BUILD.bazel
@@ -0,0 +1,62 @@
+load("@rules_rust//rust:defs.bzl", "rust_doc", "rust_library", "rust_test")
+
+package(default_visibility = ["//ffi/rust_calling_c:__subpackages__"])
+
+rust_library(
+    name = "matrix",
+    srcs = [
+        "src/ffi.rs",
+        "src/matrix.rs",
+    ],
+    deps = [
+        "//ffi/rust_calling_c/c:native_matrix",
+        "@libc",
+    ],
+)
+
+rust_test(
+    name = "matrix_test",
+    crate = ":matrix",
+)
+
+rust_doc(
+    name = "matrix_doc",
+    crate = ":matrix",
+)
+
+## Do the same as above, but with a dynamic c library.
+
+rust_library(
+    name = "matrix_dynamically_linked",
+    srcs = [
+        "src/ffi.rs",
+        "src/matrix.rs",
+    ],
+    crate_root = "src/matrix.rs",
+    target_compatible_with = select({
+        # TODO: Make this work on windows
+        "@platforms//os:windows": ["@platforms//:incompatible"],
+        "//conditions:default": [],
+    }),
+    deps = [
+        "//ffi/rust_calling_c/c:native_matrix_so",
+        "@libc",
+    ],
+)
+
+rust_test(
+    name = "matrix_dylib_test",
+    crate = ":matrix_dynamically_linked",
+    target_compatible_with = select({
+        # TODO: This test requires --incompatible_macos_set_install_name and Bazel 4.2.0+
+        "@platforms//os:macos": ["@platforms//:incompatible"],
+        # TODO: Make this work on windows
+        "@platforms//os:windows": ["@platforms//:incompatible"],
+        "//conditions:default": [],
+    }),
+)
+
+rust_doc(
+    name = "matrix_dylib_doc",
+    crate = ":matrix_dynamically_linked",
+)