From 2ddf1b11e9d9f149881682a578cbee39dc237109 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sat, 19 Oct 2024 17:06:19 -0400 Subject: [PATCH 1/4] [bazel] MVP for building wpilibc --- .bazelrc | 2 + WORKSPACE | 52 +++++++++ apriltag/BUILD.bazel | 112 +++++++++++++++++++ cameraserver/BUILD.bazel | 29 ++++- cscore/BUILD.bazel | 89 +++++++++++++++ epilogue-processor/BUILD.bazel | 22 ++++ epilogue-runtime/BUILD.bazel | 12 ++ fieldImages/BUILD.bazel | 31 +++++ protoplugin/BUILD.bazel | 27 +++++ protoplugin/bazel_proto_generator.py | 38 +++++++ protoplugin/wpi_proto_library.bzl | 41 +++++++ romiVendordep/BUILD.bazel | 53 +++++++++ shared/bazel/compiler_flags/osx_flags.rc | 3 + shared/bazel/compiler_flags/roborio_flags.rc | 2 + upstream_utils/protobuf_patches/BUILD.bazel | 0 wpilibNewCommands/BUILD.bazel | 87 ++++++++++++++ wpilibc/BUILD.bazel | 80 +++++++++++++ wpilibcIntegrationTests/BUILD.bazel | 24 ++++ wpimath/BUILD.bazel | 104 +++++++++++++++++ xrpVendordep/BUILD.bazel | 54 +++++++++ 20 files changed, 861 insertions(+), 1 deletion(-) create mode 100644 apriltag/BUILD.bazel create mode 100644 epilogue-processor/BUILD.bazel create mode 100644 epilogue-runtime/BUILD.bazel create mode 100644 fieldImages/BUILD.bazel create mode 100644 protoplugin/BUILD.bazel create mode 100755 protoplugin/bazel_proto_generator.py create mode 100644 protoplugin/wpi_proto_library.bzl create mode 100644 romiVendordep/BUILD.bazel create mode 100644 upstream_utils/protobuf_patches/BUILD.bazel create mode 100644 wpilibNewCommands/BUILD.bazel create mode 100644 wpilibc/BUILD.bazel create mode 100644 wpilibcIntegrationTests/BUILD.bazel create mode 100644 xrpVendordep/BUILD.bazel diff --git a/.bazelrc b/.bazelrc index 051ff924bd8..d01d1768521 100644 --- a/.bazelrc +++ b/.bazelrc @@ -8,6 +8,8 @@ build --java_runtime_version=roboriojdk_17 build --tool_java_language_version=17 build --tool_java_runtime_version=remotejdk_17 +build --proto_toolchain_for_cc=//:proto_cc_toolchain + test --test_output=errors test --test_verbose_timeout_warnings diff --git a/WORKSPACE b/WORKSPACE index 602b2ed4297..60447ae2344 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -98,3 +98,55 @@ setup_legacy_bzlmodrio_opencv_cpp_dependencies() load("@bzlmodrio-opencv//:maven_java_deps.bzl", "setup_legacy_bzlmodrio_opencv_java_dependencies") setup_legacy_bzlmodrio_opencv_java_dependencies() + +http_archive( + name = "com_google_protobuf", + patch_args = ["-p1"], + patches = [ + "//upstream_utils/protobuf_patches:0001-Fix-sign-compare-warnings.patch", + "//upstream_utils/protobuf_patches:0002-Remove-redundant-move.patch", + "//upstream_utils/protobuf_patches:0003-Fix-maybe-uninitialized-warnings.patch", + "//upstream_utils/protobuf_patches:0004-Fix-coded_stream-WriteRaw.patch", + "//upstream_utils/protobuf_patches:0005-Suppress-enum-enum-conversion-warning.patch", + "//upstream_utils/protobuf_patches:0006-Fix-noreturn-function-returning.patch", + "//upstream_utils/protobuf_patches:0007-Work-around-GCC-12-restrict-warning-compiler-bug.patch", + "//upstream_utils/protobuf_patches:0008-Disable-MSVC-switch-warning.patch", + "//upstream_utils/protobuf_patches:0009-Disable-unused-function-warning.patch", + "//upstream_utils/protobuf_patches:0010-Disable-pedantic-warning.patch", + "//upstream_utils/protobuf_patches:0011-Avoid-use-of-sprintf.patch", + ], + sha256 = "f7042d540c969b00db92e8e1066a9b8099c8379c33f40f360eb9e1d98a36ca26", + strip_prefix = "protobuf-3.21.12", + urls = [ + "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.21.12.zip", + ], +) + +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") + +protobuf_deps() + +# Rules Python +http_archive( + name = "rules_python", + sha256 = "c68bdc4fbec25de5b5493b8819cfc877c4ea299c0dcb15c244c5a00208cde311", + strip_prefix = "rules_python-0.31.0", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.31.0/rules_python-0.31.0.tar.gz", +) + +load("@rules_python//python:repositories.bzl", "py_repositories") + +py_repositories() + +http_archive( + name = "build_bazel_apple_support", + sha256 = "c4bb2b7367c484382300aee75be598b92f847896fb31bbd22f3a2346adf66a80", + url = "https://github.com/bazelbuild/apple_support/releases/download/1.15.1/apple_support.1.15.1.tar.gz", +) + +load( + "@build_bazel_apple_support//lib:repositories.bzl", + "apple_support_dependencies", +) + +apple_support_dependencies() diff --git a/apriltag/BUILD.bazel b/apriltag/BUILD.bazel new file mode 100644 index 00000000000..ea1ef1abe00 --- /dev/null +++ b/apriltag/BUILD.bazel @@ -0,0 +1,112 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") +load("@rules_java//java:defs.bzl", "java_binary", "java_library") +load("@rules_python//python:defs.bzl", "py_binary") +load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources") + +cc_library( + name = "thirdparty-apriltag", + srcs = glob(["src/main/native/thirdparty/apriltag/src/**"]), + hdrs = glob(["src/main/native/thirdparty/apriltag/include/**"]), + copts = select({ + "@bazel_tools//src/conditions:darwin": [ + "-Wno-format-nonliteral", + "-Wno-gnu-zero-variadic-macro-arguments", + "-Wno-uninitialized", + "-Wno-sign-compare", + "-Wno-type-limits", + ], + "@bazel_tools//src/conditions:windows": [ + "/wd4005", + "/wd4018", + "/wd4244", + "/wd4267", + "/wd4996", + ], + "@rules_bzlmodrio_toolchains//constraints/combined:is_linux": [ + "-Wno-format-nonliteral", + "-Wno-maybe-uninitialized", + "-Wno-sign-compare", + "-Wno-type-limits", + ], + }), + includes = ["src/main/native/thirdparty/apriltag/include/common"], + strip_include_prefix = "src/main/native/thirdparty/apriltag/include", + visibility = ["//visibility:public"], +) + +generate_resources( + name = "generate-resources", + namespace = "frc", + prefix = "APRILTAG", + resource_files = glob(["src/main/native/resources/**"]), + visibility = ["//visibility:public"], +) + +cc_library( + name = "apriltag.static", + srcs = [":generate-resources"] + glob( + ["src/main/native/cpp/**"], + exclude = ["src/main/native/cpp/jni/**"], + ), + hdrs = glob(["src/main/native/include/**/*"]), + defines = ["WPILIB_EXPORTS"], + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + ":thirdparty-apriltag", + "//wpimath:wpimath.static", + "//wpiutil:wpiutil.static", + ], +) + +java_library( + name = "apriltag-java", + srcs = glob(["src/main/java/**/*.java"]), + resource_strip_prefix = "apriltag/src/main/native/resources", + resources = glob(["src/main/native/resources/**"]), + visibility = ["//visibility:public"], + deps = [ + "//wpimath:wpimath-java", + "//wpiutil:wpiutil-java", + "@bzlmodrio-opencv//libraries/java/opencv", + "@maven//:com_fasterxml_jackson_core_jackson_annotations", + "@maven//:com_fasterxml_jackson_core_jackson_core", + "@maven//:com_fasterxml_jackson_core_jackson_databind", + ], +) + +cc_test( + name = "apriltag-cpp-test", + size = "small", + srcs = glob(["src/test/native/cpp/**"]), + tags = [ + "no-asan", + ], + deps = [ + ":apriltag.static", + "//thirdparty/googletest:googletest.static", + ], +) + +cc_binary( + name = "DevMain-Cpp", + srcs = ["src/dev/native/cpp/main.cpp"], + deps = [ + ":apriltag.static", + ], +) + +java_binary( + name = "DevMain-Java", + srcs = ["src/dev/java/edu/wpi/first/apriltag/DevMain.java"], + main_class = "edu.wpi.first.apriltag.DevMain", + deps = [ + ":apriltag-java", + ], +) + +py_binary( + name = "convert_apriltag_layouts", + srcs = ["convert_apriltag_layouts.py"], + tags = ["manual"], +) diff --git a/cameraserver/BUILD.bazel b/cameraserver/BUILD.bazel index 542f0f3c961..73995c01353 100644 --- a/cameraserver/BUILD.bazel +++ b/cameraserver/BUILD.bazel @@ -1,6 +1,22 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") load("@rules_java//java:defs.bzl", "java_binary", "java_library") +cc_library( + name = "cameraserver.static", + srcs = glob(["src/main/native/cpp/**"]), + hdrs = glob(["src/main/native/include/**/*"]), + includes = [ + "cpp", + "src/main/native/include", + ], + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + "//cscore:cscore.static", + "//ntcore:ntcore.static", + ], +) + java_library( name = "cameraserver-java", srcs = glob(["src/main/java/**/*.java"]), @@ -16,10 +32,21 @@ java_library( ], ) +cc_test( + name = "cameraserver-cpp-test", + size = "small", + srcs = glob(["src/test/native/**"]), + deps = [ + ":cameraserver.static", + "//thirdparty/googletest:googletest.static", + ], +) + cc_binary( name = "DevMain-Cpp", srcs = ["src/dev/native/cpp/main.cpp"], deps = [ + ":cameraserver.static", ], ) diff --git a/cscore/BUILD.bazel b/cscore/BUILD.bazel index a2470f8afe1..d40fb4d2fd9 100644 --- a/cscore/BUILD.bazel +++ b/cscore/BUILD.bazel @@ -1,5 +1,76 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library") load("@rules_java//java:defs.bzl", "java_binary", "java_library") +WIN_SRCS = glob([ + "src/main/native/windows/**/*.cpp", + "src/main/native/windows/**/*.h", +]) + +LINUX_SRCS = glob([ + "src/main/native/linux/**/*.cpp", + "src/main/native/linux/**/*.h", +]) + +MAC_SRCS = glob(["src/main/native/osx/**/*.cpp"]) + +filegroup( + name = "native-srcs", + srcs = select({ + "@bazel_tools//src/conditions:darwin": MAC_SRCS, + "@bazel_tools//src/conditions:windows": WIN_SRCS, + "@rules_bzlmodrio_toolchains//constraints/combined:is_linux": LINUX_SRCS, + }), +) + +objc_library( + name = "cscore-mac", + srcs = glob([ + "src/main/native/objcpp/**/*.mm", + "src/main/native/cpp/*.h", + ]), + hdrs = glob([ + "src/main/native/include/**/*", + "src/main/native/objcpp/**/*.h", + ]), + copts = [ + "-std=c++20", + ], + includes = [ + "src/main/native/cpp", + "src/main/native/include", + "src/main/native/objcpp", + ], + tags = ["manual"], + deps = [ + "//wpinet:wpinet.static", + "//wpiutil:wpiutil.static", + "@bzlmodrio-opencv//libraries/cpp/opencv", + ], +) + +cc_library( + name = "cscore.static", + srcs = [":native-srcs"] + glob( + ["src/main/native/cpp/**"], + exclude = ["src/main/native/cpp/jni/**"], + ), + hdrs = glob(["src/main/native/include/**/*"]), + includes = [ + "src/main/native/cpp", + "src/main/native/include", + ], + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + "//wpinet:wpinet.static", + "//wpiutil:wpiutil.static", + "@bzlmodrio-opencv//libraries/cpp/opencv", + ] + select({ + "@bazel_tools//src/conditions:darwin": [":cscore-mac"], + "//conditions:default": [], + }), +) + java_library( name = "cscore-java", srcs = glob(["src/main/java/**/*.java"]), @@ -10,6 +81,24 @@ java_library( ], ) +cc_test( + name = "cscore-cpp-test", + size = "small", + srcs = glob(["src/test/native/**"]), + deps = [ + ":cscore.static", + "//thirdparty/googletest:googletest.static", + ], +) + +cc_binary( + name = "DevMain-Cpp", + srcs = ["src/dev/native/cpp/main.cpp"], + deps = [ + ":cscore.static", + ], +) + java_binary( name = "DevMain-Java", srcs = ["src/dev/java/edu/wpi/first/cscore/DevMain.java"], diff --git a/epilogue-processor/BUILD.bazel b/epilogue-processor/BUILD.bazel new file mode 100644 index 00000000000..a9a8e083ab4 --- /dev/null +++ b/epilogue-processor/BUILD.bazel @@ -0,0 +1,22 @@ +load("@rules_java//java:defs.bzl", "java_library", "java_plugin") + +java_library( + name = "processor", + srcs = glob(["src/main/java/**/*.java"]), + visibility = ["//visibility:public"], + runtime_deps = [ + "//wpilibNewCommands:wpilibNewCommands-java", + ], + deps = [ + "//epilogue-runtime:epilogue", + ], +) + +java_plugin( + name = "plugin", + processor_class = "edu.wpi.first.epilogue.processor.AnnotationProcessor", + visibility = ["//visibility:public"], + deps = [ + ":processor", + ], +) diff --git a/epilogue-runtime/BUILD.bazel b/epilogue-runtime/BUILD.bazel new file mode 100644 index 00000000000..05db6b75270 --- /dev/null +++ b/epilogue-runtime/BUILD.bazel @@ -0,0 +1,12 @@ +load("@rules_java//java:defs.bzl", "java_library") + +java_library( + name = "epilogue", + srcs = glob(["src/main/java/**/*.java"]), + visibility = ["//visibility:public"], + deps = [ + "//ntcore:networktables-java", + "//wpiunits", + "//wpiutil:wpiutil-java", + ], +) diff --git a/fieldImages/BUILD.bazel b/fieldImages/BUILD.bazel new file mode 100644 index 00000000000..b5cfc82cfa4 --- /dev/null +++ b/fieldImages/BUILD.bazel @@ -0,0 +1,31 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_java//java:defs.bzl", "java_library") +load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources") + +generate_resources( + name = "generate-resources", + namespace = "fields", + prefix = "FIELDS", + resource_files = glob(["src/main/native/resources/**"]), + visibility = ["//visibility:public"], +) + +cc_library( + name = "fieldImages", + srcs = [":generate-resources"] + glob(["src/main/native/cpp/**"]), + hdrs = glob(["src/main/native/include/**/*"]), + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], +) + +java_library( + name = "fieldImages-java", + srcs = glob(["src/main/java/**/*.java"]), + resource_strip_prefix = "fieldImages/src/main/native/resources", + resources = glob(["src/main/native/resources/**"]), + visibility = ["//visibility:public"], + deps = [ + "@maven//:com_fasterxml_jackson_core_jackson_annotations", + "@maven//:com_fasterxml_jackson_core_jackson_databind", + ], +) diff --git a/protoplugin/BUILD.bazel b/protoplugin/BUILD.bazel new file mode 100644 index 00000000000..d9548cc3483 --- /dev/null +++ b/protoplugin/BUILD.bazel @@ -0,0 +1,27 @@ +load("@rules_java//java:defs.bzl", "java_binary", "java_import") +load("@rules_python//python:defs.bzl", "py_binary") + +java_import( + name = "binary", + jars = ["binary/wpiprotoplugin.jar"], +) + +java_binary( + name = "wpi_proto_plugin", + main_class = "org.wpilib.ProtoCDllGenerator", + runtime_deps = [ + ":binary", + ], +) + +py_binary( + name = "bazel_proto_generator", + srcs = ["bazel_proto_generator.py"], + data = [ + ":wpi_proto_plugin", + "@com_google_protobuf//:protoc", + ], + tags = ["manual"], + visibility = ["//visibility:public"], + deps = ["@rules_python//python/runfiles"], +) diff --git a/protoplugin/bazel_proto_generator.py b/protoplugin/bazel_proto_generator.py new file mode 100755 index 00000000000..8bec033eb8f --- /dev/null +++ b/protoplugin/bazel_proto_generator.py @@ -0,0 +1,38 @@ +from python.runfiles import Runfiles +import argparse +import subprocess +import os + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--include_prefix", required=True) + parser.add_argument("--proto_files", nargs="+") + parser.add_argument("--output_files", nargs="+") + + args = parser.parse_args() + assert len(args.proto_files) * 2 == len(args.output_files) + + r = Runfiles.Create() + if os.name == "nt": + protoc = r.Rlocation("com_google_protobuf/protoc.exe") + plugin = r.Rlocation("__main__/protoplugin/wpi_proto_plugin.exe") + else: + protoc = r.Rlocation("com_google_protobuf/protoc") + plugin = r.Rlocation("__main__/protoplugin/wpi_proto_plugin") + + output_directory = os.path.dirname(args.output_files[0]) + + cmd = [] + cmd.append(protoc) + cmd.append(f"--cpp_out={output_directory}") + cmd.append(f"-I{args.include_prefix}") + cmd.append(f"--wpilib_out={output_directory}") + cmd.append(f"--plugin=protoc-gen-wpilib={plugin}") + cmd.extend(args.proto_files) + + subprocess.check_call(cmd) + + +if __name__ == "__main__": + main() diff --git a/protoplugin/wpi_proto_library.bzl b/protoplugin/wpi_proto_library.bzl new file mode 100644 index 00000000000..7ff922f2a4b --- /dev/null +++ b/protoplugin/wpi_proto_library.bzl @@ -0,0 +1,41 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +def wpi_proto_library( + name, + proto_files, + include_prefix): + gen_srcs = [] + gen_hdrs = [] + + for pf in proto_files: + gen_srcs.append("generated_proto/" + pf[:-5] + "pb.cc") + gen_hdrs.append("generated_proto/" + pf[:-5] + "pb.h") + + cmd = "$(locations //protoplugin:bazel_proto_generator) --include_prefix={} --proto_files $(SRCS) --output_files $(OUTS)".format(include_prefix) + native.genrule( + name = "generate_proto", + srcs = proto_files, + outs = gen_srcs + gen_hdrs, + cmd = cmd, + tools = [ + "//protoplugin:bazel_proto_generator", + ], + visibility = ["//visibility:public"], + ) + + native.filegroup( + name = name + ".srcs", + srcs = gen_srcs, + ) + + native.filegroup( + name = name + ".hdr_files", + srcs = gen_hdrs, + ) + + cc_library( + name = name + ".hdrs", + hdrs = gen_hdrs, + includes = ["generated_proto/src/main/proto"], + visibility = ["//visibility:public"], + ) diff --git a/romiVendordep/BUILD.bazel b/romiVendordep/BUILD.bazel new file mode 100644 index 00000000000..7cc0913b6e7 --- /dev/null +++ b/romiVendordep/BUILD.bazel @@ -0,0 +1,53 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") +load("@rules_java//java:defs.bzl", "java_binary", "java_library") + +cc_library( + name = "romi-cpp.static", + srcs = glob([ + "src/main/native/cpp/**", + ]), + hdrs = glob(["src/main/native/include/**"]), + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + "//wpilibc:wpilibc.static", + ], +) + +java_library( + name = "romi-java", + srcs = glob(["src/main/java/**/*.java"]), + visibility = ["//visibility:public"], + deps = [ + "//hal:hal-java", + "//wpilibj", + ], +) + +cc_test( + name = "romi-test", + size = "small", + srcs = glob(["src/test/native/cpp/**"]), + deps = [ + "//thirdparty/googletest:googletest.static", + ], +) + +cc_binary( + name = "DevMain-Cpp", + srcs = ["src/dev/native/cpp/main.cpp"], + deps = [ + ":romi-cpp.static", + ], +) + +java_binary( + name = "DevMain-Java", + srcs = ["src/dev/java/edu/wpi/first/wpilibj/romi/DevMain.java"], + main_class = "edu.wpi.first.wpilibj.romi.DevMain", + deps = [ + "//hal:hal-java", + "//ntcore:networktables-java", + "//wpiutil:wpiutil-java", + ], +) diff --git a/shared/bazel/compiler_flags/osx_flags.rc b/shared/bazel/compiler_flags/osx_flags.rc index da12307993e..b152a181f84 100644 --- a/shared/bazel/compiler_flags/osx_flags.rc +++ b/shared/bazel/compiler_flags/osx_flags.rc @@ -42,3 +42,6 @@ build:macos --linkopt=-Wl,-rpath,'@loader_path'" # Things not in nativetools build:macos --copt=-Wno-shorten-64-to-32 + +build:macos --host_per_file_copt=external/zlib/.*\.c@-Wno-deprecated-non-prototype +build:macos --host_per_file_copt=external/com_google_protobuf/.*\.cc@-Wno-unused-function \ No newline at end of file diff --git a/shared/bazel/compiler_flags/roborio_flags.rc b/shared/bazel/compiler_flags/roborio_flags.rc index 691da8d5e6e..4be54159474 100644 --- a/shared/bazel/compiler_flags/roborio_flags.rc +++ b/shared/bazel/compiler_flags/roborio_flags.rc @@ -14,3 +14,5 @@ build:roborio --cxxopt=-Wno-error=deprecated-declarations # Extra 11 build:roborio --cxxopt=-Wno-error=deprecated-enum-enum-conversion + +build:roborio --host_per_file_copt=external/zlib/.*\.c@-Wno-deprecated-non-prototype \ No newline at end of file diff --git a/upstream_utils/protobuf_patches/BUILD.bazel b/upstream_utils/protobuf_patches/BUILD.bazel new file mode 100644 index 00000000000..e69de29bb2d diff --git a/wpilibNewCommands/BUILD.bazel b/wpilibNewCommands/BUILD.bazel new file mode 100644 index 00000000000..6add11137ad --- /dev/null +++ b/wpilibNewCommands/BUILD.bazel @@ -0,0 +1,87 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") +load("@rules_java//java:defs.bzl", "java_binary", "java_library") + +cc_library( + name = "generated_cc_headers", + hdrs = glob(["src/generated/main/native/include/**"]), + includes = ["src/generated/main/native/include"], + strip_include_prefix = "src/generated/main/native/include", + visibility = ["//wpilibNewCommands:__subpackages__"], +) + +filegroup( + name = "generated_cc_source", + srcs = glob(["src/generated/main/native/cpp/**"]), + visibility = ["//wpilibNewCommands:__subpackages__"], +) + +filegroup( + name = "generated_java", + srcs = glob(["src/generated/main/java/**/*.java"]), + visibility = ["//wpilibNewCommands:__subpackages__"], +) + +cc_library( + name = "wpilibNewCommands.static", + srcs = glob(["src/main/native/cpp/**"]) + [":generated_cc_source"], + hdrs = glob(["src/main/native/include/**"]), + includes = ["src/main/native/include"], + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + ":generated_cc_headers", + "//wpilibc:wpilibc.static", + ], +) + +java_library( + name = "wpilibNewCommands-java", + srcs = glob(["src/main/java/**/*.java"]) + [":generated_java"], + visibility = ["//visibility:public"], + deps = [ + "//cscore:cscore-java", + "//hal:hal-java", + "//ntcore:networktables-java", + "//wpilibj", + "//wpimath:wpimath-java", + "//wpinet:wpinet-java", + "//wpiunits", + "//wpiutil:wpiutil-java", + ], +) + +cc_test( + name = "wpilibNewCommands-cpp-test", + size = "small", + srcs = glob([ + "src/test/native/**/*.cpp", + "src/test/native/**/*.h", + ]), + tags = [ + "no-tsan", + "no-ubsan", + ], + deps = [ + ":wpilibNewCommands.static", + "//thirdparty/googletest:googletest.static", + ], +) + +cc_binary( + name = "DevMain-Cpp", + srcs = ["src/dev/native/cpp/main.cpp"], + deps = [ + ], +) + +java_binary( + name = "DevMain-Java", + srcs = ["src/dev/java/edu/wpi/first/wpilibj2/commands/DevMain.java"], + main_class = "edu.wpi.first.wpilibj2.commands.DevMain", + deps = [ + "//hal:hal-java", + "//ntcore:networktables-java", + "//wpimath:wpimath-java", + "//wpiutil:wpiutil-java", + ], +) diff --git a/wpilibc/BUILD.bazel b/wpilibc/BUILD.bazel new file mode 100644 index 00000000000..c11298d3d57 --- /dev/null +++ b/wpilibc/BUILD.bazel @@ -0,0 +1,80 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") +load("//shared/bazel/rules/gen:gen-version-file.bzl", "generate_version_file") + +generate_version_file( + name = "generate-version", + output_file = "WPILibVersion.cpp", + template = "src/generate/WPILibVersion.cpp.in", + visibility = ["//wpilibc:__subpackages__"], +) + +cc_library( + name = "generated_cc_headers", + hdrs = glob(["src/generated/main/native/include/**"]), + includes = ["src/generated/main/native/include"], + strip_include_prefix = "src/generated/main/native/include", + visibility = ["//wpilibc:__subpackages__"], +) + +filegroup( + name = "generated_cc_source", + srcs = glob( + ["src/generated/main/native/cpp/**"], + exclude = ["src/generated/main/native/cpp/jni/**"], + ), + visibility = ["//wpilibc:__subpackages__"], +) + +cc_library( + name = "wpilibc.static", + srcs = [ + ":generate-version", + ] + glob([ + "src/main/native/cppcs/**", + "src/main/native/cpp/**", + ]) + [":generated_cc_source"], + hdrs = glob(["src/main/native/include/**"]), + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + ":generated_cc_headers", + "//cameraserver:cameraserver.static", + "//cscore:cscore.static", + "//hal:wpiHal.static", + "//ntcore:ntcore.static", + "//wpimath:wpimath.static", + "//wpinet:wpinet.static", + "//wpiutil:wpiutil.static", + ], +) + +cc_library( + name = "test-headers", + testonly = True, + hdrs = glob(["src/test/native/include/**"]), + includes = ["src/test/native/include"], +) + +cc_test( + name = "wpilibc-test", + size = "small", + srcs = glob(["src/test/native/cpp/**"]), + tags = [ + "no-asan", + "no-tsan", + "no-ubsan", + ], + deps = [ + ":test-headers", + ":wpilibc.static", + "//thirdparty/googletest:googletest.static", + ], +) + +cc_binary( + name = "DevMain-Cpp", + srcs = ["src/dev/native/cpp/main.cpp"], + deps = [ + ":wpilibc.static", + ], +) diff --git a/wpilibcIntegrationTests/BUILD.bazel b/wpilibcIntegrationTests/BUILD.bazel new file mode 100644 index 00000000000..c67b2dd969b --- /dev/null +++ b/wpilibcIntegrationTests/BUILD.bazel @@ -0,0 +1,24 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") + +ATHENA_SOURCES = glob(["src/main/native/cpp/**"]) + +NON_ATHENA_SOURCES = glob(["src/main/native/dt/**"]) + +cc_library( + name = "test_headers", + hdrs = glob(["src/main/native/include/**"]), + strip_include_prefix = "src/main/native/include", +) + +cc_binary( + name = "wpilibcIntegrationTests", + srcs = select({ + "@rules_bzlmodrio_toolchains//constraints/is_roborio:roborio": ATHENA_SOURCES, + "//conditions:default": NON_ATHENA_SOURCES, + }), + deps = [ + ":test_headers", + "//thirdparty/googletest:googletest.static", + "//wpilibc:wpilibc.static", + ], +) diff --git a/wpimath/BUILD.bazel b/wpimath/BUILD.bazel index 2f650293fdb..e15c79e5ea3 100644 --- a/wpimath/BUILD.bazel +++ b/wpimath/BUILD.bazel @@ -1,5 +1,7 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") load("@rules_java//java:defs.bzl", "java_binary", "java_library") load("@rules_python//python:defs.bzl", "py_binary") +load("//protoplugin:wpi_proto_library.bzl", "wpi_proto_library") filegroup( name = "generated_java", @@ -7,6 +9,74 @@ filegroup( visibility = ["//wpimath:__subpackages__"], ) +wpi_proto_library( + name = "cc_proto", + include_prefix = "wpimath/src/main/proto", + proto_files = glob(["src/main/proto/*.proto"]), +) + +cc_library( + name = "eigen-headers", + hdrs = glob([ + "src/main/native/thirdparty/eigen/include/**", + ]), + includes = ["src/main/native/thirdparty/eigen/include"], + strip_include_prefix = "src/main/native/thirdparty/eigen/include", + visibility = ["//wpimath:__subpackages__"], +) + +cc_library( + name = "gcem", + hdrs = glob([ + "src/main/native/thirdparty/gcem/include/**", + ]), + includes = ["src/main/native/thirdparty/gcem/include"], + strip_include_prefix = "src/main/native/thirdparty/gcem/include", + visibility = ["//wpimath:__subpackages__"], +) + +cc_library( + name = "sleipnir-headers", + hdrs = glob([ + "src/main/native/thirdparty/sleipnir/include/**/*.hpp", + ]), + includes = ["src/main/native/thirdparty/sleipnir/include"], + strip_include_prefix = "src/main/native/thirdparty/sleipnir/include", + visibility = ["//wpimath:__subpackages__"], +) + +filegroup( + name = "sleipnir-srcs", + srcs = glob(["src/main/native/thirdparty/sleipnir/src/**"]), + visibility = ["//wpimath:__subpackages__"], +) + +cc_library( + name = "wpimath.static", + srcs = glob( + ["src/main/native/cpp/**"], + exclude = ["src/main/native/cpp/jni/**"], + ) + [ + ":cc_proto.srcs", + ":sleipnir-srcs", + ], + hdrs = glob(["src/main/native/include/**"]), + defines = ["WPILIB_EXPORTS"], + includes = [ + "src/main/native/include", + "src/main/native/thirdparty/sleipnir/src", + ], + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + ":cc_proto.hdrs", + ":eigen-headers", + ":gcem", + ":sleipnir-headers", + "//wpiutil:wpiutil.static", + ], +) + java_library( name = "wpimath-java", srcs = [":generated_java"] + glob(["src/main/java/**/*.java"]), @@ -24,6 +94,40 @@ java_library( ], ) +cc_library( + name = "test_headers", + hdrs = glob([ + "src/test/native/include/**", + ]), + strip_include_prefix = "src/test/native/include", +) + +cc_test( + name = "wpimath-cpp-test", + size = "small", + srcs = glob([ + "src/test/native/cpp/**/*.cpp", + "src/test/native/cpp/**/*.h", + ]), + tags = [ + "no-bullseye", + "no-raspi", + ], + deps = [ + ":test_headers", + ":wpimath.static", + "//thirdparty/googletest:googletest.static", + ], +) + +cc_binary( + name = "DevMain-Cpp", + srcs = ["src/dev/native/cpp/main.cpp"], + deps = [ + ":wpimath.static", + ], +) + java_binary( name = "DevMain-Java", srcs = ["src/dev/java/edu/wpi/first/math/DevMain.java"], diff --git a/xrpVendordep/BUILD.bazel b/xrpVendordep/BUILD.bazel new file mode 100644 index 00000000000..964ea19d70f --- /dev/null +++ b/xrpVendordep/BUILD.bazel @@ -0,0 +1,54 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") +load("@rules_java//java:defs.bzl", "java_binary", "java_library") + +cc_library( + name = "xrp-cpp", + srcs = glob([ + "src/main/native/cpp/**", + ]), + hdrs = glob(["src/main/native/include/**"]), + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + "//wpilibc:wpilibc.static", + ], +) + +java_library( + name = "xrp-java", + srcs = glob(["src/main/java/**/*.java"]), + visibility = ["//visibility:public"], + deps = [ + "//hal:hal-java", + "//wpilibj", + "//wpimath:wpimath-java", + ], +) + +cc_test( + name = "xrp-cpp-test", + size = "small", + srcs = glob(["src/test/native/cpp/**"]), + deps = [ + "//thirdparty/googletest:googletest.static", + ], +) + +cc_binary( + name = "DevMain-Cpp", + srcs = ["src/dev/native/cpp/main.cpp"], + deps = [ + "//wpiutil:wpiutil.static", + ], +) + +java_binary( + name = "DevMain-Java", + srcs = ["src/dev/java/edu/wpi/first/wpilibj/xrp/DevMain.java"], + main_class = "edu.wpi.first.wpilibj.xrp.DevMain", + deps = [ + "//hal:hal-java", + "//ntcore:networktables-java", + "//wpiutil:wpiutil-java", + ], +) From e37e6713c79627ae8473ba5042facc8a08d5819d Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Thu, 14 Nov 2024 22:57:00 -0500 Subject: [PATCH 2/4] Transition to nanopb --- .bazelrc | 2 -- WORKSPACE | 39 -------------------------- protoplugin/BUILD.bazel | 27 ------------------ protoplugin/bazel_proto_generator.py | 38 -------------------------- protoplugin/wpi_proto_library.bzl | 41 ---------------------------- wpimath/BUILD.bazel | 27 +++++++++--------- wpiutil/BUILD.bazel | 4 +-- 7 files changed, 16 insertions(+), 162 deletions(-) delete mode 100644 protoplugin/BUILD.bazel delete mode 100755 protoplugin/bazel_proto_generator.py delete mode 100644 protoplugin/wpi_proto_library.bzl diff --git a/.bazelrc b/.bazelrc index 6740b8dd6a8..bb73151474b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -8,8 +8,6 @@ build --java_runtime_version=roboriojdk_17 build --tool_java_language_version=17 build --tool_java_runtime_version=remotejdk_17 -build --proto_toolchain_for_cc=//:proto_cc_toolchain - test --test_output=errors test --test_verbose_timeout_warnings diff --git a/WORKSPACE b/WORKSPACE index 60447ae2344..f4aa7d147ec 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -99,45 +99,6 @@ load("@bzlmodrio-opencv//:maven_java_deps.bzl", "setup_legacy_bzlmodrio_opencv_j setup_legacy_bzlmodrio_opencv_java_dependencies() -http_archive( - name = "com_google_protobuf", - patch_args = ["-p1"], - patches = [ - "//upstream_utils/protobuf_patches:0001-Fix-sign-compare-warnings.patch", - "//upstream_utils/protobuf_patches:0002-Remove-redundant-move.patch", - "//upstream_utils/protobuf_patches:0003-Fix-maybe-uninitialized-warnings.patch", - "//upstream_utils/protobuf_patches:0004-Fix-coded_stream-WriteRaw.patch", - "//upstream_utils/protobuf_patches:0005-Suppress-enum-enum-conversion-warning.patch", - "//upstream_utils/protobuf_patches:0006-Fix-noreturn-function-returning.patch", - "//upstream_utils/protobuf_patches:0007-Work-around-GCC-12-restrict-warning-compiler-bug.patch", - "//upstream_utils/protobuf_patches:0008-Disable-MSVC-switch-warning.patch", - "//upstream_utils/protobuf_patches:0009-Disable-unused-function-warning.patch", - "//upstream_utils/protobuf_patches:0010-Disable-pedantic-warning.patch", - "//upstream_utils/protobuf_patches:0011-Avoid-use-of-sprintf.patch", - ], - sha256 = "f7042d540c969b00db92e8e1066a9b8099c8379c33f40f360eb9e1d98a36ca26", - strip_prefix = "protobuf-3.21.12", - urls = [ - "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.21.12.zip", - ], -) - -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() - -# Rules Python -http_archive( - name = "rules_python", - sha256 = "c68bdc4fbec25de5b5493b8819cfc877c4ea299c0dcb15c244c5a00208cde311", - strip_prefix = "rules_python-0.31.0", - url = "https://github.com/bazelbuild/rules_python/releases/download/0.31.0/rules_python-0.31.0.tar.gz", -) - -load("@rules_python//python:repositories.bzl", "py_repositories") - -py_repositories() - http_archive( name = "build_bazel_apple_support", sha256 = "c4bb2b7367c484382300aee75be598b92f847896fb31bbd22f3a2346adf66a80", diff --git a/protoplugin/BUILD.bazel b/protoplugin/BUILD.bazel deleted file mode 100644 index d9548cc3483..00000000000 --- a/protoplugin/BUILD.bazel +++ /dev/null @@ -1,27 +0,0 @@ -load("@rules_java//java:defs.bzl", "java_binary", "java_import") -load("@rules_python//python:defs.bzl", "py_binary") - -java_import( - name = "binary", - jars = ["binary/wpiprotoplugin.jar"], -) - -java_binary( - name = "wpi_proto_plugin", - main_class = "org.wpilib.ProtoCDllGenerator", - runtime_deps = [ - ":binary", - ], -) - -py_binary( - name = "bazel_proto_generator", - srcs = ["bazel_proto_generator.py"], - data = [ - ":wpi_proto_plugin", - "@com_google_protobuf//:protoc", - ], - tags = ["manual"], - visibility = ["//visibility:public"], - deps = ["@rules_python//python/runfiles"], -) diff --git a/protoplugin/bazel_proto_generator.py b/protoplugin/bazel_proto_generator.py deleted file mode 100755 index 8bec033eb8f..00000000000 --- a/protoplugin/bazel_proto_generator.py +++ /dev/null @@ -1,38 +0,0 @@ -from python.runfiles import Runfiles -import argparse -import subprocess -import os - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument("--include_prefix", required=True) - parser.add_argument("--proto_files", nargs="+") - parser.add_argument("--output_files", nargs="+") - - args = parser.parse_args() - assert len(args.proto_files) * 2 == len(args.output_files) - - r = Runfiles.Create() - if os.name == "nt": - protoc = r.Rlocation("com_google_protobuf/protoc.exe") - plugin = r.Rlocation("__main__/protoplugin/wpi_proto_plugin.exe") - else: - protoc = r.Rlocation("com_google_protobuf/protoc") - plugin = r.Rlocation("__main__/protoplugin/wpi_proto_plugin") - - output_directory = os.path.dirname(args.output_files[0]) - - cmd = [] - cmd.append(protoc) - cmd.append(f"--cpp_out={output_directory}") - cmd.append(f"-I{args.include_prefix}") - cmd.append(f"--wpilib_out={output_directory}") - cmd.append(f"--plugin=protoc-gen-wpilib={plugin}") - cmd.extend(args.proto_files) - - subprocess.check_call(cmd) - - -if __name__ == "__main__": - main() diff --git a/protoplugin/wpi_proto_library.bzl b/protoplugin/wpi_proto_library.bzl deleted file mode 100644 index 7ff922f2a4b..00000000000 --- a/protoplugin/wpi_proto_library.bzl +++ /dev/null @@ -1,41 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - -def wpi_proto_library( - name, - proto_files, - include_prefix): - gen_srcs = [] - gen_hdrs = [] - - for pf in proto_files: - gen_srcs.append("generated_proto/" + pf[:-5] + "pb.cc") - gen_hdrs.append("generated_proto/" + pf[:-5] + "pb.h") - - cmd = "$(locations //protoplugin:bazel_proto_generator) --include_prefix={} --proto_files $(SRCS) --output_files $(OUTS)".format(include_prefix) - native.genrule( - name = "generate_proto", - srcs = proto_files, - outs = gen_srcs + gen_hdrs, - cmd = cmd, - tools = [ - "//protoplugin:bazel_proto_generator", - ], - visibility = ["//visibility:public"], - ) - - native.filegroup( - name = name + ".srcs", - srcs = gen_srcs, - ) - - native.filegroup( - name = name + ".hdr_files", - srcs = gen_hdrs, - ) - - cc_library( - name = name + ".hdrs", - hdrs = gen_hdrs, - includes = ["generated_proto/src/main/proto"], - visibility = ["//visibility:public"], - ) diff --git a/wpimath/BUILD.bazel b/wpimath/BUILD.bazel index e15c79e5ea3..7979a8ba1cb 100644 --- a/wpimath/BUILD.bazel +++ b/wpimath/BUILD.bazel @@ -1,7 +1,6 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") load("@rules_java//java:defs.bzl", "java_binary", "java_library") load("@rules_python//python:defs.bzl", "py_binary") -load("//protoplugin:wpi_proto_library.bzl", "wpi_proto_library") filegroup( name = "generated_java", @@ -9,12 +8,6 @@ filegroup( visibility = ["//wpimath:__subpackages__"], ) -wpi_proto_library( - name = "cc_proto", - include_prefix = "wpimath/src/main/proto", - proto_files = glob(["src/main/proto/*.proto"]), -) - cc_library( name = "eigen-headers", hdrs = glob([ @@ -51,15 +44,23 @@ filegroup( visibility = ["//wpimath:__subpackages__"], ) +cc_library( + name = "nanopb-generated-headers", + hdrs = glob(["src/generated/main/native/cpp/**/*.h"]), + includes = ["src/generated/main/native/cpp"], + strip_include_prefix = "src/generated/main/native/cpp", + visibility = ["//wpiutil:__subpackages__"], +) + cc_library( name = "wpimath.static", srcs = glob( - ["src/main/native/cpp/**"], + [ + "src/main/native/cpp/**", + "src/generated/main/native/cpp/**/*.cpp", + ], exclude = ["src/main/native/cpp/jni/**"], - ) + [ - ":cc_proto.srcs", - ":sleipnir-srcs", - ], + ) + [":sleipnir-srcs"], hdrs = glob(["src/main/native/include/**"]), defines = ["WPILIB_EXPORTS"], includes = [ @@ -69,9 +70,9 @@ cc_library( strip_include_prefix = "src/main/native/include", visibility = ["//visibility:public"], deps = [ - ":cc_proto.hdrs", ":eigen-headers", ":gcem", + ":nanopb-generated-headers", ":sleipnir-headers", "//wpiutil:wpiutil.static", ], diff --git a/wpiutil/BUILD.bazel b/wpiutil/BUILD.bazel index e92f58c99da..5eafa60cdbd 100644 --- a/wpiutil/BUILD.bazel +++ b/wpiutil/BUILD.bazel @@ -180,9 +180,9 @@ cc_library( ":llvm-srcs", ":memory-srcs", ":mpack-srcs", + ":nanopb-srcs", ":native-srcs", ":protobuf-srcs", - ":nanopb-srcs", ], hdrs = glob(["src/main/native/include/**/*"]), includes = ["src/main/native/include"], @@ -197,8 +197,8 @@ cc_library( ":llvm-headers", ":memory-headers", ":mpack-headers", - ":protobuf-headers", ":nanopb-headers", + ":protobuf-headers", ":sigslot-headers", ] + select({ "@rules_bzlmodrio_toolchains//constraints/is_roborio:roborio": ["@bzlmodrio-ni//libraries/cpp/ni:shared"], From bf81de44ea4be8603df3ffcf1a7591897c6b056b Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Mon, 18 Nov 2024 12:42:37 -0500 Subject: [PATCH 3/4] Lint --- shared/bazel/compiler_flags/osx_flags.rc | 2 +- shared/bazel/compiler_flags/roborio_flags.rc | 2 +- upstream_utils/protobuf_patches/BUILD.bazel | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/shared/bazel/compiler_flags/osx_flags.rc b/shared/bazel/compiler_flags/osx_flags.rc index b152a181f84..2aa48df2804 100644 --- a/shared/bazel/compiler_flags/osx_flags.rc +++ b/shared/bazel/compiler_flags/osx_flags.rc @@ -44,4 +44,4 @@ build:macos --linkopt=-Wl,-rpath,'@loader_path'" build:macos --copt=-Wno-shorten-64-to-32 build:macos --host_per_file_copt=external/zlib/.*\.c@-Wno-deprecated-non-prototype -build:macos --host_per_file_copt=external/com_google_protobuf/.*\.cc@-Wno-unused-function \ No newline at end of file +build:macos --host_per_file_copt=external/com_google_protobuf/.*\.cc@-Wno-unused-function diff --git a/shared/bazel/compiler_flags/roborio_flags.rc b/shared/bazel/compiler_flags/roborio_flags.rc index 4be54159474..a0a50557263 100644 --- a/shared/bazel/compiler_flags/roborio_flags.rc +++ b/shared/bazel/compiler_flags/roborio_flags.rc @@ -15,4 +15,4 @@ build:roborio --cxxopt=-Wno-error=deprecated-declarations # Extra 11 build:roborio --cxxopt=-Wno-error=deprecated-enum-enum-conversion -build:roborio --host_per_file_copt=external/zlib/.*\.c@-Wno-deprecated-non-prototype \ No newline at end of file +build:roborio --host_per_file_copt=external/zlib/.*\.c@-Wno-deprecated-non-prototype diff --git a/upstream_utils/protobuf_patches/BUILD.bazel b/upstream_utils/protobuf_patches/BUILD.bazel index e69de29bb2d..8b137891791 100644 --- a/upstream_utils/protobuf_patches/BUILD.bazel +++ b/upstream_utils/protobuf_patches/BUILD.bazel @@ -0,0 +1 @@ + From 2acf1d2fb0ca71ed7ed8ad64ef98b87e77257ce2 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sat, 23 Nov 2024 22:48:59 -0500 Subject: [PATCH 4/4] Delete unneeded file --- upstream_utils/protobuf_patches/BUILD.bazel | 1 - 1 file changed, 1 deletion(-) delete mode 100644 upstream_utils/protobuf_patches/BUILD.bazel diff --git a/upstream_utils/protobuf_patches/BUILD.bazel b/upstream_utils/protobuf_patches/BUILD.bazel deleted file mode 100644 index 8b137891791..00000000000 --- a/upstream_utils/protobuf_patches/BUILD.bazel +++ /dev/null @@ -1 +0,0 @@ -