Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add opencv contrib #337

Merged
merged 6 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ http_archive(
integrity = "sha256-CVtgQSRXe8o2wMjNcJrxtlUxiHZY9ZQJ0kde8BkrTPw="
)

http_archive(
name = "bazel_skylib",
sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

http_archive(
name = "platforms",
urls = [
Expand Down Expand Up @@ -201,11 +214,11 @@ rules_proto_toolchains()

http_archive(
name = "com_google_protobuf",
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v25.3/protobuf-25.3.zip"],
strip_prefix="protobuf-25.3",
sha256 = "3ae7a8f2181be28e5d694617c2b85c6561ba6a16bfcdc9db8e3a95077cab8815",
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v28.3/protobuf-28.3.zip"],
strip_prefix="protobuf-28.3",
integrity = "sha256-s7TDts/nS3eurpkJ/DwTAwknF/cbwhVNfBlhrNr1/kw=",
patches = [
"@//third_party:protobuf-0002-use-rules-python-headers.patch",
"@//third_party:protobuf_0001-use-rules-python-headers.patch",
],
patch_args=["-p1"],
)
Expand Down Expand Up @@ -358,6 +371,15 @@ http_archive(
sha256 = "db6fb5e7dc76829d738fdbcdba11a810c66ca0a4752e531eaf3d793361e96de8",
)

http_archive(
name = "opencv_contrib",
url = "https://github.com/opencv/opencv_contrib/archive/refs/tags/4.7.0.zip",
strip_prefix="opencv_contrib-4.7.0",
build_file="//third_party:BUILD.opencv_contrib",
integrity = "sha256-7wAYE+w5IVWTzp3rOuxwqFJ49XoO2IsY9vYVJlhVQ2w="
)


load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
Expand Down Expand Up @@ -458,3 +480,4 @@ http_archive(
patches = ["//third_party:opengv_0001-prefix-unsupported-eigen-include-paths.patch"],
integrity = "sha256-gIK3IvE6rGDpxvN3BA+EPFKPvZ7Zi7Ix33IIcm2RULA="
)

25 changes: 5 additions & 20 deletions third_party/BUILD.eigen
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,12 @@ cc_library(
"unsupported/Eigen/Polynomials",
"unsupported/Eigen/NonLinearOptimization",
"unsupported/Eigen/NumericalDiff",
"unsupported/Eigen/SpecialFunctions",
"unsupported/Eigen/CXX11/Tensor",
],
srcs = glob(["Eigen/src/**/*"]) +
[
"unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h",
"unsupported/Eigen/src/AutoDiff/AutoDiffJacobian.h",
"unsupported/Eigen/src/Polynomials/Companion.h",
"unsupported/Eigen/src/Polynomials/PolynomialUtils.h",
"unsupported/Eigen/src/Polynomials/PolynomialSolver.h",
"unsupported/Eigen/src/NonLinearOptimization/chkder.h",
"unsupported/Eigen/src/NonLinearOptimization/covar.h",
"unsupported/Eigen/src/NonLinearOptimization/dogleg.h",
"unsupported/Eigen/src/NonLinearOptimization/fdjac1.h",
"unsupported/Eigen/src/NonLinearOptimization/lmpar.h",
"unsupported/Eigen/src/NonLinearOptimization/qrsolv.h",
"unsupported/Eigen/src/NonLinearOptimization/rwupdt.h",
"unsupported/Eigen/src/NonLinearOptimization/r1mpyq.h",
"unsupported/Eigen/src/NonLinearOptimization/r1updt.h",
"unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h",
"unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h",
"unsupported/Eigen/src/NumericalDiff/NumericalDiff.h",
],
srcs = glob([
"Eigen/src/**/*",
"unsupported/Eigen/**/src/**/*.h"]),
# Other third party dependencies often pull in Eigen using angle brackets
# This makes it so that Eigen is available at both "Eigen/Core" and <Eigen/Core>
includes=[""],
Expand Down
20 changes: 8 additions & 12 deletions third_party/BUILD.opencv
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,26 @@ SHARED_LIBS = [
"libopencv_imgproc.so",
"libopencv_features2d.so",
"libopencv_flann.so",
"libopencv_calib3d.so",
"libopencv_video.so",
"libopencv_viz.so",
"libopencv_rgbd.so",
]

cc_library(
name = "opencv_deps",
linkopts = [
"-lstdc++",
]
)

cmake(
name = "opencv",
generate_args = [
"-GNinja",
"-DBUILD_LIST=core,highgui,imgcodecs,imgproc,python3,features2d,flann",
"-DBUILD_LIST=core,highgui,imgcodecs,imgproc,python3,features2d,flann,calib3d,video,viz,rgbd",
"-DCMAKE_CXX_STANDARD=20",
"-DCMAKE_CXX_FLAGS=-Wno-deprecated-enum-enum-conversion",
"-DCMAKE_CXX_STANDARD_LIBRARIES=-lstdc++"
],
build_args = [
"-DCMAKE_CXX_STANDARD_LIBRARIES=-lstdc++",
"-DOPENCV_EXTRA_MODULES_PATH=$$EXT_BUILD_ROOT$$/external/opencv_contrib/modules"
],
build_data=["@opencv_contrib//:modules"],
generate_crosstool_file = False,
lib_source = "@opencv//:all",
includes = ["opencv4"],
deps = [":opencv_deps"],
out_shared_libs = SHARED_LIBS +
[lib + ".407" for lib in SHARED_LIBS],
visibility = ["//visibility:public"],
Expand Down
6 changes: 6 additions & 0 deletions third_party/BUILD.opencv_contrib
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

filegroup(
name = "modules",
srcs = glob(["modules/**"]),
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
diff --git a/python/build_targets.bzl b/python/build_targets.bzl
index fff32b4a5..08e0212cf 100644
index ee765ab4c..28e43c8b5 100644
--- a/python/build_targets.bzl
+++ b/python/build_targets.bzl
@@ -84,7 +84,7 @@ def build_targets(name):
@@ -87,7 +87,7 @@ def build_targets(name):
],
deps = select({
"//conditions:default": [],
- ":use_fast_cpp_protos": ["//external:python_headers"],
- ":use_fast_cpp_protos": ["@system_python//:python_headers"],
+ ":use_fast_cpp_protos": ["@rules_python//python/cc:current_py_cc_headers"],
}),
)

@@ -123,7 +123,7 @@ def build_targets(name):
"//src/google/protobuf:descriptor_legacy",
@@ -136,7 +136,7 @@ def build_targets(name):
"@com_google_absl//absl/strings",
] + select({
"//conditions:default": [],
- ":use_fast_cpp_protos": ["//external:python_headers"],
- ":use_fast_cpp_protos": ["@system_python//:python_headers"],
+ ":use_fast_cpp_protos": ["@rules_python//python/cc:current_py_cc_headers"],
}),
)

@@ -386,7 +386,7 @@ def build_targets(name):
@@ -436,7 +436,7 @@ def build_targets(name):
hdrs = ["google/protobuf/proto_api.h"],
visibility = ["//visibility:public"],
deps = [
- "//external:python_headers",
- "@system_python//:python_headers",
+ "@rules_python//python/cc:current_py_cc_headers",
],
)
Expand Down
138 changes: 102 additions & 36 deletions toolchain/gcc_toolchain_config.bzl
Original file line number Diff line number Diff line change
@@ -1,43 +1,10 @@

