Add convenience macros for rules_rust
Change-Id: I00fbe91fa2403aad344e5af964c1b7832c539f13
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/BUILD b/aos/BUILD
index 7724574..a887edc 100644
--- a/aos/BUILD
+++ b/aos/BUILD
@@ -1,9 +1,9 @@
-load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library", "flatbuffer_py_library", "flatbuffer_rust_library")
+load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library", "flatbuffer_py_library")
load("//aos/flatbuffers:generate.bzl", "static_flatbuffer")
load("@com_github_google_flatbuffers//:typescript.bzl", "flatbuffer_ts_library")
-load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("//aos:flatbuffers.bzl", "cc_static_flatbuffer")
load("//tools/build_rules:autocxx.bzl", "autocxx_library")
+load("//tools/rust:defs.bzl", "flatbuffer_rust_library", "rust_library", "rust_test")
exports_files(["aos_dump_autocomplete.sh"])
@@ -209,10 +209,6 @@
":init_for_rust",
],
override_cc_toolchain = "@llvm_toolchain//:cc-clang-x86_64-linux",
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
visibility = ["//visibility:public"],
deps = [
"@crate_index//:clap",
@@ -222,11 +218,6 @@
rust_test(
name = "init_rs_test",
crate = ":init_rs",
- rustc_flags = ["-Crelocation-model=static"],
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
)
autocxx_library(
@@ -238,10 +229,6 @@
"//aos/testing:tmpdir",
],
override_cc_toolchain = "@llvm_toolchain//:cc-clang-x86_64-linux",
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
visibility = ["//visibility:public"],
deps = [
":init_rs",
@@ -305,10 +292,6 @@
name = "configuration_rust_fbs",
srcs = ["configuration.fbs"],
crate_name = "aos_configuration_fbs",
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
visibility = ["//visibility:public"],
)
@@ -362,10 +345,6 @@
":configuration_fbs",
],
override_cc_toolchain = "@llvm_toolchain//:cc-clang-x86_64-linux",
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
visibility = ["//visibility:public"],
deps = [
":configuration_rust_fbs",
@@ -380,9 +359,6 @@
data = [
"//aos/testdata:test_configs",
],
- # TODO: Make Rust play happy with pic vs nopic. Details at:
- # https://github.com/bazelbuild/rules_rust/issues/118
- rustc_flags = ["-Crelocation-model=static"],
)
flatbuffer_ts_library(
@@ -404,10 +380,6 @@
name = "json_to_flatbuffer_rust_fbs",
srcs = ["json_to_flatbuffer.fbs"],
crate_name = "aos_json_to_flatbuffer_fbs",
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
visibility = ["//aos:__subpackages__"],
)
@@ -548,10 +520,6 @@
name = "flatbuffers_rs",
srcs = ["flatbuffers.rs"],
crate_name = "aos_flatbuffers",
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
visibility = ["//visibility:public"],
deps = [
"@com_github_google_flatbuffers//rust",
@@ -796,10 +764,6 @@
rs_deps = [
"@crate_index//:uuid",
],
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
visibility = ["//visibility:public"],
)
diff --git a/aos/events/BUILD b/aos/events/BUILD
index 75400ac..fdd8bb6 100644
--- a/aos/events/BUILD
+++ b/aos/events/BUILD
@@ -1,10 +1,9 @@
-load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_rust_library")
load("@com_github_google_flatbuffers//:typescript.bzl", "flatbuffer_ts_library")
load("//aos/flatbuffers:generate.bzl", "static_flatbuffer")
load("//aos:flatbuffers.bzl", "cc_static_flatbuffer")
load("//aos:config.bzl", "aos_config")
load("//tools/build_rules:autocxx.bzl", "autocxx_library")
-load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_doc", "rust_doc_test", "rust_library", "rust_test")
+load("//tools/rust:defs.bzl", "flatbuffer_rust_library", "rust_binary", "rust_doc", "rust_doc_test", "rust_library", "rust_test")
package(default_visibility = ["//visibility:public"])
@@ -46,19 +45,11 @@
flatbuffer_rust_library(
name = "ping_rust_fbs",
srcs = ["ping.fbs"],
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
)
flatbuffer_rust_library(
name = "pong_rust_fbs",
srcs = ["pong.fbs"],
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
)
static_flatbuffer(
@@ -165,10 +156,6 @@
"@crate_index//:futures",
"@crate_index//:thiserror",
],
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
visibility = ["//visibility:public"],
deps = [
"//aos:configuration_rs",
@@ -202,10 +189,6 @@
":ping_rust_fbs",
":pong_rust_fbs",
],
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
)
cc_test(
@@ -268,11 +251,6 @@
# a rust test crashes inside of C++, the output gets captured which makes
# it pretty much impossible to figure out what happened.
env = {"RUST_TEST_NOCAPTURE": "1"},
- rustc_flags = ["-Crelocation-model=static"],
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
deps = [
":event_loop_runtime",
":ping_lib_rs",
@@ -298,11 +276,6 @@
data = [
":pingpong_config",
],
- rustc_flags = ["-Crelocation-model=static"],
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
deps = [
":ping_lib_rs",
":shm_event_loop_rs",
@@ -337,11 +310,6 @@
data = [
":pingpong_config",
],
- rustc_flags = ["-Crelocation-model=static"],
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
deps = [
":pong_lib_rs",
":shm_event_loop_rs",
@@ -668,9 +636,6 @@
data = [
":multinode_pingpong_test_combined_config",
],
- # TODO: Make Rust play happy with pic vs nopic. Details at:
- # https://github.com/bazelbuild/rules_rust/issues/118
- rustc_flags = ["-Crelocation-model=static"],
deps = [
":ping_rust_fbs",
"//aos:test_init_rs",
@@ -693,10 +658,6 @@
"//aos:configuration_rust_fbs",
"//aos:flatbuffers_rs",
],
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
visibility = ["//visibility:public"],
deps = [
":event_loop_runtime",
@@ -714,13 +675,6 @@
name = "shm_event_loop_rs_test",
crate = ":shm_event_loop_rs",
data = [":pingpong_config"],
- # TODO: Make Rust play happy with pic vs nopic. Details at:
- # https://github.com/bazelbuild/rules_rust/issues/118
- rustc_flags = ["-Crelocation-model=static"],
- target_compatible_with = select({
- "//conditions:default": ["//tools/platforms/rust:has_support"],
- "//tools:has_msan": ["@platforms//:incompatible"],
- }),
deps = [
":ping_rust_fbs",
"//aos:test_init_rs",
diff --git a/tools/build_rules/autocxx.bzl b/tools/build_rules/autocxx.bzl
index 6cb74de..c17c5e2 100644
--- a/tools/build_rules/autocxx.bzl
+++ b/tools/build_rules/autocxx.bzl
@@ -1,4 +1,4 @@
-load("@rules_rust//rust:defs.bzl", "rust_library")
+load("@org_frc971//tools/rust:defs.bzl", "rust_library")
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
@@ -241,7 +241,7 @@
def autocxx_library(
name,
visibility = None,
- target_compatible_with = None,
+ target_compatible_with = ["//tools/platforms/rust:has_support"],
libs = [],
srcs = [],
cxxbridge_srcs = [],
diff --git a/tools/rust/defs.bzl b/tools/rust/defs.bzl
new file mode 100644
index 0000000..9c17d93
--- /dev/null
+++ b/tools/rust/defs.bzl
@@ -0,0 +1,64 @@
+load(
+ "@rules_rust//rust:defs.bzl",
+ _rust_binary = "rust_binary",
+ _rust_doc = "rust_doc",
+ _rust_doc_test = "rust_doc_test",
+ _rust_library = "rust_library",
+ _rust_test = "rust_test",
+)
+load("@com_github_google_flatbuffers//:build_defs.bzl", _flatbuffer_rust_library = "flatbuffer_rust_library")
+
+def rust_binary(target_compatible_with = ["//tools/platforms/rust:has_support"], rustc_flags = [], **kwargs):
+ _rust_binary(
+ target_compatible_with = select({
+ Label("//conditions:default"): target_compatible_with,
+ Label("//tools:has_msan"): ["@platforms//:incompatible"],
+ }),
+ # TODO: Make Rust play happy with pic vs nopic. Details at:
+ # https://github.com/bazelbuild/rules_rust/issues/118
+ rustc_flags = rustc_flags + ["-Crelocation-model=static"],
+ **kwargs
+ )
+
+def rust_library(target_compatible_with = ["//tools/platforms/rust:has_support"], **kwargs):
+ _rust_library(
+ target_compatible_with = select({
+ Label("//conditions:default"): target_compatible_with,
+ Label("//tools:has_msan"): ["@platforms//:incompatible"],
+ }),
+ **kwargs
+ )
+
+def rust_test(target_compatible_with = ["//tools/platforms/rust:has_support"], rustc_flags = [], **kwargs):
+ _rust_test(
+ target_compatible_with = select({
+ Label("//conditions:default"): target_compatible_with,
+ Label("//tools:has_msan"): ["@platforms//:incompatible"],
+ }),
+ rustc_flags = rustc_flags + ["-Crelocation-model=static"],
+ **kwargs
+ )
+
+def rust_doc_test(target_compatible_with = ["//tools/platforms/rust:has_support"], tags = [], **kwargs):
+ # TODO(james): Attempting to execute this remotely results
+ # in complaints about overly large files.
+ _rust_doc_test(
+ tags = tags + ["no-remote-exec"],
+ target_compatible_with = target_compatible_with,
+ **kwargs
+ )
+
+def rust_doc(target_compatible_with = ["//tools/platforms/rust:has_support"], **kwargs):
+ _rust_doc(
+ target_compatible_with = target_compatible_with,
+ **kwargs
+ )
+
+def flatbuffer_rust_library(target_compatible_with = ["//tools/platforms/rust:has_support"], **kwargs):
+ _flatbuffer_rust_library(
+ target_compatible_with = select({
+ Label("//conditions:default"): target_compatible_with,
+ Label("//tools:has_msan"): ["@platforms//:incompatible"],
+ }),
+ **kwargs
+ )