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/motors/BUILD b/motors/BUILD
index 8fe5ff6..b606bf7 100644
--- a/motors/BUILD
+++ b/motors/BUILD
@@ -1,5 +1,4 @@
load("//motors:macros.bzl", "hex_from_elf")
-load("//tools:environments.bzl", "mcu_cpus")
cc_library(
name = "motor",
@@ -9,7 +8,7 @@
hdrs = [
"motor.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":algorithms",
@@ -27,7 +26,7 @@
hdrs = [
"util.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
"//motors/core",
@@ -52,6 +51,7 @@
"$@",
"$<",
]),
+ target_compatible_with = ["@platforms//os:linux"],
tools = [
"@pandoc",
"@pandoc//:all_files",
@@ -66,7 +66,6 @@
hdrs = [
"algorithms.h",
],
- compatible_with = mcu_cpus,
)
cc_test(
@@ -74,6 +73,7 @@
srcs = [
"algorithms_test.cc",
],
+ target_compatible_with = ["@platforms//os:linux"],
deps = [
":algorithms",
"//aos/testing:googletest",
@@ -88,7 +88,6 @@
hdrs = [
"math.h",
],
- compatible_with = mcu_cpus,
visibility = ["//visibility:public"],
)
@@ -97,6 +96,7 @@
srcs = [
"math_test.cc",
],
+ target_compatible_with = ["@platforms//os:linux"],
deps = [
":math",
"//aos/testing:googletest",
@@ -108,7 +108,7 @@
srcs = [
"button_board.cc",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
deps = [
":util",
"//motors/core",
@@ -123,7 +123,7 @@
hex_from_elf(
name = "button_board",
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
)
cc_binary(
@@ -132,7 +132,7 @@
"simple_receiver.cc",
],
copts = ["-Wno-type-limits"],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
deps = [
":util",
"//motors/core",
@@ -146,7 +146,7 @@
hex_from_elf(
name = "simpler_receiver",
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
)
cc_binary(
@@ -155,7 +155,7 @@
"simpler_receiver.cc",
],
copts = ["-Wno-type-limits"],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
deps = [
":util",
"//motors/core",
@@ -167,11 +167,12 @@
hex_from_elf(
name = "simple_receiver",
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
)
py_library(
name = "python_init",
srcs = ["__init__.py"],
+ target_compatible_with = ["@platforms//os:linux"],
visibility = ["//visibility:public"],
)
diff --git a/motors/big/BUILD b/motors/big/BUILD
index 062828f..58fa295 100644
--- a/motors/big/BUILD
+++ b/motors/big/BUILD
@@ -1,12 +1,11 @@
load("//motors:macros.bzl", "hex_from_elf")
-load("//tools:environments.bzl", "mcu_cpus")
cc_binary(
name = "medium_salsa.elf",
srcs = [
"medium_salsa.cc",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
deps = [
":motor_controls",
"//motors:motor",
@@ -20,7 +19,7 @@
hex_from_elf(
name = "medium_salsa",
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
)
cc_library(
@@ -31,7 +30,7 @@
hdrs = [
"motor_controls.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
deps = [
"//motors:math",
"//motors:motor",
diff --git a/motors/core/BUILD b/motors/core/BUILD
index 092c540..d5e7cca 100644
--- a/motors/core/BUILD
+++ b/motors/core/BUILD
@@ -1,5 +1,3 @@
-load("//tools:environments.bzl", "mcu_cpus")
-
filegroup(
name = "linkerscripts",
srcs = [
@@ -23,7 +21,7 @@
"reg_debug.h",
"time.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
)
@@ -32,7 +30,7 @@
hdrs = [
"semihosting.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
"//third_party/GSL",
@@ -47,7 +45,7 @@
hdrs = [
"itm.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":core",
diff --git a/motors/deploy_joystick.sh b/motors/deploy_joystick.sh
index db0d855..b5af72e 100755
--- a/motors/deploy_joystick.sh
+++ b/motors/deploy_joystick.sh
@@ -1,4 +1,4 @@
#!/bin/bash
# Deploy to the driver station side of the pistol grip.
-bazel build --cpu=cortex-m4f -c opt //motors/pistol_grip:drivers_station.hex && bazel run //motors/teensy_loader_cli -- --mcu=mk64fx512 -s $(readlink -f bazel-bin/motors/pistol_grip/drivers_station.hex)
+bazel build --config=cortex-m4f -c opt //motors/pistol_grip:drivers_station.hex && bazel run //motors/teensy_loader_cli -- --mcu=mk64fx512 -s $(readlink -f bazel-bin/motors/pistol_grip/drivers_station.hex)
diff --git a/motors/fet12/BUILD b/motors/fet12/BUILD
index 5d25c41..ac9849b 100644
--- a/motors/fet12/BUILD
+++ b/motors/fet12/BUILD
@@ -1,5 +1,4 @@
load("//motors:macros.bzl", "hex_from_elf")
-load("//tools:environments.bzl", "mcu_cpus")
cc_binary(
name = "fet12.elf",
@@ -7,7 +6,7 @@
"current_equalization.h",
"fet12.cc",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
deps = [
":motor_controls",
"//motors:motor",
@@ -25,7 +24,7 @@
"current_equalization.h",
"fet12v2.cc",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
deps = [
":motor_controls",
"//motors:motor",
@@ -40,7 +39,7 @@
hex_from_elf(
name = "fet12",
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
)
cc_binary(
@@ -48,7 +47,7 @@
srcs = [
"power_wheels.cc",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
deps = [
"//motors:util",
"//motors/core",
@@ -60,7 +59,7 @@
hex_from_elf(
name = "power_wheels",
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
)
cc_library(
@@ -71,7 +70,7 @@
hdrs = [
"motor_controls.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
deps = [
"//motors:math",
"//motors:motor",
@@ -88,6 +87,7 @@
data = [
"@python_repo//:scipy",
],
+ target_compatible_with = ["@platforms//os:linux"],
)
py_binary(
@@ -99,6 +99,7 @@
":calib_sensors",
"@python_repo//:scipy",
],
+ target_compatible_with = ["@platforms//os:linux"],
)
genrule(
@@ -122,6 +123,6 @@
"$(location calib_data_6030c.csv)",
"> \"$@\"",
]),
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
tools = ["current_equalize"],
)
diff --git a/motors/macros.bzl b/motors/macros.bzl
index 6b15f00..0ff7c8d 100644
--- a/motors/macros.bzl
+++ b/motors/macros.bzl
@@ -1,4 +1,4 @@
-def hex_from_elf(name, restricted_to = None):
+def hex_from_elf(name, target_compatible_with = None):
native.genrule(
name = name,
srcs = ["%s.elf" % name],
@@ -6,6 +6,6 @@
cmd = "$(OBJCOPY) -O ihex $< $@",
executable = True,
output_to_bindir = True,
- restricted_to = restricted_to,
+ target_compatible_with = target_compatible_with,
toolchains = ["@bazel_tools//tools/cpp:current_cc_toolchain"],
)
diff --git a/motors/peripheral/BUILD b/motors/peripheral/BUILD
index c8b63e9..a42d502 100644
--- a/motors/peripheral/BUILD
+++ b/motors/peripheral/BUILD
@@ -1,5 +1,3 @@
-load("//tools:environments.bzl", "mcu_cpus")
-
cc_library(
name = "adc",
srcs = [
@@ -8,7 +6,7 @@
hdrs = [
"adc.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":configuration",
@@ -22,7 +20,7 @@
hdrs = [
"configuration.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
)
@@ -34,7 +32,7 @@
hdrs = [
"can.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
"//motors:util",
@@ -45,7 +43,6 @@
cc_library(
name = "uart_buffer",
hdrs = ["uart_buffer.h"],
- compatible_with = mcu_cpus,
visibility = ["//visibility:public"],
deps = [
"//third_party/GSL",
@@ -57,6 +54,7 @@
srcs = [
"uart_buffer_test.cc",
],
+ target_compatible_with = ["@platforms//os:linux"],
deps = [
":uart_buffer",
"//aos/testing:googletest",
@@ -67,7 +65,7 @@
name = "uart",
srcs = ["uart.cc"],
hdrs = ["uart.h"],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":uart_buffer",
@@ -82,7 +80,7 @@
name = "adc_dma",
srcs = ["adc_dma.cc"],
hdrs = ["adc_dma.h"],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":configuration",
@@ -95,7 +93,7 @@
name = "spi",
srcs = ["spi.cc"],
hdrs = ["spi.h"],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":uart_buffer",
diff --git a/motors/pistol_grip/BUILD b/motors/pistol_grip/BUILD
index d00404e..f12badb 100644
--- a/motors/pistol_grip/BUILD
+++ b/motors/pistol_grip/BUILD
@@ -1,12 +1,11 @@
load("//motors:macros.bzl", "hex_from_elf")
-load("//tools:environments.bzl", "mcu_cpus")
cc_binary(
name = "drivers_station.elf",
srcs = [
"drivers_station.cc",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
deps = [
"//motors:util",
"//motors/core",
@@ -21,7 +20,7 @@
hex_from_elf(
name = "drivers_station",
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
)
cc_binary(
@@ -35,10 +34,10 @@
"vtable_wheel0.cc",
"vtable_wheel1.cc",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
deps = [
":motor_controls",
- "//frc971/control_loops/drivetrain:haptic_input_uc",
+ "//frc971/control_loops/drivetrain:haptic_wheel",
"//motors:motor",
"//motors:util",
"//motors/core",
@@ -50,7 +49,7 @@
hex_from_elf(
name = "controller",
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
)
cc_binary(
@@ -58,7 +57,7 @@
srcs = [
"usb_forward.cc",
],
- restricted_to = ["//tools:k8"],
+ target_compatible_with = ["@platforms//cpu:x86_64"],
deps = [
# Don't add anything else here. :usb_forward_windows still has to build it
# without any other dependencies.
@@ -82,6 +81,7 @@
"$@",
]),
output_to_bindir = True,
+ target_compatible_with = ["@platforms//os:linux"],
tools = [
"usb_forward_windows_build.sh",
"@mingw_compiler//:all_files",
@@ -96,7 +96,7 @@
hdrs = [
"motor_controls.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
"//motors:math",
diff --git a/motors/print/BUILD b/motors/print/BUILD
index 26d8e45..df27ce2 100644
--- a/motors/print/BUILD
+++ b/motors/print/BUILD
@@ -1,11 +1,9 @@
-load("//tools:environments.bzl", "mcu_cpus")
-
cc_library(
name = "print",
hdrs = [
"print.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
"//aos/containers:sized_array",
@@ -22,7 +20,7 @@
hdrs = [
"uart.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":print",
@@ -39,7 +37,7 @@
hdrs = [
"itm.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":print",
@@ -55,7 +53,7 @@
hdrs = [
"semihosting.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":print",
@@ -71,7 +69,7 @@
hdrs = [
"usb.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":print",
diff --git a/motors/python/BUILD b/motors/python/BUILD
index 5eafc3a..4925d4c 100644
--- a/motors/python/BUILD
+++ b/motors/python/BUILD
@@ -7,7 +7,7 @@
"@python_repo//:scipy",
],
legacy_create_init = False,
- restricted_to = ["//tools:k8"],
+ target_compatible_with = ["@platforms//cpu:x86_64"],
deps = [
":python_init",
"//external:python-gflags",
@@ -23,7 +23,7 @@
"haptic_phase_current.py",
],
legacy_create_init = False,
- restricted_to = ["//tools:k8"],
+ target_compatible_with = ["@platforms//cpu:x86_64"],
deps = [
":python_init",
"//external:python-gflags",
@@ -35,6 +35,7 @@
py_library(
name = "python_init",
srcs = ["__init__.py"],
+ target_compatible_with = ["@platforms//os:linux"],
visibility = ["//visibility:public"],
deps = ["//motors:python_init"],
)
diff --git a/motors/seems_reasonable/BUILD b/motors/seems_reasonable/BUILD
index ccd4c36..a9eb95b 100644
--- a/motors/seems_reasonable/BUILD
+++ b/motors/seems_reasonable/BUILD
@@ -1,12 +1,10 @@
-load("//tools:environments.bzl", "mcu_cpus")
-
py_binary(
name = "drivetrain",
srcs = [
"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 +20,7 @@
"polydrivetrain.py",
],
legacy_create_init = False,
- restricted_to = ["//tools:k8"],
+ target_compatible_with = ["@platforms//cpu:x86_64"],
deps = [
":python_init",
"//external:python-gflags",
@@ -40,7 +38,7 @@
"kalman_drivetrain_motor_plant.cc",
],
cmd = "$(location :drivetrain) $(OUTS)",
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
tools = [
":drivetrain",
],
@@ -57,7 +55,7 @@
"hybrid_velocity_drivetrain.cc",
],
cmd = "$(location :polydrivetrain) $(OUTS)",
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
tools = [
":polydrivetrain",
],
@@ -74,11 +72,11 @@
"drivetrain_dog_motor_plant.h",
"polydrivetrain_dog_motor_plant.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
- "//frc971/control_loops:state_feedback_loop_uc",
- "//frc971/control_loops/drivetrain:polydrivetrain_uc",
+ "//frc971/control_loops:state_feedback_loop",
+ "//frc971/control_loops/drivetrain:polydrivetrain",
],
)
@@ -86,7 +84,6 @@
name = "spring",
srcs = ["spring.cc"],
hdrs = ["spring.h"],
- compatible_with = mcu_cpus,
visibility = ["//visibility:public"],
deps = ["//frc971/zeroing:wrap"],
)
@@ -96,6 +93,7 @@
srcs = [
"spring_test.cc",
],
+ target_compatible_with = ["@platforms//os:linux"],
deps = [
":spring",
"//aos/testing:googletest",
@@ -105,6 +103,7 @@
py_library(
name = "python_init",
srcs = ["__init__.py"],
+ target_compatible_with = ["@platforms//os:linux"],
visibility = ["//visibility:public"],
deps = ["//motors:python_init"],
)
diff --git a/motors/teensy_loader_cli/BUILD b/motors/teensy_loader_cli/BUILD
index eb68399..eea314c 100644
--- a/motors/teensy_loader_cli/BUILD
+++ b/motors/teensy_loader_cli/BUILD
@@ -7,7 +7,7 @@
"-DUSE_LIBUSB",
"-Wno-format-nonliteral",
],
- restricted_to = ["@//tools:k8"],
+ target_compatible_with = ["@platforms//cpu:x86_64"],
deps = [
"@libusb",
],
diff --git a/motors/usb/BUILD b/motors/usb/BUILD
index 3e92a16..1446e91 100644
--- a/motors/usb/BUILD
+++ b/motors/usb/BUILD
@@ -1,5 +1,3 @@
-load("//tools:environments.bzl", "mcu_cpus")
-
cc_library(
name = "legacy",
srcs = [
@@ -18,7 +16,7 @@
defines = [
"USB_SERIAL=1",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
"//motors/core",
@@ -33,7 +31,7 @@
hdrs = [
"usb.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":constants",
@@ -51,7 +49,7 @@
hdrs = [
"cdc.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":queue",
@@ -69,7 +67,7 @@
hdrs = [
"interrupt_out.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":usb",
@@ -86,7 +84,6 @@
hdrs = [
"queue.h",
],
- compatible_with = mcu_cpus,
)
cc_test(
@@ -94,6 +91,7 @@
srcs = [
"queue_test.cc",
],
+ target_compatible_with = ["@platforms//os:linux"],
deps = [
":queue",
"//aos/testing:googletest",
@@ -105,7 +103,6 @@
hdrs = [
"constants.h",
],
- compatible_with = mcu_cpus,
)
cc_test(
@@ -113,6 +110,7 @@
srcs = [
"constants_test.cc",
],
+ target_compatible_with = ["@platforms//os:linux"],
deps = [
":constants",
"//aos/testing:googletest",
@@ -127,7 +125,7 @@
hdrs = [
"hid.h",
],
- restricted_to = mcu_cpus,
+ target_compatible_with = ["@platforms//os:none"],
visibility = ["//visibility:public"],
deps = [
":usb",