Files
allwpilib/tools/wpical/BUILD.bazel

250 lines
5.9 KiB
Python
Raw Normal View History

load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_pkg//:mappings.bzl", "pkg_files")
load("//shared/bazel/rules:cc_rules.bzl", "wpilib_cc_library")
load("//shared/bazel/rules:packaging.bzl", "package_binary_cc_project")
load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources")
load("//shared/bazel/rules/gen:gen-version-file.bzl", "generate_version_file")
pkg_files(
name = "licenses",
srcs = [
"WPICalThirdPartyNotices.txt",
],
)
generate_resources(
name = "generate-resources",
namespace = "wpical",
prefix = "WPI",
resource_files = glob(["src/main/native/resources/*"]),
)
generate_version_file(
name = "generate-version",
output_file = "WPILibVersion.cpp",
template = "src/main/generate/WPILibVersion.cpp.in",
)
cc_library(
name = "headers",
hdrs = glob([
"src/main/native/include/**/*",
]),
strip_include_prefix = "src/main/native/include",
deps = [
":headers-libdogleg",
":headers-mrcal",
":headers-mrcal-generated",
":headers-mrcal-java",
],
)
cc_library(
name = "headers-libdogleg",
hdrs = glob([
"src/main/native/thirdparty/libdogleg/include/**/*",
]),
strip_include_prefix = "src/main/native/thirdparty/libdogleg/include",
)
cc_library(
name = "headers-mrcal-generated",
hdrs = glob([
"src/main/native/thirdparty/mrcal/generated/**/*",
]),
strip_include_prefix = "src/main/native/thirdparty/mrcal/generated/",
)
cc_library(
name = "headers-mrcal",
hdrs = glob([
"src/main/native/thirdparty/mrcal/include/**/*",
]),
strip_include_prefix = "src/main/native/thirdparty/mrcal/include/",
)
cc_library(
name = "headers-mrcal-java",
hdrs = glob([
"src/main/native/thirdparty/mrcal_java/include/**/*",
]),
strip_include_prefix = "src/main/native/thirdparty/mrcal_java/include/",
)
unix_copts = [
"-Wno-pedantic",
"-Wno-format-nonliteral",
"-Wno-unused-variable",
"-Wno-unused-function",
"-Wno-sign-compare",
]
osx_copts = unix_copts
copts = select({
"@platforms//os:linux": unix_copts + [
"-Wno-maybe-uninitialized",
],
"@platforms//os:osx": osx_copts,
"@platforms//os:windows": [
"/wd4047",
"/wd4098",
"/wd4267",
],
})
unix_cxxopts = [
"-Wno-missing-field-initializers",
"-Wno-pedantic",
"-fpermissive",
"-Wno-deprecated-declarations",
"-Wno-return-type",
"-Wno-missing-braces",
"-Wno-null-conversion",
"-Wno-unused-but-set-variable",
]
osx_cxxopts = unix_cxxopts + [
"-Wno-unused-variable",
"-Wno-unused-function",
"-Wno-sign-compare",
"-Wno-sometimes-uninitialized",
]
cxxopts = select({
"@platforms//os:linux": unix_cxxopts + [
"-Wno-deprecated-enum-enum-conversion",
],
"@platforms//os:osx": osx_cxxopts,
"@platforms//os:windows": [
"/wd4068",
"/wd4101",
"/wd4200",
"/wd4576",
"/wd4715",
],
})
mac_linkopts = [
"-framework",
"Metal",
"-framework",
"MetalKit",
"-framework",
"Cocoa",
"-framework",
"IOKit",
"-framework",
"CoreFoundation",
"-framework",
"CoreVideo",
"-framework",
"QuartzCore",
"-framework",
"Accelerate",
"-framework",
"AVFoundation",
"-framework",
"CoreMedia",
]
linkopts = select({
"@platforms//os:linux": [],
"@platforms//os:osx": mac_linkopts,
"@platforms//os:windows": [
"-DEFAULTLIB:Gdi32.lib",
"-DEFAULTLIB:Shell32.lib",
"-DEFAULTLIB:d3d11.lib",
"-DEFAULTLIB:d3dcompiler.lib",
"-DEFAULTLIB:Comdlg32.lib",
"-DEFAULTLIB:dbghelp.lib",
"-DEFAULTLIB:Advapi32.lib",
],
})
wpilib_cc_library(
name = "wpical_lib",
srcs = glob(
[
"src/main/native/cpp/**/*.cpp",
"src/main/native/thirdparty/libdogleg/src/**/*.cpp",
"src/main/native/thirdparty/mrcal/src/**/*.cpp",
"src/main/native/thirdparty/mrcal/src/**/*.c",
"src/main/native/thirdparty/mrcal_java/src/**/*.cpp",
],
exclude = ["src/main/native/cpp/WPIcal.cpp"],
) + [
":generate-resources",
[wpical] Refactor to use WPILib libraries and modern C++ conventions and improve UX (#7796) wpical was unable to use wpimath and its dependent libraries because Ceres was compiled with a different version of Eigen. Now that the Ceres build has been redone and shipped in #8151, we can now use wpimath and our C++ apriltag wrapper in wpical, allowing for major refactors. This includes: * Using `to_json` and `from_json` specializations to concisely serialize and deserialize all JSON files instead of manually handling JSON. * Removal of the `Fieldmap` and `Pose` classes, which were duplicates of the `AprilTagFieldLayout` and `Pose3d` classes respectively. * Using `AprilTagDetector` instead of the raw libapriltag library. * Using `Pose3d` instead of raw Eigen matrices. In addition, several other refactors were made to make the code more readable and to fix several UX issues and crashes. This includes: * Eagerly parsing every JSON file when selected by the user. This means JSON files are only parsed once on selection, instead of every time a downstream function wants to use the data. This also means invalid JSON can be detected upfront and a specific error shown immediately instead of a catch all error when trying to calibrate. * Using `std::optional` to indicate a calibration failed instead of status codes. * Processing videos on separate threads to not block the UI thread and take advantage of parallelization for camera calibration. (2x speedup on my laptop) * Removing the OpenCV calibration option, since mrcal should be better in every scenario. * Showing a progress bar for camera calibration. * Breaking up the massive `DisplayGui` function into separate functions which contain code for different popups. This also allowed for better organization and scoping of static variables. * Renaming variables to make their purpose more clear. * Displaying the tags present in a field layout when trying to combine multiple field layouts. Fixes #7722.
2025-12-31 12:28:51 -05:00
":generate-version",
],
copts = copts,
cxxopts = cxxopts,
defines = ["OPENCV_DISABLE_EIGEN_TENSOR_SUPPORT"],
include_license_files = True,
linkopts = linkopts,
linkstatic = True,
strip_include_prefix = "include",
visibility = ["//visibility:public"],
deps = [
":headers",
"//apriltag",
[bazel] Improve vendored deps, make libssh vendored (#8948) TL;DR: kill https://github.com/wpilibsuite/bzlmodRio-libssh, update versions, and make things easier for a script to update. The main motivation behind this was that libssh was out of date with the gradle version. Using these "external" dependencies can cause agita as we churn through toolchain updates. Unlike the toolchains and opencv, which can be used by external users (i.e. a all bazel robot, if a vendor wanted to use bazel) a C++ wrapper around libssh maven deps almost certainly wouldn't be pulled in, much like ceres and mrclib. As a result of vendor'ing libssh, and knowing some potential pitfalls and annoyances, this PR does the following: - Vendor libssh, akin to how mrclib is pulled in - Moves the vendor'd ceres to `shared/bazel/thirdparty`, and refactors it to better match mrclib. To me it doesn't necessarily belong in its `thirdparty` location because it is bazel only. - Due to the refactoring, libssh and ceres can now be pulled into `MODULE.bazel` instead of the `WORKSPACE.bzlmod` helper. This is good prep for a potential upgrade to killing `--enable_workspace` / bazel 9 - Write a python script that can deal with the integrity / sha256 of the http_archives. I suggested this be added to davo's mrclib PR, but this one is a little bit more robust and will actually edit the files in place. This makes upgrading versions substantially easier. - Upgrade libssh version to what gradle is using, and mrclib to the version in #8858. These changes have been tested against that PR.
2026-06-19 18:25:07 -04:00
"//shared/bazel/thirdparty/ceres",
"//wpigui",
"//wpiutil",
"@bzlmodrio-opencv//libraries/cpp/opencv",
],
)
cc_binary(
name = "wpical",
srcs = [
"src/main/native/cpp/WPIcal.cpp",
],
copts = copts,
cxxopts = cxxopts,
linkopts = select({
"@platforms//os:linux": [],
"@platforms//os:osx": [],
"@platforms//os:windows": [
"-SUBSYSTEM:WINDOWS",
],
}),
deps = [
":wpical_lib",
[wpical] Refactor to use WPILib libraries and modern C++ conventions and improve UX (#7796) wpical was unable to use wpimath and its dependent libraries because Ceres was compiled with a different version of Eigen. Now that the Ceres build has been redone and shipped in #8151, we can now use wpimath and our C++ apriltag wrapper in wpical, allowing for major refactors. This includes: * Using `to_json` and `from_json` specializations to concisely serialize and deserialize all JSON files instead of manually handling JSON. * Removal of the `Fieldmap` and `Pose` classes, which were duplicates of the `AprilTagFieldLayout` and `Pose3d` classes respectively. * Using `AprilTagDetector` instead of the raw libapriltag library. * Using `Pose3d` instead of raw Eigen matrices. In addition, several other refactors were made to make the code more readable and to fix several UX issues and crashes. This includes: * Eagerly parsing every JSON file when selected by the user. This means JSON files are only parsed once on selection, instead of every time a downstream function wants to use the data. This also means invalid JSON can be detected upfront and a specific error shown immediately instead of a catch all error when trying to calibrate. * Using `std::optional` to indicate a calibration failed instead of status codes. * Processing videos on separate threads to not block the UI thread and take advantage of parallelization for camera calibration. (2x speedup on my laptop) * Removing the OpenCV calibration option, since mrcal should be better in every scenario. * Showing a progress bar for camera calibration. * Breaking up the massive `DisplayGui` function into separate functions which contain code for different popups. This also allowed for better organization and scoping of static variables. * Renaming variables to make their purpose more clear. * Displaying the tags present in a field layout when trying to combine multiple field layouts. Fixes #7722.
2025-12-31 12:28:51 -05:00
"//glass",
"//thirdparty/imgui_suite",
],
)
cc_test(
name = "wpical_test",
size = "medium",
srcs = glob(["src/test/native/**"]),
copts = copts,
cxxopts = cxxopts,
data = glob(["src/main/native/assets/**"]) + [
"src/main/native/assets",
"src/main/native/assets/altfieldvideo",
"src/main/native/assets/fieldvideo",
],
defines = [
2025-11-07 19:56:21 -05:00
'PROJECT_ROOT_PATH=\\"tools/wpical/src/main/native/assets\\"',
"__BAZEL__=1",
],
deps = [
":wpical_lib",
[bazel] Improve vendored deps, make libssh vendored (#8948) TL;DR: kill https://github.com/wpilibsuite/bzlmodRio-libssh, update versions, and make things easier for a script to update. The main motivation behind this was that libssh was out of date with the gradle version. Using these "external" dependencies can cause agita as we churn through toolchain updates. Unlike the toolchains and opencv, which can be used by external users (i.e. a all bazel robot, if a vendor wanted to use bazel) a C++ wrapper around libssh maven deps almost certainly wouldn't be pulled in, much like ceres and mrclib. As a result of vendor'ing libssh, and knowing some potential pitfalls and annoyances, this PR does the following: - Vendor libssh, akin to how mrclib is pulled in - Moves the vendor'd ceres to `shared/bazel/thirdparty`, and refactors it to better match mrclib. To me it doesn't necessarily belong in its `thirdparty` location because it is bazel only. - Due to the refactoring, libssh and ceres can now be pulled into `MODULE.bazel` instead of the `WORKSPACE.bzlmod` helper. This is good prep for a potential upgrade to killing `--enable_workspace` / bazel 9 - Write a python script that can deal with the integrity / sha256 of the http_archives. I suggested this be added to davo's mrclib PR, but this one is a little bit more robust and will actually edit the files in place. This makes upgrading versions substantially easier. - Upgrade libssh version to what gradle is using, and mrclib to the version in #8858. These changes have been tested against that PR.
2026-06-19 18:25:07 -04:00
"//shared/bazel/thirdparty/ceres",
"//thirdparty/catch2",
"@bazel_tools//tools/cpp/runfiles",
],
)
package_binary_cc_project(
name = "wpical",
extra_files = [":licenses"],
maven_artifact_name = "wpical",
2025-11-07 20:00:38 -05:00
maven_group_id = "org.wpilib.tools",
)