From 3d5ce7cb4c815de891bed1a4cf8b407528f62b47 Mon Sep 17 00:00:00 2001 From: Erick Fuentes Date: Fri, 15 Nov 2024 05:53:06 -0500 Subject: [PATCH 1/6] wip --- WORKSPACE | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WORKSPACE b/WORKSPACE index 35d9cb27..aeef8e9d 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -458,3 +458,9 @@ http_archive( patches = ["//third_party:opengv_0001-prefix-unsupported-eigen-include-paths.patch"], integrity = "sha256-gIK3IvE6rGDpxvN3BA+EPFKPvZ7Zi7Ix33IIcm2RULA=" ) + +http_archive( + name = "kimera_vio", + urls = ["https://github.com/MIT-SPARK/Kimera-VIO/archive/2c7dff1941088e9fe9028f623afb2897451ff2ef.zip"], + strip_prefix="Kimera-VIO-2c7dff1941088e9fe9028f623afb2897451ff2ef", +) From 452419b86d90e460dd40d6bdd4a96c7ff583a5a5 Mon Sep 17 00:00:00 2001 From: Erick Fuentes Date: Fri, 15 Nov 2024 15:21:43 -0500 Subject: [PATCH 2/6] add_opencv_contrib and build libraries required for kimera --- WORKSPACE | 9 +++++++++ third_party/BUILD.eigen | 25 +++++-------------------- third_party/BUILD.opencv | 12 ++++++++---- third_party/BUILD.opencv_contrib | 6 ++++++ 4 files changed, 28 insertions(+), 24 deletions(-) create mode 100644 third_party/BUILD.opencv_contrib diff --git a/WORKSPACE b/WORKSPACE index aeef8e9d..1458ca58 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -358,6 +358,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( diff --git a/third_party/BUILD.eigen b/third_party/BUILD.eigen index 10232d4a..4a0ac0c5 100644 --- a/third_party/BUILD.eigen +++ b/third_party/BUILD.eigen @@ -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 includes=[""], diff --git a/third_party/BUILD.opencv b/third_party/BUILD.opencv index d282a7b0..e5b2fb09 100644 --- a/third_party/BUILD.opencv +++ b/third_party/BUILD.opencv @@ -13,6 +13,10 @@ 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( @@ -26,13 +30,13 @@ 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"], diff --git a/third_party/BUILD.opencv_contrib b/third_party/BUILD.opencv_contrib new file mode 100644 index 00000000..cd9b37df --- /dev/null +++ b/third_party/BUILD.opencv_contrib @@ -0,0 +1,6 @@ + +filegroup( + name = "modules", + srcs = glob(["modules/**"]), + visibility = ["//visibility:public"], +) From 8a4bfc8aa9680c3927091de8aff3f8c8f2532db1 Mon Sep 17 00:00:00 2001 From: Erick Fuentes Date: Fri, 15 Nov 2024 15:31:10 -0500 Subject: [PATCH 3/6] back out addition of Kimera_VIO --- WORKSPACE | 5 ----- 1 file changed, 5 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 1458ca58..b8546ea2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -468,8 +468,3 @@ http_archive( integrity = "sha256-gIK3IvE6rGDpxvN3BA+EPFKPvZ7Zi7Ix33IIcm2RULA=" ) -http_archive( - name = "kimera_vio", - urls = ["https://github.com/MIT-SPARK/Kimera-VIO/archive/2c7dff1941088e9fe9028f623afb2897451ff2ef.zip"], - strip_prefix="Kimera-VIO-2c7dff1941088e9fe9028f623afb2897451ff2ef", -) From 25c0e96f9d9288c8826ff735d3cd85f29828259c Mon Sep 17 00:00:00 2001 From: Erick Fuentes Date: Sun, 17 Nov 2024 10:42:07 -0500 Subject: [PATCH 4/6] update protobuf --- WORKSPACE | 8 ++++---- ...protobuf_0001-use-rules-python-headers.patch} | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) rename third_party/{protobuf-0002-use-rules-python-headers.patch => protobuf_0001-use-rules-python-headers.patch} (62%) diff --git a/WORKSPACE b/WORKSPACE index b8546ea2..940dce42 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -201,11 +201,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"], ) diff --git a/third_party/protobuf-0002-use-rules-python-headers.patch b/third_party/protobuf_0001-use-rules-python-headers.patch similarity index 62% rename from third_party/protobuf-0002-use-rules-python-headers.patch rename to third_party/protobuf_0001-use-rules-python-headers.patch index 5ed19388..df2d080f 100644 --- a/third_party/protobuf-0002-use-rules-python-headers.patch +++ b/third_party/protobuf_0001-use-rules-python-headers.patch @@ -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", ], ) From 6ba9fc8a9eb5ec0e59c1bb63155ab43d549d6810 Mon Sep 17 00:00:00 2001 From: Erick Fuentes Date: Sun, 17 Nov 2024 10:42:31 -0500 Subject: [PATCH 5/6] add rules_cc --- WORKSPACE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/WORKSPACE b/WORKSPACE index 940dce42..550afb4c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -18,6 +18,27 @@ 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 = "rules_cc", + urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.16/rules_cc-0.0.16.tar.gz"], + sha256 = "bbf1ae2f83305b7053b11e4467d317a7ba3517a12cef608543c1b1c5bf48a4df", + strip_prefix = "rules_cc-0.0.16", +) + + http_archive( name = "platforms", urls = [ From 47522c7ce77d0d5cd57c1759aa5b2584b88acc69 Mon Sep 17 00:00:00 2001 From: Erick Fuentes Date: Sun, 17 Nov 2024 18:12:13 -0500 Subject: [PATCH 6/6] switch to action configs --- WORKSPACE | 8 -- third_party/BUILD.opencv | 8 -- toolchain/gcc_toolchain_config.bzl | 138 +++++++++++++++++++++-------- 3 files changed, 102 insertions(+), 52 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 550afb4c..9c84c69b 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -31,14 +31,6 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") bazel_skylib_workspace() -http_archive( - name = "rules_cc", - urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.16/rules_cc-0.0.16.tar.gz"], - sha256 = "bbf1ae2f83305b7053b11e4467d317a7ba3517a12cef608543c1b1c5bf48a4df", - strip_prefix = "rules_cc-0.0.16", -) - - http_archive( name = "platforms", urls = [ diff --git a/third_party/BUILD.opencv b/third_party/BUILD.opencv index e5b2fb09..59613539 100644 --- a/third_party/BUILD.opencv +++ b/third_party/BUILD.opencv @@ -19,13 +19,6 @@ SHARED_LIBS = [ "libopencv_rgbd.so", ] -cc_library( - name = "opencv_deps", - linkopts = [ - "-lstdc++", - ] -) - cmake( name = "opencv", generate_args = [ @@ -40,7 +33,6 @@ cmake( 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"], diff --git a/toolchain/gcc_toolchain_config.bzl b/toolchain/gcc_toolchain_config.bzl index 453d4b37..f6a49b46 100644 --- a/toolchain/gcc_toolchain_config.bzl +++ b/toolchain/gcc_toolchain_config.bzl @@ -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, @@ -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", @@ -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), @@ -172,7 +239,6 @@ def _impl(ctx): compiler="gcc", abi_version="unknown", abi_libc_version="unknown", - tool_paths = tool_paths ) gcc_toolchain_config = rule(