Switch everything to platforms

This patch switches the codebase over from using the "cpu"
mechanism to using bazel platforms. See
https://docs.bazel.build/versions/master/platforms.html for some more
information.

Most of the substantial changes are in //tools. Instead of using
`cc_toolchain_suite` rules, we now use regular `toolchain` rules that
are registered in the WORKSPACE. That also means that bazel now uses
the target platform to select the compiler.

All --cpu=* arguments should now be --config=* arguments. For example,
`--cpu=roborio` should now be `--config=roborio`. The CI script and
all documentation has been updated to reflect that.

The remainder of the changes revolve around tagging all targets with
`target_compatible_with`.  The old mechanism allowed us to specify
repo-wide defaults. The new mechanism does not. That means every
target that didn't have any compatibility specified, now requires
compatibility with `@platforms//os:linux`.

I used buildozer for the vast majority of `target_compatible_with`
changes. buildozer automatically buildifies any BUILD files it
touches. That means this patch also contains a few non-functional
changes that I was too lazy to remove.

Change-Id: I66d6e6ad9161520ee397597cdb492585820a3acd
diff --git a/y2019/jevois/BUILD b/y2019/jevois/BUILD
index f11c67c..d6d3dfc 100644
--- a/y2019/jevois/BUILD
+++ b/y2019/jevois/BUILD
@@ -1,4 +1,3 @@
-load("//tools:environments.bzl", "mcu_cpus")
 load("//motors:macros.bzl", "hex_from_elf")
 
 jevois_crc_args = [
@@ -47,7 +46,7 @@
             "$(location jevois_crc.c)",
         ]),
     ]),
-    compatible_with = mcu_cpus,
+    target_compatible_with = ["@platforms//os:linux"],
     tools = [
         "//third_party/pycrc:pycrc_main",
     ],
@@ -61,7 +60,7 @@
     hdrs = [
         "jevois_crc.h",
     ],
-    compatible_with = mcu_cpus,
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         "//third_party/GSL",
     ],
@@ -81,19 +80,6 @@
 )
 
 cc_library(
-    name = "structures_mcu",
-    hdrs = [
-        "structures.h",
-    ],
-    restricted_to = mcu_cpus,
-    deps = [
-        "//aos/containers:sized_array",
-        "//aos/time:time_mcu",
-        "@org_tuxfamily_eigen//:eigen",
-    ],
-)
-
-cc_library(
     name = "spi",
     srcs = [
         "spi.cc",
@@ -105,27 +91,12 @@
     deps = [
         ":jevois_crc",
         ":structures",
-        "//aos/logging",
         "//aos/util:bitpacking",
         "//third_party/GSL",
-    ],
-)
-
-cc_library(
-    name = "spi_mcu",
-    srcs = [
-        "spi.cc",
-    ],
-    hdrs = [
-        "spi.h",
-    ],
-    restricted_to = mcu_cpus,
-    deps = [
-        ":jevois_crc",
-        ":structures_mcu",
-        "//aos/util:bitpacking",
-        "//third_party/GSL",
-    ],
+    ] + select({
+        "@platforms//os:linux": ["//aos/logging"],
+        "//conditions:default": [],
+    }),
 )
 
 cc_library(
@@ -142,29 +113,12 @@
         ":jevois_crc",
         ":structures",
         "//aos/containers:sized_array",
-        "//aos/logging",
         "//aos/util:bitpacking",
         "//third_party/GSL",
-    ],
-)
-
-cc_library(
-    name = "uart_mcu",
-    srcs = [
-        "uart.cc",
-    ],
-    hdrs = [
-        "uart.h",
-    ],
-    restricted_to = mcu_cpus,
-    deps = [
-        ":cobs_mcu",
-        ":jevois_crc",
-        ":structures_mcu",
-        "//aos/containers:sized_array",
-        "//aos/util:bitpacking",
-        "//third_party/GSL",
-    ],
+    ] + select({
+        "@platforms//os:linux": ["//aos/logging"],
+        "//conditions:default": [],
+    }),
 )
 
 cc_test(
@@ -172,6 +126,7 @@
     srcs = [
         "uart_test.cc",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":uart",
         "//aos/testing:googletest",
@@ -183,6 +138,7 @@
     srcs = [
         "spi_test.cc",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":spi",
         "//aos/testing:googletest",
@@ -199,22 +155,12 @@
     ],
 )
 
-cc_library(
-    name = "cobs_mcu",
-    hdrs = [
-        "cobs.h",
-    ],
-    restricted_to = mcu_cpus,
-    deps = [
-        "//third_party/GSL",
-    ],
-)
-
 cc_test(
     name = "cobs_test",
     srcs = [
         "cobs_test.cc",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":cobs",
         "//aos/testing:googletest",
@@ -227,6 +173,7 @@
     name = "serial",
     srcs = ["serial.cc"],
     hdrs = ["serial.h"],
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
     deps = [
         "//aos/logging",
@@ -238,12 +185,12 @@
     srcs = [
         "teensy.cc",
     ],
-    restricted_to = ["//tools:cortex-m4f"],
+    target_compatible_with = ["//tools/platforms/hardware:cortex_m4f"],
     deps = [
-        ":cobs_mcu",
-        ":spi_mcu",
-        ":uart_mcu",
-        "//aos/time:time_mcu",
+        ":cobs",
+        ":spi",
+        ":uart",
+        "//aos/time:time",
         "//motors:util",
         "//motors/core",
         "//motors/peripheral:configuration",
@@ -257,5 +204,5 @@
 
 hex_from_elf(
     name = "teensy",
-    restricted_to = ["//tools:cortex-m4f"],
+    target_compatible_with = ["//tools/platforms/hardware:cortex_m4f"],
 )
diff --git a/y2019/jevois/camera/BUILD b/y2019/jevois/camera/BUILD
index bf716a0..6bd2b99 100644
--- a/y2019/jevois/camera/BUILD
+++ b/y2019/jevois/camera/BUILD
@@ -4,6 +4,7 @@
     name = "reader",
     srcs = ["reader.cc"],
     hdrs = ["reader.h"],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         "//aos/time",
         "//aos/vision/image:camera_params",
@@ -17,6 +18,7 @@
     name = "image_stream",
     srcs = ["image_stream.cc"],
     hdrs = ["image_stream.h"],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":reader",
         "//aos/logging",
diff --git a/y2019/jevois/deploy_teensy.sh b/y2019/jevois/deploy_teensy.sh
index 50d0571..87ea153 100755
--- a/y2019/jevois/deploy_teensy.sh
+++ b/y2019/jevois/deploy_teensy.sh
@@ -2,4 +2,4 @@
 
 cd "$(dirname "${BASH_SOURCE[0]}")"
 
-bazel build --cpu=cortex-m4f -c opt //y2019/jevois:teensy.hex -s && bazel run //motors/teensy_loader_cli -- --mcu=mk64fx512 -s $(readlink -f ../../bazel-bin/y2019/jevois/teensy.hex)
+bazel build --config=cortex-m4f -c opt //y2019/jevois:teensy.hex -s && bazel run //motors/teensy_loader_cli -- --mcu=mk64fx512 -s $(readlink -f ../../bazel-bin/y2019/jevois/teensy.hex)