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/y2016/BUILD b/y2016/BUILD
index 6944d4f..8c695c8 100644
--- a/y2016/BUILD
+++ b/y2016/BUILD
@@ -9,6 +9,7 @@
     hdrs = [
         "constants.h",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
     deps = [
         "//aos/logging",
@@ -27,6 +28,7 @@
     srcs = [
         "joystick_reader.cc",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":constants",
         "//aos:init",
@@ -69,6 +71,7 @@
         "//y2016/actors:vision_align_action",
         "//y2016/vision:target_receiver",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 aos_config(
@@ -89,6 +92,7 @@
         "//y2016/actors:vision_align_action_fbs",
         "//y2016/actors:superstructure_action_fbs",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
     deps = [
         "//aos/robot_state:config",
@@ -103,7 +107,7 @@
     srcs = [
         "wpilib_interface.cc",
     ],
-    restricted_to = ["//tools:roborio"],
+    target_compatible_with = ["//tools/platforms/hardware:roborio"],
     deps = [
         ":constants",
         "//aos:init",
@@ -149,5 +153,6 @@
 py_library(
     name = "python_init",
     srcs = ["__init__.py"],
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
 )
diff --git a/y2016/actors/BUILD b/y2016/actors/BUILD
index f80128d..6a8c915 100644
--- a/y2016/actors/BUILD
+++ b/y2016/actors/BUILD
@@ -16,6 +16,7 @@
         "superstructure_action.fbs",
     ],
     gen_reflections = 1,
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
 )
 
@@ -27,6 +28,7 @@
     hdrs = [
         "superstructure_actor.h",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":superstructure_action_fbs",
         "//aos/actions:action_lib",
@@ -44,6 +46,7 @@
     srcs = [
         "superstructure_actor_main.cc",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":superstructure_action_fbs",
         ":superstructure_action_lib",
@@ -60,6 +63,7 @@
     hdrs = [
         "autonomous_actor.h",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":vision_align_action_lib",
         "//aos/actions:action_lib",
@@ -81,6 +85,7 @@
     srcs = [
         "autonomous_actor_main.cc",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":autonomous_action_lib",
         "//aos:init",
@@ -93,6 +98,7 @@
         "vision_align_action.fbs",
     ],
     gen_reflections = 1,
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
 )
 
@@ -104,6 +110,7 @@
     hdrs = [
         "vision_align_actor.h",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":vision_align_action_fbs",
         "//aos:math",
@@ -126,6 +133,7 @@
     srcs = [
         "vision_align_actor_main.cc",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":vision_align_action_fbs",
         ":vision_align_action_lib",
diff --git a/y2016/control_loops/BUILD b/y2016/control_loops/BUILD
index de3bfeb..ddc39d4 100644
--- a/y2016/control_loops/BUILD
+++ b/y2016/control_loops/BUILD
@@ -1,6 +1,7 @@
 py_library(
     name = "python_init",
     srcs = ["__init__.py"],
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
     deps = ["//y2016:python_init"],
 )
diff --git a/y2016/control_loops/drivetrain/BUILD b/y2016/control_loops/drivetrain/BUILD
index e706f25..0988e03 100644
--- a/y2016/control_loops/drivetrain/BUILD
+++ b/y2016/control_loops/drivetrain/BUILD
@@ -7,6 +7,7 @@
         "kalman_drivetrain_motor_plant.cc",
     ],
     cmd = "$(location //y2016/control_loops/python:drivetrain) $(OUTS)",
+    target_compatible_with = ["@platforms//os:linux"],
     tools = [
         "//y2016/control_loops/python:drivetrain",
     ],
@@ -23,6 +24,7 @@
         "hybrid_velocity_drivetrain.cc",
     ],
     cmd = "$(location //y2016/control_loops/python:polydrivetrain) $(OUTS)",
+    target_compatible_with = ["@platforms//os:linux"],
     tools = [
         "//y2016/control_loops/python:polydrivetrain",
     ],
@@ -42,6 +44,7 @@
         "kalman_drivetrain_motor_plant.h",
         "polydrivetrain_dog_motor_plant.h",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
     deps = [
         "//frc971/control_loops:hybrid_state_feedback_loop",
@@ -57,6 +60,7 @@
     hdrs = [
         "drivetrain_base.h",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
     deps = [
         ":polydrivetrain_plants",
@@ -71,6 +75,7 @@
     srcs = [
         "drivetrain_main.cc",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
     deps = [
         ":drivetrain_base",
diff --git a/y2016/control_loops/python/BUILD b/y2016/control_loops/python/BUILD
index 65964fd..6c2c02d 100644
--- a/y2016/control_loops/python/BUILD
+++ b/y2016/control_loops/python/BUILD
@@ -6,7 +6,7 @@
         "drivetrain.py",
     ],
     legacy_create_init = False,
-    restricted_to = ["//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
         "//external:python-gflags",
@@ -22,7 +22,7 @@
         "polydrivetrain.py",
     ],
     legacy_create_init = False,
-    restricted_to = ["//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
         "//external:python-gflags",
@@ -37,7 +37,7 @@
         "drivetrain.py",
         "polydrivetrain.py",
     ],
-    restricted_to = ["//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     visibility = ["//visibility:public"],
     deps = [
         ":python_init",
@@ -55,7 +55,7 @@
         "shooter.py",
     ],
     legacy_create_init = False,
-    restricted_to = ["//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
         "//external:python-gflags",
@@ -71,7 +71,7 @@
         "intake.py",
     ],
     legacy_create_init = False,
-    restricted_to = ["//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
         "//external:python-gflags",
@@ -87,7 +87,7 @@
         "shoulder.py",
     ],
     legacy_create_init = False,
-    restricted_to = ["//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
         "//aos/util:py_trapezoid_profile",
@@ -104,7 +104,7 @@
         "wrist.py",
     ],
     legacy_create_init = False,
-    restricted_to = ["//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
         "//aos/util:py_trapezoid_profile",
@@ -120,7 +120,7 @@
     srcs = [
         "wrist.py",
     ],
-    restricted_to = ["//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         "//aos/util:py_trapezoid_profile",
         "//external:python-gflags",
@@ -134,7 +134,7 @@
     srcs = [
         "shoulder.py",
     ],
-    restricted_to = ["//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         "//aos/util:py_trapezoid_profile",
         "//external:python-gflags",
@@ -149,7 +149,7 @@
     srcs = [
         "arm.py",
     ],
-    restricted_to = ["//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":shoulder_lib",
         ":wrist_lib",
@@ -167,7 +167,7 @@
         "arm.py",
     ],
     legacy_create_init = False,
-    restricted_to = ["//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
         ":shoulder_lib",
@@ -182,6 +182,7 @@
 py_library(
     name = "python_init",
     srcs = ["__init__.py"],
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
     deps = ["//y2016/control_loops:python_init"],
 )
diff --git a/y2016/control_loops/shooter/BUILD b/y2016/control_loops/shooter/BUILD
index 3ffc9cc..a6cf134 100644
--- a/y2016/control_loops/shooter/BUILD
+++ b/y2016/control_loops/shooter/BUILD
@@ -8,6 +8,7 @@
         "shooter_goal.fbs",
     ],
     gen_reflections = 1,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 flatbuffer_cc_library(
@@ -16,6 +17,7 @@
         "shooter_position.fbs",
     ],
     gen_reflections = 1,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 flatbuffer_cc_library(
@@ -24,6 +26,7 @@
         "shooter_output.fbs",
     ],
     gen_reflections = 1,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 flatbuffer_cc_library(
@@ -32,6 +35,7 @@
         "shooter_status.fbs",
     ],
     gen_reflections = 1,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 genrule(
@@ -43,6 +47,7 @@
         "shooter_integral_plant.cc",
     ],
     cmd = "$(location //y2016/control_loops/python:shooter) $(OUTS)",
+    target_compatible_with = ["@platforms//os:linux"],
     tools = [
         "//y2016/control_loops/python:shooter",
     ],
@@ -59,6 +64,7 @@
         "shooter_integral_plant.h",
         "shooter_plant.h",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         "//frc971/control_loops:state_feedback_loop",
     ],
@@ -72,6 +78,7 @@
     hdrs = [
         "shooter.h",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":shooter_goal_fbs",
         ":shooter_output_fbs",
@@ -88,6 +95,7 @@
         "shooter_lib_test.cc",
     ],
     data = ["//y2016:config"],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":shooter_goal_fbs",
         ":shooter_lib",
@@ -106,6 +114,7 @@
     srcs = [
         "shooter_main.cc",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":shooter_goal_fbs",
         ":shooter_lib",
diff --git a/y2016/control_loops/superstructure/BUILD b/y2016/control_loops/superstructure/BUILD
index aecfd98..cb07ebe 100644
--- a/y2016/control_loops/superstructure/BUILD
+++ b/y2016/control_loops/superstructure/BUILD
@@ -8,6 +8,7 @@
         "superstructure_goal.fbs",
     ],
     gen_reflections = 1,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 flatbuffer_cc_library(
@@ -19,6 +20,7 @@
     includes = [
         "//frc971/control_loops:control_loops_fbs_includes",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 flatbuffer_cc_library(
@@ -27,6 +29,7 @@
         "superstructure_output.fbs",
     ],
     gen_reflections = 1,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 flatbuffer_cc_library(
@@ -38,6 +41,7 @@
     includes = [
         "//frc971/control_loops:control_loops_fbs_includes",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 genrule(
@@ -49,6 +53,7 @@
         "integral_intake_plant.cc",
     ],
     cmd = "$(location //y2016/control_loops/python:intake) $(OUTS)",
+    target_compatible_with = ["@platforms//os:linux"],
     tools = [
         "//y2016/control_loops/python:intake",
     ],
@@ -64,6 +69,7 @@
         "integral_arm_plant.cc",
     ],
     cmd = "$(location //y2016/control_loops/python:arm) $(OUTS)",
+    target_compatible_with = ["@platforms//os:linux"],
     tools = [
         "//y2016/control_loops/python:arm",
     ],
@@ -84,6 +90,7 @@
         "integral_arm_plant.h",
         "integral_intake_plant.h",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         "//frc971/control_loops:state_feedback_loop",
     ],
@@ -99,6 +106,7 @@
         "superstructure.h",
         "superstructure_controls.h",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":superstructure_goal_fbs",
         ":superstructure_output_fbs",
@@ -123,6 +131,7 @@
         "superstructure_lib_test.cc",
     ],
     data = ["//y2016:config"],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":superstructure_goal_fbs",
         ":superstructure_lib",
@@ -143,6 +152,7 @@
     srcs = [
         "superstructure_main.cc",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":superstructure_lib",
         "//aos:init",
diff --git a/y2016/dashboard/BUILD b/y2016/dashboard/BUILD
index 9e8198a..0dc3ad4 100644
--- a/y2016/dashboard/BUILD
+++ b/y2016/dashboard/BUILD
@@ -7,6 +7,7 @@
         ["www_defaults/**/*"],
         exclude = ["www/**/*"],
     ),
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 aos_downloader_dir(
@@ -15,6 +16,7 @@
         "www/**/*",
     ]),
     dir = "www",
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
 )
 
@@ -24,6 +26,7 @@
         "dashboard.cc",
         "dashboard.h",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
     deps = [
         ":gen_embedded",
diff --git a/y2016/queues/BUILD b/y2016/queues/BUILD
index 5c51a41..337ea96 100644
--- a/y2016/queues/BUILD
+++ b/y2016/queues/BUILD
@@ -8,4 +8,5 @@
         "ball_detector.fbs",
     ],
     gen_reflections = 1,
+    target_compatible_with = ["@platforms//os:linux"],
 )
diff --git a/y2016/vision/BUILD b/y2016/vision/BUILD
index 072b6ca..2a8031d 100644
--- a/y2016/vision/BUILD
+++ b/y2016/vision/BUILD
@@ -1,6 +1,7 @@
 load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library")
 load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
 load("//tools/build_rules:gtk_dependent.bzl", "gtk_dependent_cc_binary", "gtk_dependent_cc_library")
+load("//tools:platforms.bzl", "platforms")
 
 flatbuffer_cc_library(
     name = "vision_fbs",
@@ -8,17 +9,20 @@
         "vision.fbs",
     ],
     gen_reflections = 1,
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
 )
 
 cc_proto_library(
     name = "vision_data",
     srcs = ["vision_data.proto"],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 cc_proto_library(
     name = "calibration",
     srcs = ["calibration.proto"],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 _calibration_values_embedded_before = """
@@ -60,6 +64,7 @@
         "cat $(location :calibration.pb) | sed 's/\"/\\\\\"/g ; s/^/\"/g ; s/$$/\\\\n\"/g' >> $@",
         "echo '%s' >> $@" % _calibration_values_embedded_after,
     ]),
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 cc_library(
@@ -71,6 +76,7 @@
     hdrs = [
         "stereo_geometry.h",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":calibration",
         "//aos/logging",
@@ -81,10 +87,10 @@
 cc_binary(
     name = "target_sender",
     srcs = ["target_sender.cc"],
-    restricted_to = [
-        "//tools:k8",
-        "//tools:armhf-debian",
-    ],
+    target_compatible_with = platforms.any_of([
+        "@platforms//cpu:x86_64",
+        "//tools/platforms/hardware:raspberry_pi",
+    ]),
     deps = [
         ":calibration",
         ":stereo_geometry",
@@ -106,10 +112,10 @@
     name = "blob_filters",
     srcs = ["blob_filters.cc"],
     hdrs = ["blob_filters.h"],
-    restricted_to = [
-        "//tools:k8",
-        "//tools:armhf-debian",
-    ],
+    target_compatible_with = platforms.any_of([
+        "@platforms//cpu:x86_64",
+        "//tools/platforms/hardware:raspberry_pi",
+    ]),
     visibility = ["//visibility:public"],
     deps = [
         "//aos/vision/blob:codec",
@@ -127,6 +133,7 @@
     srcs = [
         "target_receiver.cc",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
     deps = [
         ":stereo_geometry",
@@ -146,10 +153,10 @@
 gtk_dependent_cc_binary(
     name = "debug_receiver",
     srcs = ["debug_receiver.cc"],
-    restricted_to = [
-        "//tools:k8",
-        "//tools:armhf-debian",
-    ],
+    target_compatible_with = platforms.any_of([
+        "@platforms//cpu:x86_64",
+        "//tools/platforms/hardware:raspberry_pi",
+    ]),
     visibility = ["//visibility:public"],
     deps = [
         ":blob_filters",
diff --git a/y2016/vision/tools/BUILD b/y2016/vision/tools/BUILD
index edbfca5..62ed6b4 100644
--- a/y2016/vision/tools/BUILD
+++ b/y2016/vision/tools/BUILD
@@ -1,12 +1,13 @@
 load("//tools/build_rules:gtk_dependent.bzl", "gtk_dependent_cc_binary", "gtk_dependent_cc_library")
+load("//tools:platforms.bzl", "platforms")
 
 gtk_dependent_cc_binary(
     name = "blob_stream_replay",
     srcs = ["blob_stream_replay.cc"],
-    restricted_to = [
-        "//tools:k8",
-        "//tools:armhf-debian",
-    ],
+    target_compatible_with = platforms.any_of([
+        "@platforms//cpu:x86_64",
+        "//tools/platforms/hardware:raspberry_pi",
+    ]),
     deps = [
         "//aos/vision/blob:range_image",
         "//aos/vision/blob:stream_view",