Clean up a few things with the way we use rules_rust

After using rules_rust a bit more, I noticed that some of the ways we
had it set up aren't quite correct. In particular, arch-related `cfg`
didn't work for armv7, which breaks many more complex crates.

Change-Id: I5a15160abfd9da7609f7e9e4b60ec40cbe055d25
Signed-off-by: Brian Silverman <bsilver16384@gmail.com>
diff --git a/tools/rust/BUILD b/tools/rust/BUILD
index a652530..e58bb19 100644
--- a/tools/rust/BUILD
+++ b/tools/rust/BUILD
@@ -1,8 +1,55 @@
 load("@rules_rust//rust:toolchain.bzl", "rust_stdlib_filegroup", "rust_toolchain")
 load("@bazel_skylib//rules:write_file.bzl", "write_file")
 
-# Similar to the one automatically generated by @rust, but with the correct
-# hardware platform configured.
+# We have to declare our toolchains individually to get the corect constraints
+# configured so we can robustly select the correct one for each of our
+# platforms.
+
+toolchain(
+    name = "rust-toolchain-x86",
+    exec_compatible_with = [
+        "@platforms//os:linux",
+        "@platforms//cpu:x86_64",
+    ],
+    target_compatible_with = [
+        "@platforms//os:linux",
+        "@platforms//cpu:x86_64",
+    ],
+    toolchain = "@rust//:toolchain_for_x86_64-unknown-linux-gnu_impl",
+    toolchain_type = "@rules_rust//rust:toolchain",
+)
+
+toolchain(
+    name = "rust-toolchain-armv7",
+    exec_compatible_with = [
+        "@platforms//os:linux",
+        "@platforms//cpu:x86_64",
+    ],
+    target_compatible_with = [
+        "@platforms//os:linux",
+        "@platforms//cpu:armv7",
+        # Include this so we're incompatible with the roborio platform, to avoid
+        # subtle order dependencies.
+        "//tools/platforms/hardware:raspberry_pi",
+    ],
+    toolchain = "@rust//:toolchain_for_armv7-unknown-linux-gnueabihf_impl",
+    toolchain_type = "@rules_rust//rust:toolchain",
+)
+
+toolchain(
+    name = "rust-toolchain-arm64",
+    exec_compatible_with = [
+        "@platforms//os:linux",
+        "@platforms//cpu:x86_64",
+    ],
+    target_compatible_with = [
+        "@platforms//os:linux",
+        "@platforms//cpu:arm64",
+    ],
+    toolchain = "@rust//:toolchain_for_aarch64-unknown-linux-gnu_impl",
+    toolchain_type = "@rules_rust//rust:toolchain",
+)
+
 toolchain(
     name = "rust-toolchain-roborio",
     exec_compatible_with = [
@@ -11,6 +58,7 @@
     ],
     target_compatible_with = [
         "@platforms//os:linux",
+        "@platforms//cpu:armv7",
         "//tools/platforms/hardware:roborio",
     ],
     toolchain = "@rust//:toolchain_for_arm-unknown-linux-gnueabi_impl",