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/third_party/flatbuffers/BUILD b/third_party/flatbuffers/BUILD
index 3114495..57f2b8e 100644
--- a/third_party/flatbuffers/BUILD
+++ b/third_party/flatbuffers/BUILD
@@ -1,11 +1,9 @@
-licenses(["notice"])
-
-load("@//tools:environments.bzl", "mcu_cpus")
-
package(
default_visibility = ["//visibility:public"],
)
+licenses(["notice"])
+
exports_files([
"LICENSE",
"tsconfig.json",
@@ -79,7 +77,6 @@
"include/flatbuffers/stl_emulation.h",
"include/flatbuffers/util.h",
],
- compatible_with = mcu_cpus,
linkstatic = 1,
strip_include_prefix = "/include",
)
diff --git a/third_party/flatbuffers/build_defs.bzl b/third_party/flatbuffers/build_defs.bzl
index f9c06f8..4462c8e 100644
--- a/third_party/flatbuffers/build_defs.bzl
+++ b/third_party/flatbuffers/build_defs.bzl
@@ -52,8 +52,10 @@
reflection_visibility = None,
compatible_with = None,
restricted_to = None,
+ target_compatible_with = None,
output_to_bindir = False):
- """Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler.
+ """Generates code files for reading/writing the given flatbuffers in the
+ requested language using the public compiler.
Args:
name: Rule name.
@@ -73,6 +75,8 @@
built for, in addition to default-supported environments.
restricted_to: Optional, The list of environments this rule can be built
for, instead of default-supported environments.
+ target_compatible_with: Optional, the list of constraints the target
+ platform must satisfy for this target to be considered compatible.
output_to_bindir: Passed to genrule for output to bin directory.
@@ -108,6 +112,7 @@
cmd = genrule_cmd,
compatible_with = compatible_with,
restricted_to = restricted_to,
+ target_compatible_with = target_compatible_with,
message = "Generating flatbuffer files for %s:" % (name),
)
if reflection_name:
@@ -135,6 +140,7 @@
tools = [flatc_path],
compatible_with = compatible_with,
restricted_to = restricted_to,
+ target_compatible_with = target_compatible_with,
cmd = reflection_genrule_cmd,
message = "Generating flatbuffer reflection binary for %s:" % (name),
)
@@ -157,6 +163,7 @@
visibility = None,
compatible_with = None,
restricted_to = None,
+ target_compatible_with = None,
srcs_filegroup_visibility = None,
gen_reflections = False):
'''A cc_library with the generated reader/writers for the given flatbuffer definitions.
@@ -176,6 +183,8 @@
(e.g. --gen-mutable).
visibility: The visibility of the generated cc_library. By default, use the
default visibility of the project.
+ target_compatible_with: Optional, the list of constraints the target
+ platform must satisfy for this target to be considered compatible.
srcs_filegroup_visibility: The visibility of the generated srcs filegroup.
By default, use the value of the visibility parameter above.
gen_reflections: Optional, if true this will generate the flatbuffer
@@ -239,6 +248,7 @@
includes = includes,
include_paths = include_paths,
flatc_args = flatc_args,
+ target_compatible_with = target_compatible_with,
compatible_with = compatible_with,
restricted_to = restricted_to,
reflection_name = reflection_name,
@@ -261,6 +271,7 @@
includes = [],
compatible_with = compatible_with,
restricted_to = restricted_to,
+ target_compatible_with = target_compatible_with,
linkstatic = 1,
visibility = visibility,
)
@@ -281,6 +292,7 @@
namespace,
tables,
compatible_with = None,
+ target_compatible_with = None,
includes = [],
include_paths = DEFAULT_INCLUDE_PATHS,
flatc_args = DEFAULT_FLATC_ARGS,
@@ -314,12 +326,14 @@
include_paths = include_paths,
flatc_args = flatc_args,
compatible_with = compatible_with,
+ target_compatible_with = target_compatible_with,
)
native.py_library(
name = name,
srcs = python_files,
visibility = visibility,
compatible_with = compatible_with,
+ target_compatible_with = target_compatible_with,
imports = ["."],
deps = ["@com_github_google_flatbuffers//:flatpy"],
)
@@ -328,6 +342,7 @@
name,
srcs,
compatible_with = None,
+ target_compatible_with = None,
includes = [],
include_paths = DEFAULT_INCLUDE_PATHS,
flatc_args = DEFAULT_FLATC_TS_ARGS,
@@ -350,12 +365,14 @@
include_paths = include_paths,
flatc_args = flatc_args,
compatible_with = compatible_with,
+ target_compatible_with = target_compatible_with,
)
ts_library(
name = name,
srcs = outs,
visibility = visibility,
compatible_with = compatible_with,
+ target_compatible_with = target_compatible_with,
deps = [
"@npm//@types",
],
diff --git a/third_party/flatbuffers/grpc/src/compiler/BUILD b/third_party/flatbuffers/grpc/src/compiler/BUILD
index d3ffd1f..12972c7 100644
--- a/third_party/flatbuffers/grpc/src/compiler/BUILD
+++ b/third_party/flatbuffers/grpc/src/compiler/BUILD
@@ -1,4 +1,3 @@
-
package(
default_visibility = ["//visibility:public"],
)
diff --git a/third_party/flatbuffers/src/BUILD b/third_party/flatbuffers/src/BUILD
index 41968b6..63f0426 100644
--- a/third_party/flatbuffers/src/BUILD
+++ b/third_party/flatbuffers/src/BUILD
@@ -2,7 +2,6 @@
default_visibility = ["//visibility:private"],
)
-
# Public flatc library to compile flatbuffer files at runtime.
cc_library(
name = "flatbuffers",
diff --git a/third_party/flatbuffers/tests/BUILD b/third_party/flatbuffers/tests/BUILD
index 203a08c..6fbda6b 100644
--- a/third_party/flatbuffers/tests/BUILD
+++ b/third_party/flatbuffers/tests/BUILD
@@ -14,13 +14,13 @@
"namespace_test/namespace_test2_generated.h",
"native_type_test_impl.cpp",
"native_type_test_impl.h",
+ "optional_scalars_generated.h",
"test.cpp",
"test_assert.cpp",
"test_assert.h",
"test_builder.cpp",
"test_builder.h",
"union_vector/union_vector_generated.h",
- "optional_scalars_generated.h",
],
copts = [
"-DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE",
@@ -43,6 +43,7 @@
":monsterdata_test.golden",
":monsterdata_test.json",
":native_type_test.fbs",
+ ":optional_scalars.fbs",
":prototest/imported.proto",
":prototest/test.golden",
":prototest/test.proto",
@@ -54,7 +55,6 @@
":unicode_test.json",
":union_vector/union_vector.fbs",
":union_vector/union_vector.json",
- ":optional_scalars.fbs",
],
includes = [
"",