load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "feature", "flag_group", "flag_set", "tool_path")
load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
"action_config", "feature", "flag_group", "flag_set", "tool_path", "tool", "variable_with_value")

def _impl(ctx):
gcc_version = ctx.attr.gcc_version
tool_paths = [
tool_path(
name = "gcc",
path = "/usr/bin/gcc-{}".format(gcc_version),
),
tool_path(
name = "ar",
path = "/usr/bin/ar",
),
tool_path(
name = "ld",
path = "/usr/bin/ld.gold",
),
tool_path(
name = "cpp",
path = "/usr/bin/g++-{}".format(gcc_version),
),
tool_path(
name = "gcov",
path = "/bin/false",
),
tool_path(
name = "nm",
path = "/bin/false",
),
tool_path(
name = "objdump",
path = "/bin/false",
),
tool_path(
name = "strip",
path = "/bin/false",
),
]
all_link_actions = [
ACTION_NAMES.cpp_link_executable,
ACTION_NAMES.cpp_link_dynamic_library,
Expand All @@ -47,6 +14,52 @@ def _impl(ctx):
ACTION_NAMES.c_compile,
ACTION_NAMES.cpp_compile,
]
action_configs = [
action_config(
action_name = ACTION_NAMES.preprocess_assemble,
tools = [tool(path="/usr/bin/gcc-{}".format(gcc_version))],
),
action_config(
action_name = ACTION_NAMES.assemble,
tools = [tool(path="/usr/bin/gcc-{}".format(gcc_version))],
),
action_config(
action_name = ACTION_NAMES.c_compile,
tools = [tool(path="/usr/bin/gcc-{}".format(gcc_version))],
implies = [
"c_compile_flags"
],
),
action_config(
action_name = ACTION_NAMES.cpp_compile,
tools = [tool(path="/usr/bin/g++-{}".format(gcc_version))],
# implies = [
# "cpp_compile_flags"
# ],
),
action_config(
action_name = ACTION_NAMES.cpp_link_executable,
tools = [tool(path="/usr/bin/g++-{}".format(gcc_version))],
# implies = [
# "default_linker_flags"
# ],
),
action_config(
action_name = ACTION_NAMES.cpp_link_dynamic_library,
tools = [tool(path="/usr/bin/g++-{}".format(gcc_version))],
# implies = [
# "default_linker_flags"
# ],
),
action_config(
action_name = ACTION_NAMES.cpp_link_static_library,
tools = [tool(path="/usr/bin/ar")],
implies = [
"archiver_flags"
],
),
]

