Skip to content

Commit

Permalink
[bazel] MVP for building wpilibc + commands framework (wpilibsuite#7231)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreiniger authored Dec 19, 2024
1 parent 38d8929 commit 9ccd731
Show file tree
Hide file tree
Showing 17 changed files with 729 additions and 7 deletions.
27 changes: 23 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ maven_install(
# Download toolchains
http_archive(
name = "rules_bzlmodrio_toolchains",
sha256 = "2ef1cafce7f4fd4e909bb5de8b0dc771a934646afd55d5f100ff31f6b500df98",
url = "https://github.com/wpilibsuite/rules_bzlmodRio_toolchains/releases/download/2024-1.bcr1/rules_bzlmodRio_toolchains-2024-1.bcr1.tar.gz",
sha256 = "fe267e2af53c1def1e962700a9aeda9e8fdfa9fb46b72167c615ec0e25447dd6",
url = "https://github.com/wpilibsuite/rules_bzlmodRio_toolchains/releases/download/2025-1/rules_bzlmodRio_toolchains-2025-1.tar.gz",
)

load("@rules_bzlmodrio_toolchains//:maven_deps.bzl", "setup_legacy_setup_toolchains_dependencies")
Expand Down Expand Up @@ -71,6 +71,12 @@ register_toolchains(
"@local_bullseye_64//:macos",
"@local_bullseye_64//:linux",
"@local_bullseye_64//:windows",
"@local_bookworm_32//:macos",
"@local_bookworm_32//:linux",
"@local_bookworm_32//:windows",
"@local_bookworm_64//:macos",
"@local_bookworm_64//:linux",
"@local_bookworm_64//:windows",
)

setup_legacy_setup_jdk_dependencies()
Expand All @@ -87,8 +93,8 @@ setup_legacy_bzlmodrio_ni_cpp_dependencies()

http_archive(
name = "bzlmodrio-opencv",
sha256 = "5314cce05b49451a46bf3e3140fc401342e53d5f3357612ed4473e59bb616cba",
url = "https://github.com/wpilibsuite/bzlmodRio-opencv/releases/download/2024.4.8.0-4.bcr1/bzlmodRio-opencv-2024.4.8.0-4.bcr1.tar.gz",
sha256 = "4f4a607956ca8555618736c3058dd96e09d02df19e95088c1e352d2319fd70c7",
url = "https://github.com/wpilibsuite/bzlmodRio-opencv/releases/download/2025.4.10.0-2/bzlmodRio-opencv-2025.4.10.0-2.tar.gz",
)

load("@bzlmodrio-opencv//:maven_cpp_deps.bzl", "setup_legacy_bzlmodrio_opencv_cpp_dependencies")
Expand All @@ -98,3 +104,16 @@ 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 = "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()
112 changes: 112 additions & 0 deletions apriltag/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
29 changes: 28 additions & 1 deletion cameraserver/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"]),
Expand All @@ -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",
],
)

Expand Down
89 changes: 89 additions & 0 deletions cscore/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"]),
Expand All @@ -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"],
Expand Down
22 changes: 22 additions & 0 deletions epilogue-processor/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class LoggerGenerator {
LoggerGenerator::isBuiltInJavaMethod;
private final ProcessingEnvironment m_processingEnv;
private final List<ElementHandler> m_handlers;

@SuppressWarnings("BadAnnotationImplementation")
private final Logged m_defaultConfig =
new Logged() {
@Override
Expand Down
12 changes: 12 additions & 0 deletions epilogue-runtime/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
31 changes: 31 additions & 0 deletions fieldImages/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
Loading

0 comments on commit 9ccd731

Please sign in to comment.