opencv4.13.0.bcr.6 (#10285)
This change replaces `rules_android_ndk` to avoid the heavy impact it
has on consumers in favor of more modern `cpu_features` module to solve
the same purpose. There is also a new `--@opencv//:cpufeatures` label
flag that users can use to restore the previous behavior if
`@cpu_features` is insufficient for some reason.
diff --git a/modules/opencv/4.12.0.bcr.6/MODULE.bazel b/modules/opencv/4.12.0.bcr.6/MODULE.bazel
new file mode 100644
index 0000000..3578a73
--- /dev/null
+++ b/modules/opencv/4.12.0.bcr.6/MODULE.bazel
@@ -0,0 +1,39 @@
+module(
+ name = "opencv",
+ version = "4.12.0.bcr.6",
+ bazel_compatibility = [">=7.2.1"],
+ compatibility_level = 0,
+)
+
+bazel_dep(name = "apple_support", version = "2.2.0")
+bazel_dep(name = "bazel_skylib", version = "1.9.0")
+bazel_dep(name = "rules_cc", version = "0.2.17")
+bazel_dep(name = "rules_license", version = "1.0.0")
+bazel_dep(name = "platforms", version = "1.0.0")
+bazel_dep(name = "libpng", version = "1.6.54")
+bazel_dep(name = "libjpeg_turbo", version = "3.1.3.bcr.4")
+bazel_dep(name = "zlib", version = "1.3.1.bcr.8")
+bazel_dep(name = "eigen", version = "5.0.1")
+bazel_dep(name = "libtiff", version = "4.7.1")
+bazel_dep(name = "libwebp", version = "1.5.0")
+bazel_dep(name = "rules_qt", version = "0.0.7")
+
+
+# Needed for cpufeatures library which is a dependency of OpenCV when building for Android
+bazel_dep(name = "cpu_features", version = "0.11.0.bcr.1")
+
+rules_qt_fetch = use_extension("@rules_qt//extension:qt.bzl", "fetch")
+rules_qt_fetch.install(
+ name = "qt_mac_x86_64",
+ build_file = "@rules_qt//extension:qt/6.8.3/mac_aarch64.BUILD",
+ os = "macos",
+ version = "6.8.3",
+)
+rules_qt_fetch.install(
+ name = "qt_windows_x86_64",
+ build_file = "@rules_qt//extension:qt/6.8.3/windows_x86_64.BUILD",
+ os = "windows",
+ version = "6.8.3",
+ windows_architecture = "win64_msvc2022",
+)
+use_repo(rules_qt_fetch, "qt_linux_x86_64", "qt_linux_aarch64", "qt_mac_aarch64", "qt_mac_x86_64", "qt_windows_x86_64")
diff --git a/modules/opencv/4.12.0.bcr.6/overlay/BUILD.bazel b/modules/opencv/4.12.0.bcr.6/overlay/BUILD.bazel
new file mode 100644
index 0000000..4a7d4d1
--- /dev/null
+++ b/modules/opencv/4.12.0.bcr.6/overlay/BUILD.bazel
@@ -0,0 +1,876 @@
+load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
+load("@bazel_skylib//rules:write_file.bzl", "write_file")
+load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
+load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
+load("@bazel_skylib//lib:selects.bzl", "selects")
+load("@rules_cc//cc:objc_library.bzl", "objc_library")
+load("@rules_cc//cc:cc_library.bzl", "cc_library")
+load("@rules_license//rules:license.bzl", "license")
+load("@rules_qt//:qt.bzl", "qt_cc_library")
+
+load(
+ "//:opencv.bzl",
+ "CONFIG_DESKTOP",
+ "CONFIG_NON_DESKTOP",
+ "ENABLED_OPTS",
+ "OPENCV_COPTS",
+ "OPENCV_OPTIMIZATION_COPTS",
+ "opencv_module",
+)
+
+package(
+ default_applicable_licenses = [":license"],
+)
+
+license(
+ name = "license",
+ license_kinds = ["@rules_license//licenses/spdx:Apache-2.0"],
+ license_text = "LICENSE",
+)
+
+exports_files([
+ "LICENSE",
+])
+
+write_file(
+ name = "_private/version_string.inc",
+ out = "private/version_string.inc",
+ content = ["\"4.12.0\""],
+)
+
+write_file(
+ name = "_opencv2/opencv_modules_desktop.hpp",
+ out = "opencv2/opencv_modules_desktop.hpp",
+ content = ["".join([
+ "#define HAVE_OPENCV_{}\n".format(x.upper())
+ for x in CONFIG_DESKTOP["modules"]
+ ])],
+)
+
+write_file(
+ name = "_opencv2/opencv_modules_non_desktop.hpp",
+ out = "opencv2/opencv_modules_non_desktop.hpp",
+ content = ["".join([
+ "#define HAVE_OPENCV_{}\n".format(x.upper())
+ for x in CONFIG_NON_DESKTOP["modules"]
+ ])],
+)
+
+copy_file(
+ name = "generate_opencv_modules_hpp",
+ src = select({
+ "@platforms//os:linux": "opencv2/opencv_modules_desktop.hpp",
+ "@platforms//os:macos": "opencv2/opencv_modules_desktop.hpp",
+ "@platforms//os:windows": "opencv2/opencv_modules_desktop.hpp",
+ "//conditions:default": "opencv2/opencv_modules_non_desktop.hpp",
+ }),
+ out = "opencv2/opencv_modules.hpp",
+)
+
+write_file(
+ name = "_custom_hal.hpp",
+ out = "custom_hal.hpp",
+ content = [
+ "#ifndef _CUSTOM_HAL_INCLUDED_",
+ "#define _CUSTOM_HAL_INCLUDED_",
+ "#endif",
+ ],
+)
+
+write_file(
+ name = "_opencv_data_config.hpp",
+ out = "opencv_data_config.hpp",
+ content = [
+ "#define OPENCV_INSTALL_PREFIX \"\"",
+ "#define OPENCV_DATA_INSTALL_PATH \"\"",
+ "#define OPENCV_BUILD_DIR \"\"",
+ "#define OPENCV_DATA_BUILD_DIR_SEARCH_PATHS \"\"",
+ "#define OPENCV_INSTALL_DATA_DIR_RELATIVE \"\"",
+ ],
+)
+
+[
+ write_file(
+ name = "_bazel-config/cv_cpu_config-{}.h".format(arch),
+ out = "bazel-config/cv_cpu_config-{}.h".format(arch),
+ content = [
+ "// OpenCV CPU baseline features\n",
+ ] + [
+ "#define CV_CPU_COMPILE_{} 1\n#define CV_CPU_BASELINE_COMPILE_{} 1\n".format(arch.upper(), arch.upper())
+ for arch in config.get("baseline", [])
+ ] + [
+ "#define CV_CPU_BASELINE_FEATURES 0 \\",
+ ] + [
+ " , CV_CPU_{} \\".format(arch.upper())
+ for arch in config.get("baseline", [])
+ ] + [
+ "\n",
+ "// OpenCV supported CPU dispathed features\n",
+ ] + [
+ "#define CV_CPU_DISPATCH_COMPILE_{} 1".format(arch.upper())
+ for arch in config.get("dispatch", [])
+ ] + [
+ "\n#define CV_CPU_DISPATCH_FEATURES 0 \\",
+ ] + [
+ " , CV_CPU_{} \\".format(arch.upper())
+ for arch in config.get("dispatch", [])
+ ] + [
+ "\n",
+ ],
+ ) for arch, config in ENABLED_OPTS.items()
+]
+
+write_file(
+ name = "_bazel-config/cv_cpu_config_no_baseline.h",
+ out = "bazel-config/cv_cpu_config_no_baseline.h",
+ content = [
+ "// OpenCV CPU baseline features\n",
+ "#define CV_CPU_BASELINE_FEATURES 0\n",
+ "// OpenCV supported CPU dispathed features\n",
+ "#define CV_CPU_DISPATCH_FEATURES 0\n",
+ ],
+)
+
+copy_file(
+ name = "_cv_cpu_config.h",
+ out = "cv_cpu_config.h",
+ src = select({
+ "@platforms//cpu:arm64": "bazel-config/cv_cpu_config-arm64.h",
+ "@platforms//cpu:armv7": "bazel-config/cv_cpu_config-armv7.h",
+ "@platforms//cpu:x86_64": "bazel-config/cv_cpu_config-x86_64.h",
+ "@platforms//cpu:mips64": "bazel-config/cv_cpu_config-mips64.h",
+ "@platforms//cpu:ppc64le": "bazel-config/cv_cpu_config-ppc64le.h",
+ "@platforms//cpu:riscv64": "bazel-config/cv_cpu_config-riscv64.h",
+ # LoongArch is not yet supported in the official platforms repo
+ # "@platforms//cpu:loongarch64": "bazel-config/cv_cpu_config-loongarch64.h",
+ "//conditions:default": "bazel-config/cv_cpu_config_no_baseline.h",
+ }),
+)
+
+# Opencv has a lot of options to enable certain features
+# Leverage this, cv_cpu_config.h, and cpu opts to enable these features
+expand_template(
+ name = "expand_cvconfig.h.in",
+ out = "cvconfig.h",
+ substitutions = {
+ "#cmakedefine BUILD_SHARED_LIBS\n": "/* #undef BUILD_SHARED_LIBS */\n",
+ "#cmakedefine CV_ENABLE_INTRINSICS\n": "#define CV_ENABLE_INTRINSICS\n",
+ "#cmakedefine CV_DISABLE_OPTIMIZATION\n": "/* #undef CV_DISABLE_OPTIMIZATION */\n",
+ "${OPENCV_CUDA_ARCH_BIN}": "",
+ "${OPENCV_CUDA_ARCH_FEATURES}": "",
+ "${OPENCV_CUDA_ARCH_PTX}": "",
+ "#cmakedefine HAVE_CLAMDBLAS\n": "/* #undef HAVE_CLAMDBLAS */\n",
+ "#cmakedefine HAVE_CLAMDFFT\n": "/* #undef HAVE_CLAMDFFT */\n",
+ "#cmakedefine HAVE_CLP\n": "/* #undef HAVE_CLP */\n",
+ "#cmakedefine HAVE_CUDA\n": "/* #undef HAVE_CUDA */\n",
+ "#cmakedefine HAVE_CUBLAS\n": "/* #undef HAVE_CUBLAS */\n",
+ "#cmakedefine HAVE_CUDNN\n": "/* #undef HAVE_CUDNN */\n",
+ "#cmakedefine HAVE_CUFFT\n": "/* #undef HAVE_CUFFT */\n",
+ "#cmakedefine HAVE_DIRECTX\n": "/* #undef HAVE_DIRECTX */\n",
+ "#cmakedefine HAVE_DIRECTX_NV12\n": "/* #undef HAVE_DIRECTX_NV12 */\n",
+ "#cmakedefine HAVE_D3D11\n": "/* #undef HAVE_D3D11 */\n",
+ "#cmakedefine HAVE_D3D10\n": "/* #undef HAVE_D3D10 */\n",
+ "#cmakedefine HAVE_D3D9\n": "/* #undef HAVE_D3D9 */\n",
+ "#cmakedefine HAVE_GDAL\n": "/* #undef HAVE_GDAL */\n",
+ "#cmakedefine HAVE_HALIDE\n": "/* #undef HAVE_HALIDE */\n",
+ "#cmakedefine HAVE_VULKAN\n": "/* #undef HAVE_VULKAN */\n",
+ "#cmakedefine HAVE_INTTYPES_H 1\n": "/* #undef HAVE_INTTYPES_H */\n",
+ "#cmakedefine HAVE_IPP\n": "/* #undef HAVE_IPP */\n",
+ "#cmakedefine HAVE_IPP_IW_LL\n": "/* #undef HAVE_IPP_IW_LL */",
+ "#cmakedefine HAVE_IPP_ICV\n": "/* #undef HAVE_IPP_ICV */\n",
+ "#cmakedefine HAVE_IPP_IW\n": "/* #undef HAVE_IPP_IW */\n",
+ "#cmakedefine HAVE_IPP_A\n": "/* #undef HAVE_IPP_A */\n",
+ "#cmakedefine HAVE_OPENJPEG\n": "/* #undef HAVE_OPENJPEG */\n",
+ "#cmakedefine HAVE_JASPER\n": "/* #undef HAVE_JASPER */\n",
+ "#cmakedefine HAVE_AVIF\n": "/* #undef HAVE_AVIF */\n",
+ "#cmakedefine HAVE_JPEG\n": "#define HAVE_JPEG 1\n",
+ "#cmakedefine HAVE_JPEGXL\n": "/* #undef HAVE_JPEGXL */\n",
+ "#cmakedefine HAVE_GDCM\n": "/* #undef HAVE_GDCM */\n",
+ "#cmakedefine HAVE_NVCUVID\n": "/* #undef HAVE_NVCUVID */\n",
+ "#cmakedefine HAVE_NVCUVID_HEADER\n": "/* #undef HAVE_NVCUVID_HEADER */\n",
+ "#cmakedefine HAVE_DYNLINK_NVCUVID_HEADER\n": "/* #undef HAVE_DYNLINK_NVCUVID_HEADER */\n",
+ "#cmakedefine HAVE_NVCUVENC\n": "/* #undef HAVE_NVCUVENC */\n",
+ "#cmakedefine HAVE_OPENCL\n": "/* #undef HAVE_OPENCL */\n",
+ "#cmakedefine HAVE_OPENCL_STATIC\n": "/* #undef HAVE_OPENCL_STATIC */\n",
+ "#cmakedefine HAVE_OPENCL_SVM\n": "/* #undef HAVE_OPENCL_SVM */\n",
+ "#cmakedefine HAVE_OPENCL_D3D11_NV\n": "/* #undef HAVE_OPENCL_D3D11_NV */\n",
+ "#cmakedefine HAVE_OPENEXR\n": "/* #undef HAVE_OPENEXR */\n",
+ "#cmakedefine HAVE_OPENGL\n": "/* #undef HAVE_OPENGL */\n",
+ "#cmakedefine HAVE_PNG\n": "#define HAVE_PNG 1\n",
+ "#cmakedefine HAVE_SPNG\n": "/* #undef HAVE_SPNG */\n",
+ "#cmakedefine HAVE_PTHREAD\n": "#define HAVE_PTHREAD\n",
+ "#cmakedefine HAVE_PTHREADS_PF\n": "#define HAVE_PTHREADS_PF\n",
+ "#cmakedefine HAVE_TBB\n": "/* #undef HAVE_TBB */\n",
+ "#cmakedefine HAVE_HPX\n": "/* #undef HAVE_HPX */\n",
+ "#cmakedefine HAVE_TIFF\n": "#define HAVE_TIFF 1\n",
+ "#cmakedefine HAVE_WEBP\n": "#define HAVE_WEBP 1\n",
+ "#cmakedefine WORDS_BIGENDIAN\n": "/* #undef WORDS_BIGENDIAN */\n",
+ "#cmakedefine HAVE_VA\n": "/* #undef HAVE_VA */\n",
+ "#cmakedefine HAVE_VA_INTEL\n": "/* #undef HAVE_VA_INTEL */\n",
+ "#cmakedefine HAVE_LAPACK\n": "/* #undef HAVE_LAPACK */\n",
+ "#cmakedefine ENABLE_INSTRUMENTATION\n": "/* #undef ENABLE_INSTRUMENTATION */\n",
+ "#cmakedefine HAVE_OPENVX\n": "/* #undef HAVE_OPENVX */\n",
+ "#cmakedefine OPENCV_TRACE\n": "/* #undef OPENCV_TRACE */\n",
+ "#cmakedefine HAVE_QUIRC\n": "/* undef HAVE_QUIRC */\n",
+ } | select({
+ ":have_eigen": {
+ "#cmakedefine HAVE_EIGEN\n": "#define HAVE_EIGEN 1\n",
+ },
+ "//conditions:default": {
+ "#cmakedefine HAVE_EIGEN\n": "/* #undef HAVE_EIGEN */\n",
+ },
+ }),
+ template = "@opencv//:cmake/templates/cvconfig.h.in",
+)
+
+cc_library(
+ name = "_base_headers",
+ hdrs = [
+ "custom_hal.hpp",
+ "cv_cpu_config.h",
+ "cvconfig.h",
+ "opencv2/opencv_modules.hpp",
+ "opencv_data_config.hpp",
+ "include/opencv2/opencv.hpp",
+ ],
+ includes = [
+ "opencv2",
+ "private",
+ "include",
+ ],
+ textual_hdrs = [
+ "private/version_string.inc",
+ ],
+ defines = select({
+ ":emscripten_with_simd": ["CV_WASM_SIMD=1"],
+ "@platforms//os:emscripten": ["CV_FORCE_SIMD128_CPP=1"], # Use CPP SIMD emulation on Emscripten when WASM SIMD is not available
+ "//conditions:default": [],
+ })
+)
+
+cc_library(
+ name = "opencv",
+ deps = selects.with_or({
+ ("@platforms//os:linux", "@platforms//os:macos", "@platforms//os:windows"): [":" + module for module in CONFIG_DESKTOP["modules"]],
+ "//conditions:default": [":" + module for module in CONFIG_NON_DESKTOP["modules"]],
+ }),
+ visibility = ["//visibility:public"],
+)
+
+# Escape hatch for consumers that need the Android NDK's own cpufeatures instead
+# of the `@cpu_features` implementation, e.g. one provided by `rules_android_ndk`:
+# --@opencv//:cpufeatures=@androidndk//:cpufeatures
+label_flag(
+ name = "cpufeatures",
+ build_setting_default = "@cpu_features//:ndk_compat",
+ visibility = ["//visibility:public"],
+)
+
+cc_library(
+ name = "cpufeatures_android",
+ hdrs = ["3rdparty/cpufeatures/cpu-features.h"],
+ strip_include_prefix = "3rdparty/cpufeatures",
+ deps = [
+ ":cpufeatures",
+ ],
+ target_compatible_with = ["@platforms//os:android"],
+)
+
+opencv_module(
+ name = "core",
+ dispatched_files = {
+ "mathfuncs_core": [
+ "sse2",
+ "avx",
+ "avx2",
+ "lasx",
+ ],
+ "stat": [
+ "sse4_2",
+ "avx2",
+ "lasx",
+ ],
+ "arithm": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ "vsx3",
+ "lasx",
+ ],
+ "convert": [
+ "sse2",
+ "avx2",
+ "vsx3",
+ "lasx",
+ ],
+ "convert_scale": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "count_non_zero": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "has_non_zero": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "matmul": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ "avx512_skx",
+ "neon_dotprod",
+ "lasx",
+ ],
+ "mean": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "merge": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "split": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "sum": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "norm": [
+ "sse2",
+ "sse4_1",
+ "avx",
+ "avx2",
+ "neon_dotprod",
+ "lasx",
+ ],
+ },
+ linkopts = select({
+ "@platforms//os:linux": ["-ldl", "-lpthread", "-lrt"],
+ "//conditions:default": [],
+ }),
+ local_defines = select({
+ ":have_allocator_stats": [],
+ "//conditions:default": [
+ "OPENCV_DISABLE_ALLOCATOR_STATS=1"
+ ],
+ }) + select({
+ "@platforms//os:android": [
+ "HAVE_CPUFEATURES=1",
+ ],
+ "//conditions:default": [],
+ }) + selects.with_or({
+ "@platforms//os:windows": [
+ "HAVE_WIN32_ALIGNED_MALLOC=1",
+ ],
+ ("@platforms//os:macos", "@platforms//os:ios"): [
+ "HAVE_POSIX_MEMALIGN=1",
+ ],
+ ("@platforms//os:android", "@platforms//os:linux", "@platforms//os:emscripten"): [
+ "HAVE_POSIX_MEMALIGN=1",
+ "HAVE_MALLOC_H=1",
+ "HAVE_MEMALIGN=1",
+ ],
+ "//conditions:default": [ ],
+ }) + select({
+ ":ubsan_enabled": [
+ "CV_STRONG_ALIGNMENT=1", # UBSan checks for strict alignment
+ ],
+ "//conditions:default": [],
+ }),
+ copts = select({
+ ":ubsan_enabled": [
+ "-fno-sanitize=function", # call to function cv::hal::sub32f via pointer of incorrect type
+ ],
+ "//conditions:default": [],
+ }),
+ deps = [
+ "@zlib",
+ ] + select({
+ "@platforms//os:android": [":cpufeatures_android"],
+ "//conditions:default": [],
+ }) + select({
+ ":have_eigen": ["@eigen"],
+ "//conditions:default": [],
+ }),
+)
+
+opencv_module(
+ name = "imgproc",
+ copts = [
+ "-Wno-deprecated-enum-float-conversion",
+ "-Wno-deprecated-volatile",
+ ],
+ dispatched_files = {
+ "accum": [
+ "sse4_1",
+ "avx",
+ "avx2",
+ ],
+ "bilateral_filter": [
+ "sse2",
+ "avx2",
+ ],
+ "box_filter": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "filter": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "color_hsv": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "color_rgb": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "color_yuv": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "median_blur": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "morph": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "smooth": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "sumpixels": [
+ "sse2",
+ "avx2",
+ "avx512_skx",
+ ],
+ },
+ deps = [":core"],
+)
+
+opencv_module(
+ name = "features2d",
+ copts = [
+ "-Wno-deprecated-enum-float-conversion",
+ "-Wno-deprecated-volatile",
+ ],
+ dispatched_files = {
+ "sift": [
+ "sse4_1",
+ "avx2",
+ "avx512_skx",
+ ],
+ },
+ deps = [
+ ":imgproc",
+ ":flann",
+ ],
+)
+
+opencv_module(
+ name = "flann",
+ deps = [":core"],
+)
+
+opencv_module(
+ name = "calib3d",
+ copts = [
+ "-Wno-deprecated-enum-float-conversion",
+ ],
+ dispatched_files = {
+ "undistort": [
+ "sse2",
+ "avx2",
+ ],
+ },
+ deps = [
+ ":imgproc",
+ ":features2d",
+ ":flann",
+ ],
+)
+
+opencv_module(
+ name = "imgcodecs",
+ local_defines = ["HAVE_WEBP"],
+ deps = [
+ ":imgproc",
+ "@libjpeg_turbo//:jpeg",
+ "@libpng",
+ "@libtiff//:tiff",
+ "@libwebp",
+ ],
+)
+
+opencv_module(
+ name = "objdetect",
+ deps = [
+ ":calib3d",
+ ":imgproc",
+ ":core",
+ ],
+)
+
+# TODO: add build flags for enabling varoious video backends on different platforms
+objc_library(
+ name = "ocv.3rdparty.avfoundation",
+ srcs = select({
+ "@platforms//os:macos": [
+ "modules/videoio/src/cap_avfoundation_mac.mm",
+ ],
+ "@platforms//os:ios": [
+ "modules/videoio/src/cap_avfoundation.mm",
+ ],
+ "//conditions:default": [],
+ }),
+ hdrs = glob([
+ "modules/videoio/src/**/*.h",
+ "modules/videoio/src/**/*.hpp",
+ "modules/videoio/include/**/*.hpp",
+ "modules/videoio/include/**/*.h",
+ ]),
+ includes = [
+ "modules/videoio/include",
+ "modules/videoio/src",
+ ],
+ copts = OPENCV_COPTS + OPENCV_OPTIMIZATION_COPTS + [
+ "-fno-objc-arc", # Disable Automatic Reference Counting, as OpenCV uses manual reference counting
+ ],
+ linkopts = select({
+ "@platforms//os:macos": [
+ "-framework Cocoa",
+ "-framework Accelerate",
+ "-framework AVFoundation",
+ "-framework CoreGraphics",
+ "-framework CoreMedia",
+ "-framework CoreVideo",
+ "-framework QuartzCore",
+ ],
+ "@platforms//os:ios": [
+ "-framework AVFoundation",
+ "-framework QuartzCore",
+ ],
+ }),
+ deps = [
+ ":imgproc",
+ ":imgcodecs",
+ ],
+ target_compatible_with = select({
+ "@platforms//os:macos": ["@platforms//os:macos"],
+ "@platforms//os:ios": ["@platforms//os:ios"],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+)
+
+opencv_module(
+ name = "photo",
+ deps = [
+ ":core",
+ ":imgproc",
+ ],
+)
+
+opencv_module(
+ name = "videoio",
+ deps = [
+ ":imgproc",
+ ":imgcodecs",
+ ] + select({
+ "@platforms//os:macos": [":ocv.3rdparty.avfoundation"],
+ "@platforms//os:ios": [":ocv.3rdparty.avfoundation"],
+ "//conditions:default": [],
+ }),
+ local_defines = select({
+ "@platforms//os:macos": ["HAVE_AVFOUNDATION=1"],
+ "@platforms//os:ios": ["HAVE_AVFOUNDATION=1"],
+ "@platforms//os:linux": ["HAVE_CAMV4L=1", "HAVE_CAMV4L2=1"],
+ "@platforms//os:windows": ["HAVE_DSHOW=1"],
+ "//conditions:default": [],
+ }),
+ sources = [
+ "modules/videoio/src/videoio_registry.cpp",
+ "modules/videoio/src/videoio_c.cpp",
+ "modules/videoio/src/cap.cpp",
+ "modules/videoio/src/cap_images.cpp",
+ "modules/videoio/src/cap_mjpeg_encoder.cpp",
+ "modules/videoio/src/cap_mjpeg_decoder.cpp",
+ "modules/videoio/src/backend_plugin.cpp",
+ "modules/videoio/src/backend_static.cpp",
+ "modules/videoio/src/container_avi.cpp",
+ ] + select({
+ "@platforms//os:linux": [
+ "modules/videoio/src/cap_v4l.cpp",
+ ],
+ "@platforms//os:windows": [
+ "modules/videoio/src/cap_dshow.cpp",
+ ],
+ "//conditions:default": [],
+ }),
+ compatible_with = select({
+ "@platforms//os:linux": ["@platforms//os:linux"],
+ "@platforms//os:windows": ["@platforms//os:windows"],
+ "@platforms//os:macos": ["@platforms//os:macos"],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+)
+
+objc_library(
+ name = "ocv.3rdparty.cocoa",
+ srcs = [
+ "opencv_highgui_config.hpp",
+ ] + select({
+ "@platforms//os:macos": [
+ "modules/highgui/src/window_cocoa.mm",
+ ],
+ "//conditions:default": [],
+ }),
+ hdrs = glob([
+ "modules/highgui/src/**/*.h",
+ "modules/highgui/src/**/*.hpp",
+ "modules/highgui/include/**/*.hpp",
+ "modules/highgui/include/**/*.h",
+ ]),
+ includes = [
+ "modules/highgui/include",
+ "modules/highgui/src",
+ ],
+ copts = OPENCV_COPTS + OPENCV_OPTIMIZATION_COPTS + [
+ "-fno-objc-arc", # Disable Automatic Reference Counting, as OpenCV uses manual reference counting
+ ],
+ linkopts = select({
+ "@platforms//os:macos": [
+ "-framework Cocoa",
+ ],
+ }),
+ deps = [
+ ":videoio",
+ ":imgcodecs",
+ ],
+ target_compatible_with = select({
+ "@platforms//os:macos": ["@platforms//os:macos"],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+)
+
+write_file(
+ name = "_highgui_config.hpp",
+ out = "opencv_highgui_config.hpp",
+ content = select({
+ ":have_qt": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"QT\"",
+ ],
+ ":have_gtk3": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"GTK3\"",
+ ],
+ "@platforms//os:macos": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"COCOA\"",
+ ],
+ "@platforms//os:windows": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"WIN32UI\"",
+ ],
+ "//conditions:default": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"\"",
+ ],
+ }),
+)
+
+# NOTE: HighGUI is not a hermetic module, it depends on system-provided GUI libraries
+# Referencing of system libs based on https://stackoverflow.com/questions/51408079/how-do-i-reference-a-system-library-used-by-an-external-dependency-if-copts-does
+
+genrule(
+ name = "highgui_qrc",
+ srcs = ["modules/highgui/src/window_QT.qrc"] + glob(["modules/highgui/src/files_Qt/Material/*.png"]),
+ outs = ["qrc_window_QT.cpp"],
+ cmd = select({
+ "@rules_qt//:linux_x86_64": "$(location @qt_linux_x86_64//:rcc) -name window_QT $(location modules/highgui/src/window_QT.qrc) -o $@",
+ "@rules_qt//:linux_aarch64": "$(location @qt_linux_aarch64//:rcc) -name window_QT $(location modules/highgui/src/window_QT.qrc) -o $@",
+ "@rules_qt//:osx_arm64": "$(location @qt_mac_aarch64//:rcc) -name window_QT $(location modules/highgui/src/window_QT.qrc) -o $@",
+ "@rules_qt//:osx_x86_64": "$(location @qt_mac_x86_64//:rcc) -name window_QT $(location modules/highgui/src/window_QT.qrc) -o $@",
+ "@platforms//os:windows": "$(location @qt_windows_x86_64//:rcc) -name window_QT $(location modules/highgui/src/window_QT.qrc) -o $@",
+ }),
+ tools = select({
+ "@rules_qt//:linux_x86_64": ["@qt_linux_x86_64//:rcc"],
+ "@rules_qt//:linux_aarch64": ["@qt_linux_aarch64//:rcc"],
+ "@rules_qt//:osx_arm64": ["@qt_mac_aarch64//:rcc"],
+ "@rules_qt//:osx_x86_64": ["@qt_mac_x86_64//:rcc"],
+ "@platforms//os:windows": ["@qt_windows_x86_64//:rcc"],
+ }),
+ tags = ["local"],
+)
+
+qt_cc_library(
+ name = "highgui_qt",
+ srcs = [
+ "modules/highgui/src/window_QT.cpp",
+ ":highgui_qrc",
+ ],
+ hdrs = ["modules/highgui/src/window_QT.h"],
+ normal_hdrs = ["opencv_highgui_config.hpp"] + glob([
+ "modules/highgui/include/**/*.hpp",
+ "modules/highgui/include/**/*.h",
+ "modules/highgui/src/**/*.hpp",
+ "modules/highgui/src/**/*.h",
+ ], exclude = ["modules/highgui/src/window_QT.h"]),
+ copts = OPENCV_COPTS + OPENCV_OPTIMIZATION_COPTS,
+ includes = ["modules/highgui/include"],
+ local_defines = ["HAVE_QT=1"],
+ deps = [
+ ":_base_headers",
+ ":videoio",
+ ":imgcodecs",
+ "@rules_qt//:qt_widgets",
+ "@rules_qt//:qt_gui",
+ "@rules_qt//:qt_core",
+ "@rules_qt//:qt_concurrent",
+ "@rules_qt//:qt_test",
+ ],
+ target_compatible_with = select({
+ ":have_qt": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+)
+
+opencv_module(
+ name = "highgui",
+ deps = [
+ ":videoio",
+ ":imgcodecs",
+ ] + select({
+ ":have_qt": [":highgui_qt"],
+ ":have_gtk3": [":gtk3"],
+ "@platforms//os:macos": [":ocv.3rdparty.cocoa"],
+ "//conditions:default": [],
+ }),
+ local_defines = select({
+ ":have_qt": ["HAVE_QT=1"],
+ ":have_gtk3": ["HAVE_GTK3=1", "HAVE_GTK=1"],
+ "@platforms//os:macos": ["HAVE_COCOA=1"],
+ "@platforms//os:windows": ["HAVE_WIN32UI=1"],
+ "//conditions:default": [],
+ }),
+ sources = [
+ "modules/highgui/src/backend.cpp",
+ "modules/highgui/src/window.cpp",
+ "modules/highgui/src/roiSelector.cpp",
+ "opencv_highgui_config.hpp",
+ ] + select({
+ ":have_gtk3": [
+ "modules/highgui/src/window_gtk.cpp",
+ ],
+ "@platforms//os:windows": [
+ "modules/highgui/src/window_w32.cpp",
+ ],
+ "//conditions:default": [],
+ }),
+ linkopts = select({
+ "@platforms//os:windows": [
+ "user32.lib",
+ "gdi32.lib",
+ ],
+ "//conditions:default": [],
+ }),
+ compatible_with = select({
+ "@platforms//os:linux": ["@platforms//os:linux"],
+ "@platforms//os:windows": ["@platforms//os:windows"],
+ "@platforms//os:macos": ["@platforms//os:macos"],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+)
+
+################ FLAGS and configuration settings ################
+
+
+bool_flag(
+ name = "disable_allocator_stats",
+ build_setting_default = True,
+)
+
+config_setting(
+ name = "have_allocator_stats",
+ flag_values = {":disable_allocator_stats": "False"},
+)
+
+bool_flag(
+ name = "with_eigen",
+ build_setting_default = False,
+)
+
+config_setting(
+ name = "have_eigen",
+ flag_values = {":with_eigen": "True"},
+)
+
+config_setting(
+ name = "debug_build",
+ values = {"compilation_mode": "dbg"},
+)
+
+config_setting(
+ name = "emscripten_with_simd",
+ constraint_values = [
+ "@platforms//os:emscripten",
+ ],
+ values = {
+ "features": "wasm_simd",
+ },
+)
+
+config_setting(
+ name = "ubsan_enabled",
+ values = {
+ "features": "ubsan",
+ },
+)
+
+bool_flag(
+ name = "with_gtk3",
+ build_setting_default = False,
+)
+
+config_setting(
+ name = "have_gtk3",
+ flag_values = {":with_gtk3": "True"},
+)
+
+bool_flag(
+ name = "with_qt",
+ build_setting_default = False,
+)
+
+config_setting(
+ name = "have_qt",
+ flag_values = {":with_qt": "True"},
+)
+
+# TODO: replace with BCR version of GTK3 after https://github.com/bazelbuild/bazel-central-registry/issues/6187 is resolved
+label_flag(
+ name = "gtk3",
+ build_setting_default = ":gtk3_stub",
+)
+
+cc_library(
+ name = "gtk3_stub",
+ target_compatible_with = ["@platforms//:incompatible"],
+)
diff --git a/modules/opencv/4.12.0.bcr.6/overlay/MODULE.bazel b/modules/opencv/4.12.0.bcr.6/overlay/MODULE.bazel
new file mode 100644
index 0000000..3578a73
--- /dev/null
+++ b/modules/opencv/4.12.0.bcr.6/overlay/MODULE.bazel
@@ -0,0 +1,39 @@
+module(
+ name = "opencv",
+ version = "4.12.0.bcr.6",
+ bazel_compatibility = [">=7.2.1"],
+ compatibility_level = 0,
+)
+
+bazel_dep(name = "apple_support", version = "2.2.0")
+bazel_dep(name = "bazel_skylib", version = "1.9.0")
+bazel_dep(name = "rules_cc", version = "0.2.17")
+bazel_dep(name = "rules_license", version = "1.0.0")
+bazel_dep(name = "platforms", version = "1.0.0")
+bazel_dep(name = "libpng", version = "1.6.54")
+bazel_dep(name = "libjpeg_turbo", version = "3.1.3.bcr.4")
+bazel_dep(name = "zlib", version = "1.3.1.bcr.8")
+bazel_dep(name = "eigen", version = "5.0.1")
+bazel_dep(name = "libtiff", version = "4.7.1")
+bazel_dep(name = "libwebp", version = "1.5.0")
+bazel_dep(name = "rules_qt", version = "0.0.7")
+
+
+# Needed for cpufeatures library which is a dependency of OpenCV when building for Android
+bazel_dep(name = "cpu_features", version = "0.11.0.bcr.1")
+
+rules_qt_fetch = use_extension("@rules_qt//extension:qt.bzl", "fetch")
+rules_qt_fetch.install(
+ name = "qt_mac_x86_64",
+ build_file = "@rules_qt//extension:qt/6.8.3/mac_aarch64.BUILD",
+ os = "macos",
+ version = "6.8.3",
+)
+rules_qt_fetch.install(
+ name = "qt_windows_x86_64",
+ build_file = "@rules_qt//extension:qt/6.8.3/windows_x86_64.BUILD",
+ os = "windows",
+ version = "6.8.3",
+ windows_architecture = "win64_msvc2022",
+)
+use_repo(rules_qt_fetch, "qt_linux_x86_64", "qt_linux_aarch64", "qt_mac_aarch64", "qt_mac_x86_64", "qt_windows_x86_64")
diff --git a/modules/opencv/4.12.0.bcr.6/overlay/opencv.bzl b/modules/opencv/4.12.0.bcr.6/overlay/opencv.bzl
new file mode 100644
index 0000000..963a0df
--- /dev/null
+++ b/modules/opencv/4.12.0.bcr.6/overlay/opencv.bzl
@@ -0,0 +1,566 @@
+load("@bazel_skylib//rules:write_file.bzl", "write_file")
+load("@rules_cc//cc:defs.bzl", "cc_library")
+
+OPENCV_COPTS = [
+ "-D_USE_MATH_DEFINES",
+ "-D__OPENCV_BUILD=1",
+ "-D__STDC_CONSTANT_MACROS",
+ "-D__STDC_FORMAT_MACROS",
+ "-D__STDC_LIMIT_MACROS",
+] + select({
+ "@platforms//os:macos": ["-Wno-implicit-function-declaration"],
+ "//conditions:default": [],
+})
+
+OPENCV_OPTIMIZATION_COPTS = select({
+ "//:debug_build": [],
+ "//conditions:default": [
+ "-Os",
+ ]
+})
+
+# NOTE: The copts here are compatible with GCC and Clang, except for PPCLE64 which are clang-specific.
+# This is based on OpenCVCompilerOptimizations.cmake
+# TODO: Add support for MSVC and ICC.
+
+# NOTE: Starlark does not support while loops nor recursion, sw we have to manually compute full "implies" and "copts"
+_KNOWN_OPTS = {
+ "x86_64": {
+ "sse": {
+ "copts": ["-msse"],
+ "implies": [],
+ },
+ "sse2": {
+ "copts": ["-msse", "-msse2"],
+ "implies": ["sse"],
+ },
+ "sse3": {
+ "copts": ["-msse", "-msse2", "-msse3"],
+ "implies": ["sse", "sse2"],
+ },
+ "ssse3": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3"],
+ "implies": ["sse", "sse2", "sse3"],
+ },
+ "sse4_1": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1"],
+ "implies": ["sse", "sse2", "sse3", "ssse3"],
+ },
+ "popcnt": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1"],
+ },
+ "sse4_2": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt"],
+ },
+ "avx": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mavx"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2"],
+ },
+ "fp16": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mavx"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx"],
+ },
+ "fma3": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mfma", "-mavx"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx"],
+ },
+ "avx2": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16"],
+ },
+ "avx_512f": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2"],
+ },
+ "avx512_common": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f"],
+ },
+ "avx512_knl": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512er", "-mavx512pf"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common"],
+ },
+ "avx512_knm": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512er", "-mavx512pf", "-mavx5124fmaps", "-mavx5124vnniw", "-mavx512vpopcntdq"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common", "avx512_knl"],
+ },
+ "avx512_skx": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common"],
+ },
+ "avx512_cnl": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl", "-mavx512ifma", "-mavx512vbmi"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common", "avx512_skx"],
+ },
+ "avx512_clx": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl", "-mavx512vnni"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common", "avx512_skx"],
+ },
+ "avx512_icl": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl", "-mavx512ifma", "-mavx512vbmi2", "-mavx512bitalg", "-mavx512vpopcntdq"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common", "avx512_skx"],
+ },
+ },
+ "armv7": {
+ "vfpv3": {
+ "copts": ["-mfpu=vfpv3"],
+ "implies": [],
+ },
+ "neon": {
+ "copts": ["-mfpu=neon"],
+ "implies": [],
+ },
+ "fp16": {
+ "copts": ["-mfpu=neon-fp16", "-mfp16-format=ieee"],
+ "implies": ["neon"],
+ },
+ },
+ "arm64": {
+ "neon": {
+ "copts": [],
+ "implies": [],
+ },
+ "fp16": {
+ "copts": [],
+ "implies": ["neon"],
+ },
+ "neon_dotprod": {
+ "copts": ["-march=armv8.2-a+dotprod"],
+ "implies": ["neon"],
+ },
+ "neon_fp16": {
+ "copts": ["-march=armv8.2-a+fp16"],
+ "implies": ["neon"],
+ },
+ "neon_bf16": {
+ "copts": ["-march=armv8.2-a+bf16"],
+ "implies": ["neon"],
+ },
+ },
+ "mips64": {
+ "msa": {
+ "copts": ["-mmsa"],
+ "implies": [],
+ },
+ },
+ "ppc64le": {
+ "vsx": {
+ "copts": ["-mvsx", "-maltivec"],
+ "implies": [],
+ },
+ "vsx3": {
+ "copts": ["-mvsx", "-maltivec", "-mpower9-vector"],
+ "implies": ["vsx"],
+ },
+ },
+ "riscv64": {
+ "rvv": {
+ "copts": [],
+ "implies": [],
+ },
+ },
+ "loongarch64": {
+ "lsx": {
+ "copts": ["-mlsx"],
+ "implies": [],
+ },
+ "lasx": {
+ "copts": ["-mlasx"],
+ "implies": [],
+ },
+ },
+}
+
+def _arch_for_opt(opt):
+ for arch, opts in _KNOWN_OPTS.items():
+ if opt in opts:
+ return arch
+ fail("Unknown optimization: {}".format(opt))
+
+
+# Optimizations that will always be enabled for a given architecture
+# All other optimizations will be dispatched at runtime
+# TODO: make these configurable via build flag
+BASELINE_OPTS = {
+ "x86_64": ["sse", "sse2", "sse3"],
+ "armv7": ["neon"],
+ "arm64": ["neon", "fp16"],
+ "mips64": [],
+ "ppc64le": [],
+ "riscv64": [],
+ "loongarch64": [],
+}
+
+def _calc_enabled_opts():
+ enabled_opts = {}
+ for arch, baseline_opts in BASELINE_OPTS.items():
+ possible_opts = _KNOWN_OPTS[arch].keys()
+ dispatched_opts = [opt for opt in possible_opts if opt not in baseline_opts]
+ enabled_opts[arch] = {
+ "baseline": baseline_opts,
+ "dispatched": dispatched_opts,
+ }
+ return enabled_opts
+
+ENABLED_OPTS = _calc_enabled_opts()
+
+# OpenCV modules that will be built
+# TODO: make this configurable via build flag
+MODULES_COMMON = [
+ "calib3d",
+ "core",
+ "features2d",
+ "flann",
+ "imgcodecs",
+ "imgproc",
+ "objdetect",
+ "photo",
+]
+
+MODULES_DESKTOP = MODULES_COMMON + [
+ "videoio",
+ "highgui",
+]
+
+CONFIG_BASE = {
+ "stub_opencl": [
+ "core",
+ "imgproc",
+ "features2d",
+ "calib3d",
+ "objdetect",
+ "photo",
+ ],
+ "contains_src_headers": [
+ "imgproc",
+ "imgcodecs",
+ "features2d",
+ "calib3d",
+ "videoio",
+ ],
+ "contains_3rdparty": [
+ "features2d",
+ ],
+}
+
+def _merge_dicts(dict1, dict2):
+ merged = dict(dict1) # Create a copy of the first dictionary
+ merged.update(dict2) # Update with the second dictionary
+ return merged
+
+CONFIG_DESKTOP =_merge_dicts(CONFIG_BASE, {
+ "modules": MODULES_DESKTOP,
+})
+
+CONFIG_NON_DESKTOP = _merge_dicts(CONFIG_BASE, {
+ "modules": MODULES_COMMON,
+})
+
+def opencv_module(
+ name,
+ dispatched_files = {},
+ deps = [],
+ copts = [],
+ linkopts = [],
+ local_defines = [],
+ compatible_with = [],
+ sources = None, # reserved for modules that list sources explicitly, such as videoio or highgui
+ ):
+ """
+ Creates a Bazel rule for an OpenCV module.
+
+ Args:
+ name: The name of the module.
+ dispatched_files: A mapping of keys to a list of operators.
+ deps: A list of dependencies for the module.
+ copts: Additional compiler options.
+ linkopts: Additional linker options.
+ """
+ prefix = "modules/{}".format(name)
+ dispatched_files = dispatched_files
+ extra_headers = []
+
+ glob_hdrs = [
+ prefix + "/include/**/*.hpp",
+ prefix + "/include/**/*.h",
+ ]
+
+ # Stub out opencl as all empty since we don't need to use any opencl functionality
+ if name in CONFIG_BASE["stub_opencl"]:
+ header_file = prefix + "/src/opencl_kernels_{}.hpp".format(name)
+ write_file(
+ name = "_{}".format(header_file),
+ content = [
+ "#include \"opencv2/core/ocl.hpp\"",
+ "#include \"opencv2/core/ocl_genbase.hpp\"",
+ "#include \"opencv2/core/opencl/ocl_defs.hpp\"",
+ ],
+ out = header_file,
+ )
+ extra_headers.append(header_file)
+
+ # A Helper target to hold the headers generated in module's src dir
+ # This is to avoid hacks with `copts` to include src dir as this can lead to issues
+ # with include paths when target is used as a dependency from other modules
+ cc_library(
+ name = name + "_generated_headers",
+ hdrs = extra_headers,
+ strip_include_prefix = prefix + "/src",
+ )
+
+ simd_extra_headers = []
+
+ dispatched_targets = {
+ "@platforms//cpu:x86_64": [],
+ "@platforms//cpu:armv7": [],
+ "@platforms//cpu:arm64": [],
+ "@platforms//cpu:mips64": [],
+ "@platforms//cpu:ppc64le": [],
+ "@platforms//cpu:riscv64": [],
+ # "@platforms//cpu:loongarch64": [],
+ "//conditions:default": [],
+ }
+
+ for fname, opts in dispatched_files.items():
+ # Define file paths for SIMD declarations and SIMD header
+ simd_declarations = "{}/src/{}.simd_declarations.hpp".format(prefix, fname)
+ simd_filename = "{}/src/{}.simd.hpp".format(prefix, fname)
+
+ simd_definitions_start = [
+ "#define CV_CPU_SIMD_FILENAME \"{}\"".format(simd_filename),
+ ]
+ simd_opts = {
+ "x86_64": [],
+ "armv7": [],
+ "arm64": [],
+ "mips64": [],
+ "ppc64le": [],
+ "riscv64": [],
+ "loongarch64": [],
+ }
+ dispatch_simd = {
+ "x86_64": [],
+ "armv7": [],
+ "arm64": [],
+ "mips64": [],
+ "ppc64le": [],
+ "riscv64": [],
+ "loongarch64": [],
+ }
+ for opt in opts:
+ arch = _arch_for_opt(opt)
+ if opt not in ENABLED_OPTS[arch]["baseline"]:
+ simd_opts[arch] += [
+ "#define CV_CPU_DISPATCH_MODE {}".format(opt.upper()),
+ "#include \"opencv2/core/private/cv_cpu_include_simd_declarations.hpp\"",
+ ]
+ dispatch_simd[arch] += [opt]
+
+ dispatch_modes_simd = {}
+ dispatch_modes_empty = [
+ "#define CV_CPU_DISPATCH_MODES_ALL BASELINE",
+ ]
+ for arch, dispatched_opts in dispatch_simd.items():
+ if len(dispatched_opts) > 0 and arch != "loongarch64": # loongarch64 currently not supported by bazel platforms
+ dispatch_modes_simd[arch] = [
+ "#define CV_CPU_DISPATCH_MODES_ALL " + ", ".join([x.upper() for x in reversed(dispatched_opts) + ["BASELINE"]]),
+ ]
+
+ # also, create a cc_library for each dispatched file and add it to list of deps
+ for opt in dispatched_opts:
+ simd_cpp_file = "{}/src/{}.{}.cpp".format(prefix, fname, opt)
+
+ write_file(
+ name = "_{}".format(simd_cpp_file),
+ out = simd_cpp_file,
+ content = [
+ "#include \"{}/src/precomp.hpp\"".format(prefix),
+ "#include \"{}/src/{}.simd.hpp\"".format(prefix, fname),
+ ],
+ )
+
+ simd_target_name = "_{}/src/{}_{}_{}_{}_simd".format(prefix, name, fname, arch, opt)
+
+ cc_library(
+ name = simd_target_name,
+ srcs = [
+ simd_cpp_file,
+ simd_declarations,
+ ] + native.glob([
+ prefix + "/src/**/*.hpp",
+ prefix + "/src/**/*.h"
+ ],
+ allow_empty = True
+ ),
+ hdrs = native.glob(glob_hdrs, allow_empty = True),
+ deps = deps + [":_base_headers"],
+ # note: some files don't include generated simd_declarations.hpp, so
+ # we need to define CV_CPU_DISPATCH_MODE here as well
+ # notable example: color_hsv operators in imgproc module
+ # This workaround also exist in OpenCVCompilerOptimizations.cmake
+ # in function ocv_compiler_optimization_process_sources
+ local_defines = [
+ "CV_CPU_DISPATCH_MODE={}".format(opt.upper()),
+ "CV_CPU_COMPILE_{}=1".format(opt.upper()),
+ ] + [
+ "CV_CPU_COMPILE_{}=1".format(x.upper())
+ for x in _KNOWN_OPTS[arch][opt]["implies"]
+ if x not in ENABLED_OPTS[arch]["baseline"]
+ ],
+ implementation_deps = [":" + name + "_generated_headers"],
+ copts = OPENCV_COPTS + OPENCV_OPTIMIZATION_COPTS +
+ copts +
+ _KNOWN_OPTS[arch][opt]["copts"] +
+ select({
+ ":ubsan_enabled": [
+ "-fno-sanitize=alignment", # alignment sanitizer will catch these, but they are intentional in most SIMD code
+ ],
+ "//conditions:default": [],
+ }),
+ target_compatible_with = ["@platforms//cpu:{}".format(arch)],
+ strip_include_prefix = prefix + "/include",
+ features = [
+ "exceptions", # enable exceptions for opencv modules
+ ],
+ )
+ dispatched_targets["@platforms//cpu:{}".format(arch)].append(Label(":" + simd_target_name))
+ else:
+ dispatch_modes_simd[arch] = dispatch_modes_empty
+
+ simd_definitions_end = ["#undef CV_CPU_SIMD_FILENAME"]
+ simd_extra_headers.append(simd_declarations)
+
+ select_dict = {}
+ for arch in simd_opts.keys():
+ if arch != "loongarch64": # loongarch64 currently not supported by bazel platforms
+ select_dict["@platforms//cpu:{}".format(arch)] = simd_definitions_start + simd_opts[arch] + dispatch_modes_simd[arch] + simd_definitions_end
+
+ select_dict["//conditions:default"] = simd_definitions_start + dispatch_modes_empty + simd_definitions_end
+
+ # Write the SIMD declarations to the file
+ write_file(
+ name = "_{}".format(simd_declarations),
+ # note, simd_opts declarations are mainly for x86_64
+ content = select(select_dict),
+ out = simd_declarations,
+ )
+
+ glob_srcs = [prefix + "/src/**/*.cpp", prefix + "/src/**/*.hpp"]
+ if name in CONFIG_BASE["contains_src_headers"]:
+ glob_srcs.append(prefix + "/src/**/*.h")
+ if name in CONFIG_BASE["contains_3rdparty"]:
+ glob_srcs.append(prefix + "/3rdparty/**/*.h")
+
+ baseline_copts = {
+ "//conditions:default": [],
+ }
+
+ # exclude handcrafted SIMD files from the main srcs and include them only in their respective cc_library
+ srcs_excludes = []
+ # however, for baseline optimizations, any handcrafted SIMD files should be included back in the main srcs
+ srcs_baseline_includes = []
+
+ # A Helper target to hold the headers generated in module's src dir
+ # This is to avoid hacks with `copts` to include src dir as this can lead to issues
+ # with include paths when target is used as a dependency from other modules
+ cc_library(
+ name = name + "_generated_simd_headers",
+ hdrs = simd_extra_headers,
+ strip_include_prefix = prefix + "/src",
+ deps = [":" + name + "_generated_headers"],
+ )
+
+ for arch, opts in ENABLED_OPTS.items():
+ srcs_excludes += [
+ prefix + "/src/**/*.{}.cpp".format(x)
+ for x in opts["dispatched"]
+ ]
+ if arch != "loongarch64": # loongarch64 currently not supported by bazel platforms
+ arch_flags = []
+ for opt in opts["baseline"]:
+ arch_flags += _KNOWN_OPTS[arch][opt]["copts"]
+ srcs_baseline_includes.append(prefix + "/src/**/*.{}.cpp".format(opt))
+ baseline_copts["@platforms//cpu:{}".format(arch)] = arch_flags
+
+ # some modules have hand-optimized version for specific dispatched optimization
+ # This will not be covered by the dispatched cc_library above, so we need to add additional target for it
+
+ for opt in opts["dispatched"]:
+ simd_target_name = "_{}/src/{}_{}_{}_simd_handcrafted".format(prefix, name, arch, opt)
+
+ cc_library(
+ name = simd_target_name,
+ srcs = native.glob(
+ [
+ prefix + "/src/**/*.hpp",
+ prefix + "/src/**/*.h",
+ prefix + "/src/**/*.{}.cpp".format(opt)
+ ],
+ allow_empty = True
+ ),
+ hdrs = native.glob(glob_hdrs, allow_empty = True),
+ deps = deps + [":_base_headers"],
+ # note: some files don't include generated simd_declarations.hpp, so
+ # we need to define CV_CPU_DISPATCH_MODE here as well
+ # notable example: color_hsv operators in imgproc module
+ # This workaround also exist in OpenCVCompilerOptimizations.cmake
+ # in function ocv_compiler_optimization_process_sources
+ local_defines = [
+ "CV_CPU_DISPATCH_MODE={}".format(opt.upper()),
+ "CV_CPU_COMPILE_{}=1".format(opt.upper()),
+ ] + [
+ "CV_CPU_COMPILE_{}=1".format(x.upper())
+ for x in _KNOWN_OPTS[arch][opt]["implies"]
+ if x not in ENABLED_OPTS[arch]["baseline"]
+ ],
+ implementation_deps = [":" + name + "_generated_simd_headers"],
+ copts = OPENCV_COPTS + OPENCV_OPTIMIZATION_COPTS +
+ copts +
+ _KNOWN_OPTS[arch][opt]["copts"] +
+ select({
+ ":ubsan_enabled": [
+ "-fno-sanitize=alignment", # alignment sanitizer will catch these, but they are intentional in most SIMD code
+ ],
+ "//conditions:default": [],
+ }),
+ target_compatible_with = ["@platforms//cpu:{}".format(arch)],
+ strip_include_prefix = prefix + "/include",
+ features = [
+ "exceptions", # enable exceptions for opencv modules
+ ],
+ )
+ dispatched_targets["@platforms//cpu:{}".format(arch)].append(Label(":" + simd_target_name))
+
+ if sources != None:
+ # used by videoio and highgui modules
+ full_sources = sources
+ else:
+ full_sources = native.glob(glob_srcs, exclude = srcs_excludes) + native.glob(srcs_baseline_includes, allow_empty = True)
+
+ cc_library(
+ name = name,
+ srcs = full_sources,
+ hdrs = native.glob(glob_hdrs, allow_empty = True),
+ deps = deps + [":_base_headers"] + select(dispatched_targets),
+ copts = OPENCV_COPTS +
+ OPENCV_OPTIMIZATION_COPTS +
+ copts +
+ select(baseline_copts) +
+ select({
+ ":ubsan_enabled": [
+ "-fno-sanitize=alignment", # alignment sanitizer will catch these, but they are intentional in most SIMD code (which may be included in baseline)
+ ],
+ "//conditions:default": [],
+ }),
+ implementation_deps = [":" + name + "_generated_simd_headers"],
+ linkopts = linkopts,
+ local_defines = local_defines,
+ target_compatible_with = compatible_with,
+ strip_include_prefix = prefix + "/include",
+ features = [
+ "exceptions", # enable exceptions for opencv modules
+ ],
+ visibility = ["//visibility:public"],
+ )
diff --git a/modules/opencv/4.12.0.bcr.6/overlay/test/BUILD.bazel b/modules/opencv/4.12.0.bcr.6/overlay/test/BUILD.bazel
new file mode 100644
index 0000000..a7b8461
--- /dev/null
+++ b/modules/opencv/4.12.0.bcr.6/overlay/test/BUILD.bazel
@@ -0,0 +1,11 @@
+load("@rules_qt//:qt.bzl", "qt_cc_test")
+
+qt_cc_test(
+ name = "qt6_smoke_test",
+ srcs = ["qt6_smoke_test.cpp"],
+ env = {"QT_QPA_PLATFORM": "offscreen"},
+ deps = [
+ "@opencv//:core",
+ "@opencv//:highgui",
+ ],
+)
diff --git a/modules/opencv/4.12.0.bcr.6/overlay/test/MODULE.bazel b/modules/opencv/4.12.0.bcr.6/overlay/test/MODULE.bazel
new file mode 100644
index 0000000..197291f
--- /dev/null
+++ b/modules/opencv/4.12.0.bcr.6/overlay/test/MODULE.bazel
@@ -0,0 +1,29 @@
+bazel_dep(name = "apple_support", version = "2.2.0")
+bazel_dep(name = "rules_cc", version = "0.2.17")
+bazel_dep(name = "platforms", version = "1.0.0")
+bazel_dep(name = "opencv", version = "4.12.0.bcr.5")
+bazel_dep(name = "rules_qt", version = "0.0.7")
+
+local_path_override(
+ module_name = "opencv",
+ path = "..",
+)
+
+new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
+new_local_repository(name = "ubuntu-gtk-deps", build_file = "//:ubuntu-gtk-deps.BUILD.bazel", path = "/")
+
+rules_qt_fetch = use_extension("@rules_qt//extension:qt.bzl", "fetch")
+rules_qt_fetch.install(
+ name = "qt_mac_x86_64",
+ build_file = "@rules_qt//extension:qt/6.8.3/mac_aarch64.BUILD",
+ os = "macos",
+ version = "6.8.3",
+)
+rules_qt_fetch.install(
+ name = "qt_windows_x86_64",
+ build_file = "@rules_qt//extension:qt/6.8.3/windows_x86_64.BUILD",
+ os = "windows",
+ version = "6.8.3",
+ windows_architecture = "win64_msvc2022",
+)
+use_repo(rules_qt_fetch, "qt_linux_x86_64", "qt_linux_aarch64", "qt_mac_aarch64", "qt_mac_x86_64", "qt_windows_x86_64")
diff --git a/modules/opencv/4.12.0.bcr.6/overlay/test/qt6_smoke_test.cpp b/modules/opencv/4.12.0.bcr.6/overlay/test/qt6_smoke_test.cpp
new file mode 100644
index 0000000..cedadd0
--- /dev/null
+++ b/modules/opencv/4.12.0.bcr.6/overlay/test/qt6_smoke_test.cpp
@@ -0,0 +1,14 @@
+#include <opencv2/core.hpp>
+#include <opencv2/highgui.hpp>
+#include <iostream>
+
+// Exercises the Qt6 highgui backend end-to-end (window creation, event pump,
+// teardown) under Qt's offscreen QPA platform so it can run headless in CI.
+int main() {
+ cv::Mat img(64, 64, CV_8UC3, cv::Scalar(240, 240, 240));
+ cv::imshow("qt6_smoke_test", img);
+ cv::waitKey(1000);
+ cv::destroyAllWindows();
+ std::cout << "qt6 highgui smoke test OK" << std::endl;
+ return 0;
+}
diff --git a/modules/opencv/4.12.0.bcr.6/overlay/test/ubuntu-gtk-deps.BUILD.bazel b/modules/opencv/4.12.0.bcr.6/overlay/test/ubuntu-gtk-deps.BUILD.bazel
new file mode 100644
index 0000000..af46d76
--- /dev/null
+++ b/modules/opencv/4.12.0.bcr.6/overlay/test/ubuntu-gtk-deps.BUILD.bazel
@@ -0,0 +1,200 @@
+load("@rules_cc//cc:cc_import.bzl", "cc_import")
+load("@rules_cc//cc:cc_library.bzl", "cc_library")
+
+package(default_visibility = ["//visibility:public"])
+
+cc_import(
+ name = "gtk3",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgtk-3.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgtk-3.so",
+ }),
+ hdrs = glob(["usr/include/gtk-3.0/**/*.h"]),
+ strip_include_prefix = "usr/include/gtk-3.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":gdk3",
+ ":atk",
+ ],
+)
+
+cc_import(
+ name = "gdk3",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgdk-3.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgdk-3.so",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":pangocairo",
+ ":gdk_pixbuf",
+ ":gio",
+ ":glib",
+ ],
+)
+
+cc_import(
+ name = "pangocairo",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libpangocairo-1.0.so",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":pango",
+ ":cairo",
+ ],
+)
+
+cc_import(
+ name = "pango",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libpango-1.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libpango-1.0.so",
+ }),
+ hdrs = glob(["usr/include/pango-1.0/**/*.h"]),
+ strip_include_prefix = "usr/include/pango-1.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":harfbuzz",
+ ":glib",
+ ":gobject",
+ ],
+)
+
+cc_import(
+ name = "harfbuzz",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libharfbuzz.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libharfbuzz.so",
+ }),
+ hdrs = glob(["usr/include/harfbuzz/**/*.h"]),
+ strip_include_prefix = "usr/include/harfbuzz",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glib",
+ ],
+)
+
+cc_import(
+ name = "atk",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libatk-1.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libatk-1.0.so",
+ }),
+ hdrs = glob(["usr/include/atk-1.0/**/*.h"]),
+ strip_include_prefix = "usr/include/atk-1.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":cairo",
+ ],
+)
+
+cc_import(
+ name = "cairo-gobject",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libcairo-gobject.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libcairo-gobject.so",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":cairo",
+ ":gobject",
+ ],
+)
+
+cc_import(
+ name = "cairo",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libcairo.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libcairo.so",
+ }),
+ hdrs = glob(["usr/include/cairo/**/*.h"]),
+ strip_include_prefix = "usr/include/cairo",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":gdk_pixbuf",
+ ":gio",
+ ],
+)
+
+cc_import(
+ name = "gdk_pixbuf",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgdk_pixbuf-2.0.so",
+ }),
+ hdrs = glob(["usr/include/gdk-pixbuf-2.0/**/*.h"]),
+ strip_include_prefix = "usr/include/gdk-pixbuf-2.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glib",
+ ":gobject",
+ ],
+)
+
+cc_import(
+ name = "gio",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgio-2.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgio-2.0.so",
+ }),
+ hdrs = glob(["usr/include/gio-unix-2.0/**/*.h"]),
+ strip_include_prefix = "usr/include/gio-unix-2.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glib",
+ ":gobject",
+ ],
+)
+
+cc_import(
+ name = "gobject",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgobject-2.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgobject-2.0.so",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glib",
+ ],
+)
+
+cc_library(
+ name = "glibconfig-headers",
+ hdrs = select({
+ "@platforms//cpu:x86_64": glob(["usr/lib/x86_64-linux-gnu/glib-2.0/include/**/*.h"], allow_empty = True),
+ "@platforms//cpu:aarch64": glob(["usr/lib/aarch64-linux-gnu/glib-2.0/include/**/*.h"], allow_empty = True),
+ }),
+ strip_include_prefix = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/glib-2.0/include",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/glib-2.0/include",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+)
+
+cc_import(
+ name = "glib",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libglib-2.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libglib-2.0.so",
+ }),
+ hdrs = glob(["usr/include/glib-2.0/**/*.h"]),
+ strip_include_prefix = "usr/include/glib-2.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glibconfig-headers",
+ ],
+)
diff --git a/modules/opencv/4.12.0.bcr.6/presubmit.yml b/modules/opencv/4.12.0.bcr.6/presubmit.yml
new file mode 100644
index 0000000..4a27145
--- /dev/null
+++ b/modules/opencv/4.12.0.bcr.6/presubmit.yml
@@ -0,0 +1,91 @@
+bcr_test_module:
+ module_path: test
+ matrix:
+ # Currently does not build in Windows due to SIMD dispatch flags not taking into account cl.exe
+ # Also, for HighGUI on Linux, a GTK3 is needed, which should be provided via @opencv//:gtk3 label flag.
+ # This is tested only on Ubuntu, where test module installs the GTK3 with system's package manager and
+ # then imports it to the workspace.
+ ubuntu_with_gtk3:
+ - ubuntu2204
+ - ubuntu2004_arm64
+ # Qt 6.8.3 x86_64 and and aarch64 on both Mac and Linux. It also supports windows x86_64,
+ # but OpenCV doesn't currently work for windows, so we won't try and add support for it.
+ # Note that linux-aarch64 requires a glibc version >= 2.34 that requires Ubuntu 24.04+.
+ qt6_platforms:
+ - ubuntu2204
+ - ubuntu2404_arm64
+ - macos
+ - macos_arm64
+ platform:
+ - rockylinux8
+ - debian11
+ - ubuntu2204
+ - ubuntu2004_arm64
+ - macos
+ - macos_arm64
+ bazel:
+ - 7.x
+ - 8.x
+ - 9.x
+ tasks:
+ verify_targets:
+ name: Verify build targets
+ platform: ${{ platform }}
+ bazel: ${{ bazel }}
+ build_targets:
+ - '@opencv//:opencv'
+ verify_targets_gtk3:
+ name: Verify build targets on Ubuntu with system GTK3
+ platform: ${{ ubuntu_with_gtk3 }}
+ bazel: 8.x
+ shell_commands:
+ - sudo apt update && sudo apt install -y libgtk-3-dev
+ build_flags:
+ - "--@opencv//:gtk3=@ubuntu-gtk-deps//:gtk3"
+ - "--@opencv//:with_gtk3=True"
+ build_targets:
+ - '@opencv//:opencv'
+ verify_targets_qt6:
+ name: Verify build targets for Qt6
+ platform: ${{ qt6_platforms }}
+ bazel: 8.x
+ build_flags:
+ - "--@opencv//:with_qt=True"
+ build_targets:
+ - '@opencv//:opencv'
+ run_qt6_smoke_test_ubuntu_x86_64:
+ name: Run Qt6 smoke test on linux (x86_64)
+ platform: ubuntu2204
+ bazel: 8.x
+ shell_commands:
+ - sudo apt-get update && sudo apt-get install -y libegl-dev libegl1-mesa-dev libfontconfig1-dev libgl-dev libgl1-mesa-dev libpulse-dev libx11-xcb-dev libxcb-cursor-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxkbcommon-dev libxkbcommon-x11-dev
+ test_flags:
+ - "--@opencv//:with_qt=True"
+ test_targets:
+ - '//:qt6_smoke_test'
+ run_qt6_smoke_test_ubuntu_aarch64:
+ name: Run Qt6 smoke test on linux (arm64)
+ platform: ubuntu2404_arm64
+ bazel: 8.x
+ shell_commands:
+ - sudo apt-get update && sudo apt-get install -y libegl-dev libegl1-mesa-dev libfontconfig1-dev libgl-dev libgl1-mesa-dev libpulse-dev libx11-xcb-dev libxcb-cursor-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxkbcommon-dev libxkbcommon-x11-dev
+ test_flags:
+ - "--@opencv//:with_qt=True"
+ test_targets:
+ - '//:qt6_smoke_test'
+ run_qt6_smoke_test_macos_x86_64:
+ name: Run Qt6 smoke test on macOS (x86_64)
+ platform: macos
+ bazel: 8.x
+ test_flags:
+ - "--@opencv//:with_qt=True"
+ test_targets:
+ - '//:qt6_smoke_test'
+ run_qt6_smoke_test_macos_arm64:
+ name: Run Qt6 smoke test on macOS (arm64)
+ platform: macos_arm64
+ bazel: 8.x
+ test_flags:
+ - "--@opencv//:with_qt=True"
+ test_targets:
+ - '//:qt6_smoke_test'
\ No newline at end of file
diff --git a/modules/opencv/4.12.0.bcr.6/source.json b/modules/opencv/4.12.0.bcr.6/source.json
new file mode 100644
index 0000000..c42e9e2
--- /dev/null
+++ b/modules/opencv/4.12.0.bcr.6/source.json
@@ -0,0 +1,14 @@
+{
+ "integrity": "sha256-RMEG1btH7+wE5TH9kwCLP80dJxOJhcW69Or6wOHsnp0=",
+ "strip_prefix": "opencv-4.12.0",
+ "url": "https://github.com/opencv/opencv/archive/refs/tags/4.12.0.tar.gz",
+ "overlay": {
+ "BUILD.bazel": "sha256-KC1PvHln4Fv1+X7fXFRnp+CAmae9k9F6FVocDJpreDo=",
+ "MODULE.bazel": "sha256-2gGMVGtM/+qW8+xPwgq/o8eRf5ButF95AFKZC4UVa7w=",
+ "opencv.bzl": "sha256-UU2ON2LJOrr9pGlzHXOC27CnmjBZ1y2P9h9TC+sGRYU=",
+ "test/BUILD.bazel": "sha256-782O4a0cKgYULLMsMeB8gvXznfjpPj9fjztPQLh/HDU=",
+ "test/MODULE.bazel": "sha256-iD5yXzgFPStpN2ECQOCvt5UFr3qxdt3KKlb6wBWE9tM=",
+ "test/qt6_smoke_test.cpp": "sha256-xjWbsRR7yDGWs0+mYiI2WvzLLsGT13wI2Tdt3NU3dCs=",
+ "test/ubuntu-gtk-deps.BUILD.bazel": "sha256-coCXi1DH9iVC6q8qwiI3qndFVmUkNjtRhpIsSIXC9P0="
+ }
+}
diff --git a/modules/opencv/4.13.0.bcr.6/MODULE.bazel b/modules/opencv/4.13.0.bcr.6/MODULE.bazel
new file mode 100644
index 0000000..f636074
--- /dev/null
+++ b/modules/opencv/4.13.0.bcr.6/MODULE.bazel
@@ -0,0 +1,22 @@
+module(
+ name = "opencv",
+ version = "4.13.0.bcr.6",
+ bazel_compatibility = [">=7.2.1"],
+ compatibility_level = 0,
+)
+
+bazel_dep(name = "apple_support", version = "2.3.0")
+bazel_dep(name = "bazel_skylib", version = "1.9.0")
+bazel_dep(name = "rules_cc", version = "0.2.17")
+bazel_dep(name = "rules_license", version = "1.0.0")
+bazel_dep(name = "platforms", version = "1.0.0")
+bazel_dep(name = "libpng", version = "1.6.54")
+bazel_dep(name = "libjpeg_turbo", version = "3.1.3.bcr.4")
+bazel_dep(name = "libtiff", version = "4.7.1")
+bazel_dep(name = "zlib", version = "1.3.2")
+bazel_dep(name = "eigen", version = "5.0.1.bcr.1")
+bazel_dep(name = "protobuf", version = "33.4") # Note: Needs to be pinned to the same version used by the rules_android. See this comment: https://github.com/bazelbuild/rules_android/issues/435#issuecomment-3753825840
+
+# Needed for cpufeatures library which is a dependency of OpenCV when building for Android
+bazel_dep(name = "cpu_features", version = "0.11.0.bcr.1")
+
diff --git a/modules/opencv/4.13.0.bcr.6/overlay/BUILD.bazel b/modules/opencv/4.13.0.bcr.6/overlay/BUILD.bazel
new file mode 100644
index 0000000..a4f0604
--- /dev/null
+++ b/modules/opencv/4.13.0.bcr.6/overlay/BUILD.bazel
@@ -0,0 +1,926 @@
+load("@bazel_skylib//lib:selects.bzl", "selects")
+load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
+load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
+load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
+load("@bazel_skylib//rules:write_file.bzl", "write_file")
+load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
+load("@protobuf//bazel:proto_library.bzl", "proto_library")
+load("@rules_cc//cc:cc_library.bzl", "cc_library")
+load("@rules_cc//cc:objc_library.bzl", "objc_library")
+load("@rules_license//rules:license.bzl", "license")
+
+load(
+ "//:opencv.bzl",
+ "CONFIG_DESKTOP",
+ "CONFIG_NON_DESKTOP",
+ "ENABLED_OPTS",
+ "OPENCV_COPTS",
+ "OPENCV_OPTIMIZATION_COPTS",
+ "opencv_module",
+)
+
+package(
+ default_applicable_licenses = [":license"],
+)
+
+license(
+ name = "license",
+ license_kinds = ["@rules_license//licenses/spdx:Apache-2.0"],
+ license_text = "LICENSE",
+)
+
+exports_files([
+ "LICENSE",
+])
+
+write_file(
+ name = "_private/version_string.inc",
+ out = "private/version_string.inc",
+ content = ["\"4.13.0\""],
+)
+
+write_file(
+ name = "_opencv2/opencv_modules_desktop.hpp",
+ out = "opencv2/opencv_modules_desktop.hpp",
+ content = ["".join([
+ "#define HAVE_OPENCV_{}\n".format(x.upper())
+ for x in CONFIG_DESKTOP["modules"]
+ ])],
+)
+
+write_file(
+ name = "_opencv2/opencv_modules_non_desktop.hpp",
+ out = "opencv2/opencv_modules_non_desktop.hpp",
+ content = ["".join([
+ "#define HAVE_OPENCV_{}\n".format(x.upper())
+ for x in CONFIG_NON_DESKTOP["modules"]
+ ])],
+)
+
+copy_file(
+ name = "generate_opencv_modules_hpp",
+ src = select({
+ "@platforms//os:linux": "opencv2/opencv_modules_desktop.hpp",
+ "@platforms//os:macos": "opencv2/opencv_modules_desktop.hpp",
+ "@platforms//os:windows": "opencv2/opencv_modules_desktop.hpp",
+ "//conditions:default": "opencv2/opencv_modules_non_desktop.hpp",
+ }),
+ out = "opencv2/opencv_modules.hpp",
+)
+
+write_file(
+ name = "_custom_hal.hpp",
+ out = "custom_hal.hpp",
+ content = [
+ "#ifndef _CUSTOM_HAL_INCLUDED_",
+ "#define _CUSTOM_HAL_INCLUDED_",
+ "#endif",
+ ],
+)
+
+write_file(
+ name = "_opencv_data_config.hpp",
+ out = "opencv_data_config.hpp",
+ content = [
+ "#define OPENCV_INSTALL_PREFIX \"\"",
+ "#define OPENCV_DATA_INSTALL_PATH \"\"",
+ "#define OPENCV_BUILD_DIR \"\"",
+ "#define OPENCV_DATA_BUILD_DIR_SEARCH_PATHS \"\"",
+ "#define OPENCV_INSTALL_DATA_DIR_RELATIVE \"\"",
+ ],
+)
+
+[
+ write_file(
+ name = "_bazel-config/cv_cpu_config-{}.h".format(arch),
+ out = "bazel-config/cv_cpu_config-{}.h".format(arch),
+ content = [
+ "// OpenCV CPU baseline features\n",
+ ] + [
+ "#define CV_CPU_COMPILE_{} 1\n#define CV_CPU_BASELINE_COMPILE_{} 1\n".format(arch.upper(), arch.upper())
+ for arch in config.get("baseline", [])
+ ] + [
+ "#define CV_CPU_BASELINE_FEATURES 0 \\",
+ ] + [
+ " , CV_CPU_{} \\".format(arch.upper())
+ for arch in config.get("baseline", [])
+ ] + [
+ "\n",
+ "// OpenCV supported CPU dispathed features\n",
+ ] + [
+ "#define CV_CPU_DISPATCH_COMPILE_{} 1".format(arch.upper())
+ for arch in config.get("dispatch", [])
+ ] + [
+ "\n#define CV_CPU_DISPATCH_FEATURES 0 \\",
+ ] + [
+ " , CV_CPU_{} \\".format(arch.upper())
+ for arch in config.get("dispatch", [])
+ ] + [
+ "\n",
+ ],
+ ) for arch, config in ENABLED_OPTS.items()
+]
+
+write_file(
+ name = "_bazel-config/cv_cpu_config_no_baseline.h",
+ out = "bazel-config/cv_cpu_config_no_baseline.h",
+ content = [
+ "// OpenCV CPU baseline features\n",
+ "#define CV_CPU_BASELINE_FEATURES 0\n",
+ "// OpenCV supported CPU dispathed features\n",
+ "#define CV_CPU_DISPATCH_FEATURES 0\n",
+ ],
+)
+
+copy_file(
+ name = "_cv_cpu_config.h",
+ out = "cv_cpu_config.h",
+ src = select({
+ "@platforms//cpu:arm64": "bazel-config/cv_cpu_config-arm64.h",
+ "@platforms//cpu:armv7": "bazel-config/cv_cpu_config-armv7.h",
+ "@platforms//cpu:x86_64": "bazel-config/cv_cpu_config-x86_64.h",
+ "@platforms//cpu:mips64": "bazel-config/cv_cpu_config-mips64.h",
+ "@platforms//cpu:ppc64le": "bazel-config/cv_cpu_config-ppc64le.h",
+ "@platforms//cpu:riscv64": "bazel-config/cv_cpu_config-riscv64.h",
+ # LoongArch is not yet supported in the official platforms repo
+ # "@platforms//cpu:loongarch64": "bazel-config/cv_cpu_config-loongarch64.h",
+ "//conditions:default": "bazel-config/cv_cpu_config_no_baseline.h",
+ }),
+)
+
+# Opencv has a lot of options to enable certain features
+# Leverage this, cv_cpu_config.h, and cpu opts to enable these features
+expand_template(
+ name = "expand_cvconfig.h.in",
+ out = "cvconfig.h",
+ substitutions = {
+ "#cmakedefine BUILD_SHARED_LIBS\n": "/* #undef BUILD_SHARED_LIBS */\n",
+ "#cmakedefine CV_ENABLE_INTRINSICS\n": "#define CV_ENABLE_INTRINSICS\n",
+ "#cmakedefine CV_DISABLE_OPTIMIZATION\n": "/* #undef CV_DISABLE_OPTIMIZATION */\n",
+ "${OPENCV_CUDA_ARCH_BIN}": "",
+ "${OPENCV_CUDA_ARCH_FEATURES}": "",
+ "${OPENCV_CUDA_ARCH_PTX}": "",
+ "#cmakedefine HAVE_CLAMDBLAS\n": "/* #undef HAVE_CLAMDBLAS */\n",
+ "#cmakedefine HAVE_CLAMDFFT\n": "/* #undef HAVE_CLAMDFFT */\n",
+ "#cmakedefine HAVE_CLP\n": "/* #undef HAVE_CLP */\n",
+ "#cmakedefine HAVE_CUDA\n": "/* #undef HAVE_CUDA */\n",
+ "#cmakedefine HAVE_CUBLAS\n": "/* #undef HAVE_CUBLAS */\n",
+ "#cmakedefine HAVE_CUDNN\n": "/* #undef HAVE_CUDNN */\n",
+ "#cmakedefine HAVE_CUFFT\n": "/* #undef HAVE_CUFFT */\n",
+ "#cmakedefine HAVE_DIRECTX\n": "/* #undef HAVE_DIRECTX */\n",
+ "#cmakedefine HAVE_DIRECTX_NV12\n": "/* #undef HAVE_DIRECTX_NV12 */\n",
+ "#cmakedefine HAVE_D3D11\n": "/* #undef HAVE_D3D11 */\n",
+ "#cmakedefine HAVE_D3D10\n": "/* #undef HAVE_D3D10 */\n",
+ "#cmakedefine HAVE_D3D9\n": "/* #undef HAVE_D3D9 */\n",
+ "#cmakedefine HAVE_GDAL\n": "/* #undef HAVE_GDAL */\n",
+ "#cmakedefine HAVE_HALIDE\n": "/* #undef HAVE_HALIDE */\n",
+ "#cmakedefine HAVE_VULKAN\n": "/* #undef HAVE_VULKAN */\n",
+ "#cmakedefine HAVE_INTTYPES_H 1\n": "/* #undef HAVE_INTTYPES_H */\n",
+ "#cmakedefine HAVE_IPP\n": "/* #undef HAVE_IPP */\n",
+ "#cmakedefine HAVE_IPP_IW_LL\n": "/* #undef HAVE_IPP_IW_LL */",
+ "#cmakedefine HAVE_IPP_ICV\n": "/* #undef HAVE_IPP_ICV */\n",
+ "#cmakedefine HAVE_IPP_IW\n": "/* #undef HAVE_IPP_IW */\n",
+ "#cmakedefine HAVE_IPP_A\n": "/* #undef HAVE_IPP_A */\n",
+ "#cmakedefine HAVE_OPENJPEG\n": "/* #undef HAVE_OPENJPEG */\n",
+ "#cmakedefine HAVE_JASPER\n": "/* #undef HAVE_JASPER */\n",
+ "#cmakedefine HAVE_AVIF\n": "/* #undef HAVE_AVIF */\n",
+ "#cmakedefine HAVE_JPEG\n": "#define HAVE_JPEG 1\n",
+ "#cmakedefine HAVE_JPEGXL\n": "/* #undef HAVE_JPEGXL */\n",
+ "#cmakedefine HAVE_GDCM\n": "/* #undef HAVE_GDCM */\n",
+ "#cmakedefine HAVE_NVCUVID\n": "/* #undef HAVE_NVCUVID */\n",
+ "#cmakedefine HAVE_NVCUVID_HEADER\n": "/* #undef HAVE_NVCUVID_HEADER */\n",
+ "#cmakedefine HAVE_DYNLINK_NVCUVID_HEADER\n": "/* #undef HAVE_DYNLINK_NVCUVID_HEADER */\n",
+ "#cmakedefine HAVE_NVCUVENC\n": "/* #undef HAVE_NVCUVENC */\n",
+ "#cmakedefine HAVE_OPENCL\n": "/* #undef HAVE_OPENCL */\n",
+ "#cmakedefine HAVE_OPENCL_STATIC\n": "/* #undef HAVE_OPENCL_STATIC */\n",
+ "#cmakedefine HAVE_OPENCL_SVM\n": "/* #undef HAVE_OPENCL_SVM */\n",
+ "#cmakedefine HAVE_OPENCL_D3D11_NV\n": "/* #undef HAVE_OPENCL_D3D11_NV */\n",
+ "#cmakedefine HAVE_OPENEXR\n": "/* #undef HAVE_OPENEXR */\n",
+ "#cmakedefine HAVE_OPENGL\n": "/* #undef HAVE_OPENGL */\n",
+ "#cmakedefine HAVE_PNG\n": "#define HAVE_PNG 1\n",
+ "#cmakedefine HAVE_SPNG\n": "/* #undef HAVE_SPNG */\n",
+ "#cmakedefine HAVE_PTHREAD\n": "#define HAVE_PTHREAD\n",
+ "#cmakedefine HAVE_PTHREADS_PF\n": "#define HAVE_PTHREADS_PF\n",
+ "#cmakedefine HAVE_TBB\n": "/* #undef HAVE_TBB */\n",
+ "#cmakedefine HAVE_HPX\n": "/* #undef HAVE_HPX */\n",
+ "#cmakedefine HAVE_TIFF\n": "#define HAVE_TIFF 1\n",
+ "#cmakedefine WORDS_BIGENDIAN\n": "/* #undef WORDS_BIGENDIAN */\n",
+ "#cmakedefine HAVE_VA\n": "/* #undef HAVE_VA */\n",
+ "#cmakedefine HAVE_VA_INTEL\n": "/* #undef HAVE_VA_INTEL */\n",
+ "#cmakedefine HAVE_LAPACK\n": "/* #undef HAVE_LAPACK */\n",
+ "#cmakedefine ENABLE_INSTRUMENTATION\n": "/* #undef ENABLE_INSTRUMENTATION */\n",
+ "#cmakedefine HAVE_OPENVX\n": "/* #undef HAVE_OPENVX */\n",
+ "#cmakedefine OPENCV_TRACE\n": "/* #undef OPENCV_TRACE */\n",
+ "#cmakedefine HAVE_QUIRC\n": "/* undef HAVE_QUIRC */\n",
+ } | select({
+ ":have_eigen": {
+ "#cmakedefine HAVE_EIGEN\n": "#define HAVE_EIGEN 1\n",
+ },
+ "//conditions:default": {
+ "#cmakedefine HAVE_EIGEN\n": "/* #undef HAVE_EIGEN */\n",
+ },
+ }),
+ template = "@opencv//:cmake/templates/cvconfig.h.in",
+)
+
+cc_library(
+ name = "_base_headers",
+ hdrs = [
+ "custom_hal.hpp",
+ "cv_cpu_config.h",
+ "cvconfig.h",
+ "opencv2/opencv_modules.hpp",
+ "opencv_data_config.hpp",
+ "include/opencv2/opencv.hpp",
+ ],
+ includes = [
+ "opencv2",
+ "private",
+ "include",
+ ],
+ textual_hdrs = [
+ "private/version_string.inc",
+ ],
+ defines = select({
+ ":emscripten_with_simd": ["CV_WASM_SIMD=1"],
+ "@platforms//os:emscripten": ["CV_FORCE_SIMD128_CPP=1"], # Use CPP SIMD emulation on Emscripten when WASM SIMD is not available
+ "//conditions:default": [],
+ })
+)
+
+cc_library(
+ name = "opencv",
+ deps = selects.with_or({
+ ("@platforms//os:linux", "@platforms//os:macos", "@platforms//os:windows"): [":" + module for module in CONFIG_DESKTOP["modules"]],
+ "//conditions:default": [":" + module for module in CONFIG_NON_DESKTOP["modules"]],
+ }),
+ visibility = ["//visibility:public"],
+)
+
+# Escape hatch for consumers that need the Android NDK's own cpufeatures instead
+# of the `@cpu_features` implementation, e.g. one provided by `rules_android_ndk`:
+# --@opencv//:cpufeatures=@androidndk//:cpufeatures
+label_flag(
+ name = "cpufeatures",
+ build_setting_default = "@cpu_features//:ndk_compat",
+ visibility = ["//visibility:public"],
+)
+
+cc_library(
+ name = "cpufeatures_android",
+ hdrs = ["3rdparty/cpufeatures/cpu-features.h"],
+ strip_include_prefix = "3rdparty/cpufeatures",
+ deps = [
+ ":cpufeatures",
+ ],
+ target_compatible_with = ["@platforms//os:android"],
+)
+
+opencv_module(
+ name = "core",
+ dispatched_files = {
+ "mathfuncs_core": [
+ "sse2",
+ "avx",
+ "avx2",
+ "lasx",
+ ],
+ "stat": [
+ "sse4_2",
+ "avx2",
+ "lasx",
+ ],
+ "arithm": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ "vsx3",
+ "lasx",
+ ],
+ "convert": [
+ "sse2",
+ "avx2",
+ "vsx3",
+ "lasx",
+ ],
+ "convert_scale": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "count_non_zero": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "has_non_zero": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "matmul": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ "avx512_skx",
+ "neon_dotprod",
+ "lasx",
+ ],
+ "mean": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "merge": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "split": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "sum": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "norm": [
+ "sse2",
+ "sse4_1",
+ "avx",
+ "avx2",
+ "neon_dotprod",
+ "lasx",
+ ],
+ },
+ linkopts = select({
+ "@platforms//os:linux": ["-ldl", "-lpthread", "-lrt"],
+ "//conditions:default": [],
+ }),
+ local_defines = select({
+ ":have_allocator_stats": [],
+ "//conditions:default": [
+ "OPENCV_DISABLE_ALLOCATOR_STATS=1"
+ ],
+ }) + select({
+ "@platforms//os:android": [
+ "HAVE_CPUFEATURES=1",
+ ],
+ "//conditions:default": [],
+ }) + selects.with_or({
+ "@platforms//os:windows": [
+ "HAVE_WIN32_ALIGNED_MALLOC=1",
+ ],
+ ("@platforms//os:macos", "@platforms//os:ios"): [
+ "HAVE_POSIX_MEMALIGN=1",
+ ],
+ ("@platforms//os:android", "@platforms//os:linux", "@platforms//os:emscripten"): [
+ "HAVE_POSIX_MEMALIGN=1",
+ "HAVE_MALLOC_H=1",
+ "HAVE_MEMALIGN=1",
+ ],
+ "//conditions:default": [ ],
+ }) + select({
+ ":ubsan_enabled": [
+ "CV_STRONG_ALIGNMENT=1", # UBSan checks for strict alignment
+ ],
+ "//conditions:default": [],
+ }),
+ copts = select({
+ ":ubsan_enabled": [
+ "-fno-sanitize=function", # call to function cv::hal::sub32f via pointer of incorrect type
+ ],
+ "//conditions:default": [],
+ }),
+ deps = [
+ "@zlib",
+ ] + select({
+ "@platforms//os:android": [":cpufeatures_android"],
+ "//conditions:default": [],
+ }) + select({
+ ":have_eigen": ["@eigen"],
+ "//conditions:default": [],
+ }),
+)
+
+opencv_module(
+ name = "imgproc",
+ copts = [
+ "-Wno-deprecated-enum-float-conversion",
+ "-Wno-deprecated-volatile",
+ ],
+ dispatched_files = {
+ "accum": [
+ "sse4_1",
+ "avx",
+ "avx2",
+ ],
+ "bilateral_filter": [
+ "sse2",
+ "avx2",
+ ],
+ "box_filter": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "filter": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "color_hsv": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "color_rgb": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "color_yuv": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "median_blur": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "morph": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "smooth": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "sumpixels": [
+ "sse2",
+ "avx2",
+ "avx512_skx",
+ ],
+ },
+ deps = [":core"],
+)
+
+opencv_module(
+ name = "features2d",
+ copts = [
+ "-Wno-deprecated-enum-float-conversion",
+ "-Wno-deprecated-volatile",
+ ],
+ dispatched_files = {
+ "sift": [
+ "sse4_1",
+ "avx2",
+ "avx512_skx",
+ ],
+ },
+ deps = [
+ ":imgproc",
+ ":flann",
+ ],
+)
+
+proto_library(
+ name = "dnn_tf_msgs_proto",
+ srcs = glob([
+ "modules/dnn/src/tensorflow/**/*.proto",
+ ]),
+ strip_import_prefix = "modules/dnn/src/tensorflow",
+)
+
+cc_proto_library(
+ name = "dnn_tf_msgs",
+ deps = [ ":dnn_tf_msgs_proto" ],
+)
+
+proto_library(
+ name = "dnn_caffe_msgs_proto",
+ srcs = glob([
+ "modules/dnn/src/caffe/**/*.proto",
+ ]),
+ strip_import_prefix = "modules/dnn/src/caffe",
+)
+
+cc_proto_library(
+ name = "dnn_caffe_msgs",
+ deps = [ ":dnn_caffe_msgs_proto" ],
+)
+
+proto_library(
+ name = "dnn_onnx_msgs_proto",
+ srcs = glob([
+ "modules/dnn/src/onnx/**/*.proto",
+ ]),
+ strip_import_prefix = "modules/dnn/src/onnx",
+)
+
+cc_proto_library(
+ name = "dnn_onnx_msgs",
+ deps = [ ":dnn_onnx_msgs_proto" ],
+)
+
+opencv_module(
+ name = "dnn",
+ copts = [
+ "-Wno-deprecated-enum-float-conversion",
+ "-Wno-deprecated-volatile",
+ ],
+ local_defines = [
+ "HAVE_PROTOBUF=1",
+ ],
+ srcs_excludes_globs = [
+ "modules/dnn/src/ocl4dnn/**",
+ "modules/dnn/src/cuda4dnn/**",
+ ],
+ force_dispatch = True,
+ dispatched_files = {
+ "layers/layers_common": [
+ "avx",
+ "avx2",
+ "avx512_skx",
+ "rvv",
+ "lasx",
+ "neon",
+ "sve"
+ ],
+ "int8layers/layers_common": [
+ "avx2",
+ "avx512_skx",
+ "rvv",
+ "lasx",
+ "neon",
+ ],
+ "layers/cpu_kernels/conv_block": [
+ "avx",
+ "avx2",
+ "neon",
+ "neon_fp16",
+ ],
+ "layers/cpu_kernels/conv_depthwise": [
+ "avx",
+ "avx2",
+ "rvv",
+ "lasx",
+ ],
+ "layers/cpu_kernels/conv_winograd_f63": [
+ "avx",
+ "avx2",
+ "neon",
+ "neon_fp16",
+ ],
+ "layers/cpu_kernels/fast_gemm_kernels": [
+ "avx",
+ "avx2",
+ "neon",
+ "lasx",
+ ],
+ },
+ deps = [
+ ":imgproc",
+ ":dnn_caffe_msgs",
+ ":dnn_onnx_msgs",
+ ":dnn_tf_msgs",
+ ],
+)
+
+opencv_module(
+ name = "flann",
+ deps = [":core"],
+)
+
+opencv_module(
+ name = "calib3d",
+ copts = [
+ "-Wno-deprecated-enum-float-conversion",
+ ],
+ dispatched_files = {
+ "undistort": [
+ "sse2",
+ "avx2",
+ ],
+ },
+ deps = [
+ ":imgproc",
+ ":features2d",
+ ":flann",
+ ],
+)
+
+opencv_module(
+ name = "imgcodecs",
+ local_defines = [
+ "HAVE_IMGCODEC_PXM",
+ "HAVE_IMGCODEC_PFM",
+ "HAVE_IMGCODEC_HDR",
+ "HAVE_IMGCODEC_SUNRASTER",
+ "HAVE_IMGCODEC_GIF",
+ ],
+ deps = [
+ ":imgproc",
+ "@libjpeg_turbo//:jpeg",
+ "@libpng",
+ "@libtiff//:tiff",
+ ],
+)
+
+opencv_module(
+ name = "objdetect",
+ deps = [
+ ":dnn",
+ ":calib3d",
+ ":imgproc",
+ ":core",
+ ],
+)
+
+opencv_module(
+ name = "video",
+ deps = [
+ ":calib3d",
+ ":imgproc",
+ ":dnn",
+ ],
+)
+
+# TODO: add build flags for enabling varoious video backends on different platforms
+objc_library(
+ name = "ocv.3rdparty.avfoundation",
+ srcs = select({
+ "@platforms//os:macos": [
+ "modules/videoio/src/cap_avfoundation_mac.mm",
+ ],
+ "@platforms//os:ios": [
+ "modules/videoio/src/cap_avfoundation.mm",
+ ],
+ "//conditions:default": [],
+ }),
+ hdrs = glob([
+ "modules/videoio/src/**/*.h",
+ "modules/videoio/src/**/*.hpp",
+ "modules/videoio/include/**/*.hpp",
+ "modules/videoio/include/**/*.h",
+ ]),
+ includes = [
+ "modules/videoio/include",
+ "modules/videoio/src",
+ ],
+ copts = OPENCV_COPTS + OPENCV_OPTIMIZATION_COPTS + [
+ "-fno-objc-arc", # Disable Automatic Reference Counting, as OpenCV uses manual reference counting
+ ],
+ linkopts = select({
+ "@platforms//os:macos": [
+ "-framework Cocoa",
+ "-framework Accelerate",
+ "-framework AVFoundation",
+ "-framework CoreGraphics",
+ "-framework CoreMedia",
+ "-framework CoreVideo",
+ "-framework QuartzCore",
+ ],
+ "@platforms//os:ios": [
+ "-framework AVFoundation",
+ "-framework QuartzCore",
+ ],
+ }),
+ deps = [
+ ":imgproc",
+ ":imgcodecs",
+ ],
+ target_compatible_with = select({
+ "@platforms//os:macos": ["@platforms//os:macos"],
+ "@platforms//os:ios": ["@platforms//os:ios"],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+)
+
+opencv_module(
+ name = "photo",
+ deps = [
+ ":core",
+ ":imgproc",
+ ],
+)
+
+opencv_module(
+ name = "videoio",
+ deps = [
+ ":imgproc",
+ ":imgcodecs",
+ ] + select({
+ "@platforms//os:macos": [":ocv.3rdparty.avfoundation"],
+ "@platforms//os:ios": [":ocv.3rdparty.avfoundation"],
+ "//conditions:default": [],
+ }),
+ local_defines = select({
+ "@platforms//os:macos": ["HAVE_AVFOUNDATION=1"],
+ "@platforms//os:ios": ["HAVE_AVFOUNDATION=1"],
+ "@platforms//os:linux": ["HAVE_CAMV4L=1", "HAVE_CAMV4L2=1"],
+ "@platforms//os:windows": ["HAVE_DSHOW=1"],
+ "//conditions:default": [],
+ }),
+ sources = [
+ "modules/videoio/src/videoio_registry.cpp",
+ "modules/videoio/src/videoio_c.cpp",
+ "modules/videoio/src/cap.cpp",
+ "modules/videoio/src/cap_images.cpp",
+ "modules/videoio/src/cap_mjpeg_encoder.cpp",
+ "modules/videoio/src/cap_mjpeg_decoder.cpp",
+ "modules/videoio/src/backend_plugin.cpp",
+ "modules/videoio/src/backend_static.cpp",
+ "modules/videoio/src/container_avi.cpp",
+ ] + select({
+ "@platforms//os:linux": [
+ "modules/videoio/src/cap_v4l.cpp",
+ ],
+ "@platforms//os:windows": [
+ "modules/videoio/src/cap_dshow.cpp",
+ ],
+ "//conditions:default": [],
+ }),
+ compatible_with = select({
+ "@platforms//os:linux": ["@platforms//os:linux"],
+ "@platforms//os:windows": ["@platforms//os:windows"],
+ "@platforms//os:macos": ["@platforms//os:macos"],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+)
+
+objc_library(
+ name = "ocv.3rdparty.cocoa",
+ srcs = [
+ "opencv_highgui_config.hpp",
+ ] + select({
+ "@platforms//os:macos": [
+ "modules/highgui/src/window_cocoa.mm",
+ ],
+ "//conditions:default": [],
+ }),
+ hdrs = glob([
+ "modules/highgui/src/**/*.h",
+ "modules/highgui/src/**/*.hpp",
+ "modules/highgui/include/**/*.hpp",
+ "modules/highgui/include/**/*.h",
+ ]),
+ includes = [
+ "modules/highgui/include",
+ "modules/highgui/src",
+ ],
+ copts = OPENCV_COPTS + OPENCV_OPTIMIZATION_COPTS + [
+ "-fno-objc-arc", # Disable Automatic Reference Counting, as OpenCV uses manual reference counting
+ ],
+ linkopts = select({
+ "@platforms//os:macos": [
+ "-framework Cocoa",
+ ],
+ }),
+ deps = [
+ ":videoio",
+ ":imgcodecs",
+ ],
+ target_compatible_with = select({
+ "@platforms//os:macos": ["@platforms//os:macos"],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+)
+
+write_file(
+ name = "_highgui_config.hpp",
+ out = "opencv_highgui_config.hpp",
+ content = select({
+ ":have_gtk3": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"GTK3\"",
+ ],
+ "@platforms//os:macos": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"COCOA\"",
+ ],
+ "@platforms//os:windows": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"WIN32UI\"",
+ ],
+ "//conditions:default": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"\"",
+ ],
+ }),
+)
+
+# NOTE: HighGUI is not a hermetic module, it depends on system-provided GUI libraries
+# Referencing of system libs based on https://stackoverflow.com/questions/51408079/how-do-i-reference-a-system-library-used-by-an-external-dependency-if-copts-does
+
+opencv_module(
+ name = "highgui",
+ deps = [
+ ":videoio",
+ ":imgcodecs",
+ ] + select({
+ ":have_gtk3": [":gtk3"],
+ "@platforms//os:macos": [":ocv.3rdparty.cocoa"],
+ "//conditions:default": [],
+ }),
+ local_defines = select({
+ ":have_gtk3": ["HAVE_GTK3=1", "HAVE_GTK=1"],
+ "@platforms//os:macos": ["HAVE_COCOA=1"],
+ "@platforms//os:windows": ["HAVE_WIN32UI=1"],
+ "//conditions:default": [],
+ }),
+ sources = [
+ "modules/highgui/src/backend.cpp",
+ "modules/highgui/src/window.cpp",
+ "modules/highgui/src/roiSelector.cpp",
+ "opencv_highgui_config.hpp",
+ ] + select({
+ ":have_gtk3": [
+ "modules/highgui/src/window_gtk.cpp",
+ ],
+ "@platforms//os:windows": [
+ "modules/highgui/src/window_w32.cpp",
+ ],
+ "//conditions:default": [],
+ }),
+ linkopts = select({
+ "@platforms//os:windows": [
+ "user32.lib",
+ "gdi32.lib",
+ ],
+ "//conditions:default": [],
+ }),
+ compatible_with = select({
+ "@platforms//os:linux": ["@platforms//os:linux"],
+ "@platforms//os:windows": ["@platforms//os:windows"],
+ "@platforms//os:macos": ["@platforms//os:macos"],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+)
+
+################ FLAGS and configuration settings ################
+
+
+bool_flag(
+ name = "disable_allocator_stats",
+ build_setting_default = True,
+)
+
+config_setting(
+ name = "have_allocator_stats",
+ flag_values = {":disable_allocator_stats": "False"},
+)
+
+bool_flag(
+ name = "with_eigen",
+ build_setting_default = False,
+)
+
+config_setting(
+ name = "have_eigen",
+ flag_values = {":with_eigen": "True"},
+)
+
+config_setting(
+ name = "debug_build",
+ values = {"compilation_mode": "dbg"},
+)
+
+config_setting(
+ name = "emscripten_with_simd",
+ constraint_values = [
+ "@platforms//os:emscripten",
+ ],
+ values = {
+ "features": "wasm_simd",
+ },
+)
+
+config_setting(
+ name = "ubsan_enabled",
+ values = {
+ "features": "ubsan",
+ },
+)
+
+bool_flag(
+ name = "with_gtk3",
+ build_setting_default = False,
+)
+
+config_setting(
+ name = "have_gtk3",
+ flag_values = {":with_gtk3": "True"},
+)
+
+# TODO: replace with BCR version of GTK3 after https://github.com/bazelbuild/bazel-central-registry/issues/6187 is resolved
+label_flag(
+ name = "gtk3",
+ build_setting_default = ":gtk3_stub",
+)
+
+cc_library(
+ name = "gtk3_stub",
+ target_compatible_with = ["@platforms//:incompatible"],
+)
diff --git a/modules/opencv/4.13.0.bcr.6/overlay/MODULE.bazel b/modules/opencv/4.13.0.bcr.6/overlay/MODULE.bazel
new file mode 100644
index 0000000..f636074
--- /dev/null
+++ b/modules/opencv/4.13.0.bcr.6/overlay/MODULE.bazel
@@ -0,0 +1,22 @@
+module(
+ name = "opencv",
+ version = "4.13.0.bcr.6",
+ bazel_compatibility = [">=7.2.1"],
+ compatibility_level = 0,
+)
+
+bazel_dep(name = "apple_support", version = "2.3.0")
+bazel_dep(name = "bazel_skylib", version = "1.9.0")
+bazel_dep(name = "rules_cc", version = "0.2.17")
+bazel_dep(name = "rules_license", version = "1.0.0")
+bazel_dep(name = "platforms", version = "1.0.0")
+bazel_dep(name = "libpng", version = "1.6.54")
+bazel_dep(name = "libjpeg_turbo", version = "3.1.3.bcr.4")
+bazel_dep(name = "libtiff", version = "4.7.1")
+bazel_dep(name = "zlib", version = "1.3.2")
+bazel_dep(name = "eigen", version = "5.0.1.bcr.1")
+bazel_dep(name = "protobuf", version = "33.4") # Note: Needs to be pinned to the same version used by the rules_android. See this comment: https://github.com/bazelbuild/rules_android/issues/435#issuecomment-3753825840
+
+# Needed for cpufeatures library which is a dependency of OpenCV when building for Android
+bazel_dep(name = "cpu_features", version = "0.11.0.bcr.1")
+
diff --git a/modules/opencv/4.13.0.bcr.6/overlay/opencv.bzl b/modules/opencv/4.13.0.bcr.6/overlay/opencv.bzl
new file mode 100644
index 0000000..c64b3c0
--- /dev/null
+++ b/modules/opencv/4.13.0.bcr.6/overlay/opencv.bzl
@@ -0,0 +1,583 @@
+load("@bazel_skylib//rules:write_file.bzl", "write_file")
+load("@rules_cc//cc:defs.bzl", "cc_library")
+
+OPENCV_COPTS = [
+ "-D_USE_MATH_DEFINES",
+ "-D__OPENCV_BUILD=1",
+ "-D__STDC_CONSTANT_MACROS",
+ "-D__STDC_FORMAT_MACROS",
+ "-D__STDC_LIMIT_MACROS",
+]
+
+OPENCV_OPTIMIZATION_COPTS = select({
+ "//:debug_build": [],
+ "//conditions:default": [
+ "-Os",
+ ]
+})
+
+# NOTE: The copts here are compatible with GCC and Clang, except for PPCLE64 which are clang-specific.
+# This is based on OpenCVCompilerOptimizations.cmake
+# TODO: Add support for MSVC and ICC.
+
+# NOTE: Starlark does not support while loops nor recursion, sw we have to manually compute full "implies" and "copts"
+_KNOWN_OPTS = {
+ "x86_64": {
+ "sse": {
+ "copts": ["-msse"],
+ "implies": [],
+ },
+ "sse2": {
+ "copts": ["-msse", "-msse2"],
+ "implies": ["sse"],
+ },
+ "sse3": {
+ "copts": ["-msse", "-msse2", "-msse3"],
+ "implies": ["sse", "sse2"],
+ },
+ "ssse3": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3"],
+ "implies": ["sse", "sse2", "sse3"],
+ },
+ "sse4_1": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1"],
+ "implies": ["sse", "sse2", "sse3", "ssse3"],
+ },
+ "popcnt": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1"],
+ },
+ "sse4_2": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt"],
+ },
+ "avx": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mavx"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2"],
+ },
+ "fp16": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mavx"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx"],
+ },
+ "fma3": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mfma", "-mavx"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx"],
+ },
+ "avx2": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16"],
+ },
+ "avx_512f": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2"],
+ },
+ "avx512_common": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f"],
+ },
+ "avx512_knl": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512er", "-mavx512pf"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common"],
+ },
+ "avx512_knm": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512er", "-mavx512pf", "-mavx5124fmaps", "-mavx5124vnniw", "-mavx512vpopcntdq"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common", "avx512_knl"],
+ },
+ "avx512_skx": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common"],
+ },
+ "avx512_cnl": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl", "-mavx512ifma", "-mavx512vbmi"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common", "avx512_skx"],
+ },
+ "avx512_clx": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl", "-mavx512vnni"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common", "avx512_skx"],
+ },
+ "avx512_icl": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl", "-mavx512ifma", "-mavx512vbmi2", "-mavx512bitalg", "-mavx512vpopcntdq"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common", "avx512_skx"],
+ },
+ },
+ "armv7": {
+ "vfpv3": {
+ "copts": ["-mfpu=vfpv3"],
+ "implies": [],
+ },
+ "neon": {
+ "copts": ["-mfpu=neon"],
+ "implies": [],
+ },
+ "fp16": {
+ "copts": ["-mfpu=neon-fp16", "-mfp16-format=ieee"],
+ "implies": ["neon"],
+ },
+ },
+ "arm64": {
+ "neon": {
+ "copts": [],
+ "implies": [],
+ },
+ "fp16": {
+ "copts": [],
+ "implies": ["neon"],
+ },
+ "neon_dotprod": {
+ "copts": ["-march=armv8.2-a+dotprod"],
+ "implies": ["neon"],
+ },
+ "neon_fp16": {
+ "copts": ["-march=armv8.2-a+fp16"],
+ "implies": ["neon"],
+ },
+ "neon_bf16": {
+ "copts": ["-march=armv8.2-a+bf16"],
+ "implies": ["neon"],
+ },
+ "sve": {
+ "copts": ["-march=armv8.2-a+sve"],
+ "implies": [],
+ }
+ },
+ "mips64": {
+ "msa": {
+ "copts": ["-mmsa"],
+ "implies": [],
+ },
+ },
+ "ppc64le": {
+ "vsx": {
+ "copts": ["-mvsx", "-maltivec"],
+ "implies": [],
+ },
+ "vsx3": {
+ "copts": ["-mvsx", "-maltivec", "-mpower9-vector"],
+ "implies": ["vsx"],
+ },
+ },
+ "riscv64": {
+ "rvv": {
+ "copts": [],
+ "implies": [],
+ },
+ },
+ "loongarch64": {
+ "lsx": {
+ "copts": ["-mlsx"],
+ "implies": [],
+ },
+ "lasx": {
+ "copts": ["-mlasx"],
+ "implies": [],
+ },
+ },
+}
+
+def _arches_for_opt(opt):
+ arches = []
+ for arch, opts in _KNOWN_OPTS.items():
+ if opt in opts:
+ arches.append(arch)
+ if len(arches) == 0:
+ fail("Unknown optimization: {}".format(opt))
+ else:
+ return arches
+
+
+# Optimizations that will always be enabled for a given architecture
+# All other optimizations will be dispatched at runtime
+# TODO: make these configurable via build flag
+BASELINE_OPTS = {
+ "x86_64": ["sse", "sse2", "sse3"],
+ "armv7": ["neon"],
+ "arm64": ["neon", "fp16"],
+ "mips64": [],
+ "ppc64le": [],
+ "riscv64": [],
+ "loongarch64": [],
+}
+
+def _calc_enabled_opts():
+ enabled_opts = {}
+ for arch, baseline_opts in BASELINE_OPTS.items():
+ possible_opts = _KNOWN_OPTS[arch].keys()
+ dispatched_opts = [opt for opt in possible_opts if opt not in baseline_opts]
+ enabled_opts[arch] = {
+ "baseline": baseline_opts,
+ "dispatched": dispatched_opts,
+ }
+ return enabled_opts
+
+ENABLED_OPTS = _calc_enabled_opts()
+
+# OpenCV modules that will be built
+# TODO: make this configurable via build flag
+MODULES_COMMON = [
+ "calib3d",
+ "core",
+ "features2d",
+ "dnn",
+ "flann",
+ "imgcodecs",
+ "imgproc",
+ "objdetect",
+ "photo",
+ "video",
+]
+
+MODULES_DESKTOP = MODULES_COMMON + [
+ "videoio",
+ "highgui",
+]
+
+CONFIG_BASE = {
+ "stub_opencl": [
+ "core",
+ "imgproc",
+ "features2d",
+ "calib3d",
+ "objdetect",
+ "photo",
+ "video",
+ ],
+ "contains_src_headers": [
+ "imgproc",
+ "imgcodecs",
+ "features2d",
+ "calib3d",
+ "videoio",
+ "dnn",
+ ],
+ "contains_3rdparty": [
+ "features2d",
+ ],
+}
+
+def _merge_dicts(dict1, dict2):
+ merged = dict(dict1) # Create a copy of the first dictionary
+ merged.update(dict2) # Update with the second dictionary
+ return merged
+
+CONFIG_DESKTOP =_merge_dicts(CONFIG_BASE, {
+ "modules": MODULES_DESKTOP,
+})
+
+CONFIG_NON_DESKTOP = _merge_dicts(CONFIG_BASE, {
+ "modules": MODULES_COMMON,
+})
+
+def opencv_module(
+ name,
+ dispatched_files = {},
+ force_dispatch = False,
+ deps = [],
+ copts = [],
+ linkopts = [],
+ local_defines = [],
+ compatible_with = [],
+ srcs_excludes_globs = [],
+ sources = None, # reserved for modules that list sources explicitly, such as videoio or highgui
+ ):
+ """
+ Creates a Bazel rule for an OpenCV module.
+
+ Args:
+ name: The name of the module.
+ dispatched_files: A mapping of keys to a list of operators.
+ force_dispatch: If enabled, all optimizations for the files in dispatched_files will be forced to be dispatched, even if they are included in baseline.
+ deps: A list of dependencies for the module.
+ copts: Additional compiler options.
+ linkopts: Additional linker options.
+ local_defines: A list of preprocessor definitions to be added to the module.
+ compatible_with: A list of labels that specify the platforms compatible with this module.
+ srcs_excludes_globs: A list of glob patterns to exclude from the module's sources.
+ sources: A list of sources for the module. If None, sources will be determined by globbing the src directory. This is useful for modules that need to explicitly list their sources, such as videoio or highgui.
+ """
+ prefix = "modules/{}".format(name)
+ extra_headers = []
+
+ glob_hdrs = [
+ prefix + "/include/**/*.hpp",
+ prefix + "/include/**/*.h",
+ ]
+
+ # Stub out opencl as all empty since we don't need to use any opencl functionality
+ if name in CONFIG_BASE["stub_opencl"]:
+ header_file = prefix + "/src/opencl_kernels_{}.hpp".format(name)
+ write_file(
+ name = "_{}".format(header_file),
+ content = [
+ "#include \"opencv2/core/ocl.hpp\"",
+ "#include \"opencv2/core/ocl_genbase.hpp\"",
+ "#include \"opencv2/core/opencl/ocl_defs.hpp\"",
+ ],
+ out = header_file,
+ )
+ extra_headers.append(header_file)
+
+ # A Helper target to hold the headers generated in module's src dir
+ # This is to avoid hacks with `copts` to include src dir as this can lead to issues
+ # with include paths when target is used as a dependency from other modules
+ cc_library(
+ name = name + "_generated_headers",
+ hdrs = extra_headers,
+ strip_include_prefix = prefix + "/src",
+ )
+
+ simd_extra_headers = []
+
+ dispatched_targets = {
+ "@platforms//cpu:x86_64": [],
+ "@platforms//cpu:armv7": [],
+ "@platforms//cpu:arm64": [],
+ "@platforms//cpu:mips64": [],
+ "@platforms//cpu:ppc64le": [],
+ "@platforms//cpu:riscv64": [],
+ # "@platforms//cpu:loongarch64": [],
+ "//conditions:default": [],
+ }
+
+ for fname, opts in dispatched_files.items():
+ # Define file paths for SIMD declarations and SIMD header
+ simd_declarations = "{}/src/{}.simd_declarations.hpp".format(prefix, fname)
+ simd_filename = "{}/src/{}.simd.hpp".format(prefix, fname)
+
+ simd_definitions_start = [
+ "#define CV_CPU_SIMD_FILENAME \"{}\"".format(simd_filename),
+ ]
+ simd_opts = {
+ "x86_64": [],
+ "armv7": [],
+ "arm64": [],
+ "mips64": [],
+ "ppc64le": [],
+ "riscv64": [],
+ "loongarch64": [],
+ }
+ dispatch_simd = {
+ "x86_64": [],
+ "armv7": [],
+ "arm64": [],
+ "mips64": [],
+ "ppc64le": [],
+ "riscv64": [],
+ "loongarch64": [],
+ }
+ for opt in opts:
+ arches = _arches_for_opt(opt)
+ for arch in arches:
+ if force_dispatch or opt not in ENABLED_OPTS[arch]["baseline"]:
+ simd_opts[arch] += [
+ "#define CV_CPU_DISPATCH_MODE {}".format(opt.upper()),
+ "#include \"opencv2/core/private/cv_cpu_include_simd_declarations.hpp\"",
+ ]
+ dispatch_simd[arch] += [opt]
+
+ dispatch_modes_simd = {}
+ dispatch_modes_empty = [
+ "#define CV_CPU_DISPATCH_MODES_ALL BASELINE",
+ ]
+ for arch, dispatched_opts in dispatch_simd.items():
+ if len(dispatched_opts) > 0 and arch != "loongarch64": # loongarch64 currently not supported by bazel platforms
+ dispatch_modes_simd[arch] = [
+ "#define CV_CPU_DISPATCH_MODES_ALL " + ", ".join([x.upper() for x in reversed(dispatched_opts) + ["BASELINE"]]),
+ ]
+
+ # also, create a cc_library for each dispatched file and add it to list of deps
+ for opt in dispatched_opts:
+ simd_cpp_file = "{}/src/{}.{}.{}.cpp".format(prefix, fname, opt, arch)
+
+ write_file(
+ name = "_{}".format(simd_cpp_file),
+ out = simd_cpp_file,
+ content = [
+ "#include \"{}/src/precomp.hpp\"".format(prefix),
+ "#include \"{}/src/{}.simd.hpp\"".format(prefix, fname),
+ ],
+ )
+
+ simd_target_name = "_{}/src/{}_{}_{}_{}_simd".format(prefix, name, fname, arch, opt)
+
+ cc_library(
+ name = simd_target_name,
+ srcs = [
+ simd_cpp_file,
+ simd_declarations,
+ ] + native.glob([
+ prefix + "/src/**/*.hpp",
+ prefix + "/src/**/*.h"
+ ],
+ allow_empty = True
+ ),
+ hdrs = native.glob(glob_hdrs, allow_empty = True),
+ deps = deps + [":_base_headers"],
+ # note: some files don't include generated simd_declarations.hpp, so
+ # we need to define CV_CPU_DISPATCH_MODE here as well
+ # notable example: color_hsv operators in imgproc module
+ # This workaround also exist in OpenCVCompilerOptimizations.cmake
+ # in function ocv_compiler_optimization_process_sources
+ local_defines = [
+ "CV_CPU_DISPATCH_MODE={}".format(opt.upper()),
+ "CV_CPU_COMPILE_{}=1".format(opt.upper()),
+ ] + [
+ "CV_CPU_COMPILE_{}=1".format(x.upper())
+ for x in _KNOWN_OPTS[arch][opt]["implies"]
+ if x not in ENABLED_OPTS[arch]["baseline"]
+ ],
+ implementation_deps = [":" + name + "_generated_headers"],
+ copts = OPENCV_COPTS + OPENCV_OPTIMIZATION_COPTS +
+ copts +
+ _KNOWN_OPTS[arch][opt]["copts"] +
+ select({
+ ":ubsan_enabled": [
+ "-fno-sanitize=alignment", # alignment sanitizer will catch these, but they are intentional in most SIMD code
+ ],
+ "//conditions:default": [],
+ }),
+ target_compatible_with = ["@platforms//cpu:{}".format(arch)],
+ strip_include_prefix = prefix + "/include",
+ features = [
+ "exceptions", # enable exceptions for opencv modules
+ ],
+ )
+ dispatched_targets["@platforms//cpu:{}".format(arch)].append(Label(":" + simd_target_name))
+ else:
+ dispatch_modes_simd[arch] = dispatch_modes_empty
+
+ simd_definitions_end = ["#undef CV_CPU_SIMD_FILENAME"]
+ simd_extra_headers.append(simd_declarations)
+
+ select_dict = {}
+ for arch in simd_opts.keys():
+ if arch != "loongarch64": # loongarch64 currently not supported by bazel platforms
+ select_dict["@platforms//cpu:{}".format(arch)] = simd_definitions_start + simd_opts[arch] + dispatch_modes_simd[arch] + simd_definitions_end
+
+ select_dict["//conditions:default"] = simd_definitions_start + dispatch_modes_empty + simd_definitions_end
+
+ # Write the SIMD declarations to the file
+ write_file(
+ name = "_{}".format(simd_declarations),
+ # note, simd_opts declarations are mainly for x86_64
+ content = select(select_dict),
+ out = simd_declarations,
+ )
+
+ glob_srcs = [prefix + "/src/**/*.cpp", prefix + "/src/**/*.hpp"]
+ if name in CONFIG_BASE["contains_src_headers"]:
+ glob_srcs.append(prefix + "/src/**/*.h")
+ if name in CONFIG_BASE["contains_3rdparty"]:
+ glob_srcs.append(prefix + "/3rdparty/**/*.h")
+
+ baseline_copts = {
+ "//conditions:default": [],
+ }
+
+ # exclude handcrafted SIMD files from the main srcs and include them only in their respective cc_library
+ srcs_excludes = []
+ srcs_excludes += srcs_excludes_globs
+ # however, for baseline optimizations, any handcrafted SIMD files should be included back in the main srcs
+ srcs_baseline_includes = []
+
+ # A Helper target to hold the headers generated in module's src dir
+ # This is to avoid hacks with `copts` to include src dir as this can lead to issues
+ # with include paths when target is used as a dependency from other modules
+ cc_library(
+ name = name + "_generated_simd_headers",
+ hdrs = simd_extra_headers,
+ strip_include_prefix = prefix + "/src",
+ deps = [":" + name + "_generated_headers"],
+ )
+
+ for arch, opts in ENABLED_OPTS.items():
+ srcs_excludes += [
+ prefix + "/src/**/*.{}.cpp".format(x)
+ for x in opts["dispatched"]
+ ]
+ if arch != "loongarch64": # loongarch64 currently not supported by bazel platforms
+ arch_flags = []
+ for opt in opts["baseline"]:
+ arch_flags += _KNOWN_OPTS[arch][opt]["copts"]
+ srcs_baseline_includes.append(prefix + "/src/**/*.{}.cpp".format(opt))
+ baseline_copts["@platforms//cpu:{}".format(arch)] = arch_flags
+
+ # some modules have hand-optimized version for specific dispatched optimization
+ # This will not be covered by the dispatched cc_library above, so we need to add additional target for it
+
+ for opt in opts["dispatched"]:
+ simd_target_name = "_{}/src/{}_{}_{}_simd_handcrafted".format(prefix, name, arch, opt)
+
+ cc_library(
+ name = simd_target_name,
+ srcs = native.glob(
+ [
+ prefix + "/src/**/*.hpp",
+ prefix + "/src/**/*.h",
+ prefix + "/src/**/*.{}.cpp".format(opt)
+ ],
+ allow_empty = True
+ ),
+ hdrs = native.glob(glob_hdrs, allow_empty = True),
+ deps = deps + [":_base_headers"],
+ # note: some files don't include generated simd_declarations.hpp, so
+ # we need to define CV_CPU_DISPATCH_MODE here as well
+ # notable example: color_hsv operators in imgproc module
+ # This workaround also exist in OpenCVCompilerOptimizations.cmake
+ # in function ocv_compiler_optimization_process_sources
+ local_defines = [
+ "CV_CPU_DISPATCH_MODE={}".format(opt.upper()),
+ "CV_CPU_COMPILE_{}=1".format(opt.upper()),
+ ] + [
+ "CV_CPU_COMPILE_{}=1".format(x.upper())
+ for x in _KNOWN_OPTS[arch][opt]["implies"]
+ if x not in ENABLED_OPTS[arch]["baseline"]
+ ],
+ implementation_deps = [":" + name + "_generated_simd_headers"],
+ copts = OPENCV_COPTS + OPENCV_OPTIMIZATION_COPTS +
+ copts +
+ _KNOWN_OPTS[arch][opt]["copts"] +
+ select({
+ ":ubsan_enabled": [
+ "-fno-sanitize=alignment", # alignment sanitizer will catch these, but they are intentional in most SIMD code
+ ],
+ "//conditions:default": [],
+ }),
+ target_compatible_with = ["@platforms//cpu:{}".format(arch)],
+ strip_include_prefix = prefix + "/include",
+ features = [
+ "exceptions", # enable exceptions for opencv modules
+ ],
+ )
+ dispatched_targets["@platforms//cpu:{}".format(arch)].append(Label(":" + simd_target_name))
+
+ if sources != None:
+ # used by videoio and highgui modules
+ full_sources = sources
+ else:
+ full_sources = native.glob(glob_srcs, exclude = srcs_excludes) + native.glob(srcs_baseline_includes, allow_empty = True)
+
+ cc_library(
+ name = name,
+ srcs = full_sources,
+ hdrs = native.glob(glob_hdrs, allow_empty = True),
+ deps = deps + [":_base_headers"] + select(dispatched_targets),
+ copts = OPENCV_COPTS +
+ OPENCV_OPTIMIZATION_COPTS +
+ copts +
+ select(baseline_copts) +
+ select({
+ ":ubsan_enabled": [
+ "-fno-sanitize=alignment", # alignment sanitizer will catch these, but they are intentional in most SIMD code (which may be included in baseline)
+ ],
+ "//conditions:default": [],
+ }),
+ implementation_deps = [":" + name + "_generated_simd_headers"],
+ linkopts = linkopts,
+ local_defines = local_defines,
+ target_compatible_with = compatible_with,
+ strip_include_prefix = prefix + "/include",
+ features = [
+ "exceptions", # enable exceptions for opencv modules
+ ],
+ visibility = ["//visibility:public"],
+ )
diff --git a/modules/opencv/4.13.0.bcr.6/overlay/test/BUILD.bazel b/modules/opencv/4.13.0.bcr.6/overlay/test/BUILD.bazel
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/modules/opencv/4.13.0.bcr.6/overlay/test/BUILD.bazel
diff --git a/modules/opencv/4.13.0.bcr.6/overlay/test/MODULE.bazel b/modules/opencv/4.13.0.bcr.6/overlay/test/MODULE.bazel
new file mode 100644
index 0000000..66fa097
--- /dev/null
+++ b/modules/opencv/4.13.0.bcr.6/overlay/test/MODULE.bazel
@@ -0,0 +1,12 @@
+bazel_dep(name = "apple_support", version = "2.3.0")
+bazel_dep(name = "rules_cc", version = "0.2.17")
+bazel_dep(name = "platforms", version = "1.0.0")
+bazel_dep(name = "opencv")
+
+local_path_override(
+ module_name = "opencv",
+ path = "..",
+)
+
+new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
+new_local_repository(name = "ubuntu-gtk-deps", build_file = "//:ubuntu-gtk-deps.BUILD.bazel", path = "/")
diff --git a/modules/opencv/4.13.0.bcr.6/overlay/test/ubuntu-gtk-deps.BUILD.bazel b/modules/opencv/4.13.0.bcr.6/overlay/test/ubuntu-gtk-deps.BUILD.bazel
new file mode 100644
index 0000000..af46d76
--- /dev/null
+++ b/modules/opencv/4.13.0.bcr.6/overlay/test/ubuntu-gtk-deps.BUILD.bazel
@@ -0,0 +1,200 @@
+load("@rules_cc//cc:cc_import.bzl", "cc_import")
+load("@rules_cc//cc:cc_library.bzl", "cc_library")
+
+package(default_visibility = ["//visibility:public"])
+
+cc_import(
+ name = "gtk3",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgtk-3.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgtk-3.so",
+ }),
+ hdrs = glob(["usr/include/gtk-3.0/**/*.h"]),
+ strip_include_prefix = "usr/include/gtk-3.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":gdk3",
+ ":atk",
+ ],
+)
+
+cc_import(
+ name = "gdk3",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgdk-3.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgdk-3.so",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":pangocairo",
+ ":gdk_pixbuf",
+ ":gio",
+ ":glib",
+ ],
+)
+
+cc_import(
+ name = "pangocairo",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libpangocairo-1.0.so",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":pango",
+ ":cairo",
+ ],
+)
+
+cc_import(
+ name = "pango",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libpango-1.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libpango-1.0.so",
+ }),
+ hdrs = glob(["usr/include/pango-1.0/**/*.h"]),
+ strip_include_prefix = "usr/include/pango-1.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":harfbuzz",
+ ":glib",
+ ":gobject",
+ ],
+)
+
+cc_import(
+ name = "harfbuzz",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libharfbuzz.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libharfbuzz.so",
+ }),
+ hdrs = glob(["usr/include/harfbuzz/**/*.h"]),
+ strip_include_prefix = "usr/include/harfbuzz",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glib",
+ ],
+)
+
+cc_import(
+ name = "atk",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libatk-1.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libatk-1.0.so",
+ }),
+ hdrs = glob(["usr/include/atk-1.0/**/*.h"]),
+ strip_include_prefix = "usr/include/atk-1.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":cairo",
+ ],
+)
+
+cc_import(
+ name = "cairo-gobject",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libcairo-gobject.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libcairo-gobject.so",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":cairo",
+ ":gobject",
+ ],
+)
+
+cc_import(
+ name = "cairo",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libcairo.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libcairo.so",
+ }),
+ hdrs = glob(["usr/include/cairo/**/*.h"]),
+ strip_include_prefix = "usr/include/cairo",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":gdk_pixbuf",
+ ":gio",
+ ],
+)
+
+cc_import(
+ name = "gdk_pixbuf",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgdk_pixbuf-2.0.so",
+ }),
+ hdrs = glob(["usr/include/gdk-pixbuf-2.0/**/*.h"]),
+ strip_include_prefix = "usr/include/gdk-pixbuf-2.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glib",
+ ":gobject",
+ ],
+)
+
+cc_import(
+ name = "gio",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgio-2.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgio-2.0.so",
+ }),
+ hdrs = glob(["usr/include/gio-unix-2.0/**/*.h"]),
+ strip_include_prefix = "usr/include/gio-unix-2.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glib",
+ ":gobject",
+ ],
+)
+
+cc_import(
+ name = "gobject",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgobject-2.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgobject-2.0.so",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glib",
+ ],
+)
+
+cc_library(
+ name = "glibconfig-headers",
+ hdrs = select({
+ "@platforms//cpu:x86_64": glob(["usr/lib/x86_64-linux-gnu/glib-2.0/include/**/*.h"], allow_empty = True),
+ "@platforms//cpu:aarch64": glob(["usr/lib/aarch64-linux-gnu/glib-2.0/include/**/*.h"], allow_empty = True),
+ }),
+ strip_include_prefix = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/glib-2.0/include",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/glib-2.0/include",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+)
+
+cc_import(
+ name = "glib",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libglib-2.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libglib-2.0.so",
+ }),
+ hdrs = glob(["usr/include/glib-2.0/**/*.h"]),
+ strip_include_prefix = "usr/include/glib-2.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glibconfig-headers",
+ ],
+)
diff --git a/modules/opencv/4.13.0.bcr.6/presubmit.yml b/modules/opencv/4.13.0.bcr.6/presubmit.yml
new file mode 100644
index 0000000..3963a63
--- /dev/null
+++ b/modules/opencv/4.13.0.bcr.6/presubmit.yml
@@ -0,0 +1,40 @@
+bcr_test_module:
+ module_path: test
+ matrix:
+ # Currently does not build in Windows due to SIMD dispatch flags not taking into account cl.exe
+ # Also, for HighGUI on Linux, a GTK3 is needed, which should be provided via @opencv//:gtk3 label flag.
+ # This is tested only on Ubuntu, where test module installs the GTK3 with system's package manager and
+ # then imports it to the workspace.
+ ubuntu_with_gtk3:
+ - ubuntu2404
+ - ubuntu2404_arm64
+ platform:
+ - rockylinux8
+ - debian11
+ - debian12
+ - ubuntu2404
+ - ubuntu2404_arm64
+ - macos
+ - macos_arm64
+ bazel:
+ - 7.x
+ - 8.x
+ - 9.x
+ tasks:
+ verify_targets:
+ name: Verify build targets
+ platform: ${{ platform }}
+ bazel: ${{ bazel }}
+ build_targets:
+ - '@opencv//:opencv'
+ verify_targets_gtk3:
+ name: Verify build targets on Ubuntu with system GTK3
+ platform: ${{ ubuntu_with_gtk3 }}
+ bazel: 9.x
+ shell_commands:
+ - sudo apt update && sudo apt install -y libgtk-3-dev
+ build_flags:
+ - "--@opencv//:gtk3=@ubuntu-gtk-deps//:gtk3"
+ - "--@opencv//:with_gtk3=True"
+ build_targets:
+ - '@opencv//:opencv'
diff --git a/modules/opencv/4.13.0.bcr.6/source.json b/modules/opencv/4.13.0.bcr.6/source.json
new file mode 100644
index 0000000..65f81b0
--- /dev/null
+++ b/modules/opencv/4.13.0.bcr.6/source.json
@@ -0,0 +1,13 @@
+{
+ "integrity": "sha256-Qxy0idJ12iZSZYHGc119fAsA8ZD+lAsyF9OGt3rvUsc=",
+ "strip_prefix": "opencv-4.13.0",
+ "url": "https://github.com/opencv/opencv/archive/refs/tags/4.13.0.zip",
+ "overlay": {
+ "BUILD.bazel": "sha256-HAyFnRSEsRTKg41O0QQF75zCT7a2wl+sFHNpVndw4E4=",
+ "MODULE.bazel": "sha256-zfUTKc5N+bzOHVjchZl71+lLS214Of4pcJ/na+dNdfI=",
+ "opencv.bzl": "sha256-cWL5kJqeI6rRpxeEz47KH66j9ZUCbnzjIvuZDl+Opqc=",
+ "test/BUILD.bazel": "sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
+ "test/MODULE.bazel": "sha256-Xsrl3piNdEbtwKa1DM1QWsE6pL7M0K/WCLdoPdnC9Q8=",
+ "test/ubuntu-gtk-deps.BUILD.bazel": "sha256-coCXi1DH9iVC6q8qwiI3qndFVmUkNjtRhpIsSIXC9P0="
+ }
+}
diff --git a/modules/opencv/metadata.json b/modules/opencv/metadata.json
index 893bd4d..f020b26 100644
--- a/modules/opencv/metadata.json
+++ b/modules/opencv/metadata.json
@@ -28,12 +28,14 @@
"4.12.0.bcr.3",
"4.12.0.bcr.4",
"4.12.0.bcr.5",
+ "4.12.0.bcr.6",
"4.13.0",
"4.13.0.bcr.1",
"4.13.0.bcr.2",
"4.13.0.bcr.3",
"4.13.0.bcr.4",
"4.13.0.bcr.5",
+ "4.13.0.bcr.6",
"5.0.0",
"5.0.0.bcr.1",
"5.0.0.bcr.2",