features = [
feature(
name = "default_linker_flags",
Expand Down Expand Up @@ -154,11 +167,65 @@ def _impl(ctx):
)
]
),
feature(
name = "archiver_flags",
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_link_static_library],
flag_groups = [
flag_group(
flags = [
"rcsD",
"%{output_execpath}",
],
expand_if_available = "output_execpath",
),
],
),
flag_set(
actions = [ACTION_NAMES.cpp_link_static_library],
flag_groups = [
flag_group(
iterate_over = "libraries_to_link",
flag_groups = [
flag_group(
flags = ["%{libraries_to_link.name}"],
expand_if_equal = variable_with_value(
name = "libraries_to_link.type",
value = "object_file",
),
),
flag_group(
flags = ["%{libraries_to_link.object_files}"],
iterate_over = "libraries_to_link.object_files",
expand_if_equal = variable_with_value(
name = "libraries_to_link.type",
value = "object_file_group",
),
),
],
expand_if_available = "libraries_to_link",
),
],
),
flag_set(
actions = [ACTION_NAMES.cpp_link_static_library],
flag_groups = [
flag_group(
flags = ["%{user_archiver_flags}"],
iterate_over = "user_archiver_flags",
expand_if_available = "user_archiver_flags",
),
],
),
],
)
]

return cc_common.create_cc_toolchain_config_info(
ctx=ctx,
features = features,
action_configs = action_configs,
cxx_builtin_include_directories = [
"/usr/include",
"/usr/include/c++/{}".format(gcc_version),
Expand All @@ -172,7 +239,6 @@ def _impl(ctx):
compiler="gcc",
abi_version="unknown",
abi_libc_version="unknown",
tool_paths = tool_paths
)

gcc_toolchain_config = rule(
Expand Down