Skip to content

Commit c874cb2

Browse files
laltenkotlaja
authored andcommitted
Fix some behaviortree_cpp issues (bazelbuild#6151)
To be able to compile behaviortree_cpp we need to * Update ncurses to bazelbuild#6149 * Update zmq to bazelbuild#6150 * Patch BehaviorTree/BehaviorTree.CPP#1020
1 parent b750bc1 commit c874cb2

13 files changed

+295
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module(
2+
name = "behaviortree_cpp",
3+
version = "4.7.0.bcr.1",
4+
bazel_compatibility = [">=7.2.1"],
5+
)
6+
7+
# NOTE: This is the newest version of cpp-sqlite that we are compatible with.
8+
bazel_dep(name = "cpp-sqlite", version = "0.0.0-20230222-7f931c4")
9+
bazel_dep(name = "cppzmq", version = "4.10.0.bcr.1")
10+
bazel_dep(name = "flatbuffers", version = "25.2.10")
11+
bazel_dep(name = "googletest", version = "1.17.0")
12+
bazel_dep(name = "lexy", version = "2025.05.0")
13+
bazel_dep(name = "libzmq", version = "4.3.5.bcr.4")
14+
bazel_dep(name = "minicoro", version = "0.1.2")
15+
bazel_dep(name = "minitrace", version = "0.0.0-20241021-242da50")
16+
bazel_dep(name = "ncurses", version = "6.4.20221231.bcr.10")
17+
bazel_dep(name = "platforms", version = "1.0.0")
18+
bazel_dep(name = "rules_cc", version = "0.2.4")
19+
bazel_dep(name = "rules_license", version = "1.0.0")
20+
bazel_dep(name = "tinyxml2", version = "10.0.0")
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
2+
load("@rules_license//rules:license.bzl", "license")
3+
4+
license(
5+
name = "license",
6+
license_kinds = ["@rules_license//licenses/spdx:MIT"],
7+
license_text = "LICENSE",
8+
)
9+
10+
UNIX_SRCS = [
11+
"src/shared_library_UNIX.cpp",
12+
]
13+
14+
WINDOWS_SRCS = [
15+
"src/shared_library_WIN.cpp",
16+
]
17+
18+
cc_library(
19+
name = "behaviortree_cpp",
20+
srcs = glob(
21+
[
22+
"src/**/*.cpp",
23+
"src/**/*.hpp",
24+
],
25+
exclude = ["src/example.cpp"] + WINDOWS_SRCS + UNIX_SRCS,
26+
) +
27+
select({
28+
"@platforms//os:windows": WINDOWS_SRCS,
29+
"//conditions:default": UNIX_SRCS,
30+
}),
31+
hdrs = glob([
32+
"include/**/*.h",
33+
"include/**/*.hpp",
34+
]),
35+
# IMPORTANT: module_version() MUST be in the form of X.Y.Z
36+
defines = ['BTCPP_LIBRARY_VERSION=\\"' + module_version() + '\\"'],
37+
includes = ["include"],
38+
visibility = ["//visibility:public"],
39+
deps = [
40+
":wildcards",
41+
"@cpp-sqlite",
42+
"@cppzmq",
43+
"@flatbuffers",
44+
"@lexy",
45+
"@libzmq",
46+
"@minicoro",
47+
"@minitrace",
48+
"@ncurses",
49+
"@tinyxml2",
50+
],
51+
)
52+
53+
TESTS_THAT_FAIL_ON_MACOS = [
54+
# These tests are broken on x86 macOS Bazel 8
55+
"tests/gtest_postconditions.cpp",
56+
"tests/gtest_parallel.cpp",
57+
]
58+
59+
cc_test(
60+
name = "behaviortree_cpp_test",
61+
size = "small",
62+
srcs = glob(
63+
[
64+
"tests/**/*.cpp",
65+
"tests/**/*.h",
66+
"tests/**/*.hpp",
67+
"sample_nodes/*.cpp",
68+
"sample_nodes/*.h",
69+
],
70+
exclude = [
71+
# These tests are broken and are not included in the cmake build.
72+
"tests/gtest_async_action_node.cpp",
73+
"tests/gtest_logger_zmq.cpp",
74+
"tests/navigation_test.cpp",
75+
] + TESTS_THAT_FAIL_ON_MACOS,
76+
) + select({
77+
"@platforms//os:macos": [],
78+
"//conditions:default": TESTS_THAT_FAIL_ON_MACOS,
79+
}),
80+
data = glob(["tests/trees/**/*.xml"]),
81+
includes = [
82+
"tests",
83+
"tests/include",
84+
],
85+
# NOTE: It's not currently possible to get the path to a directory here. If bazel supported
86+
# getting the path to a directory, then we could get the path to the tests directory and pass it
87+
# directly as BT_TEST_FOLDER. Instead we get the path to one of the xml files, and then patch
88+
# the logic in tests/gtest_factory.cpp as a work-around.
89+
# See: https://github.com/bazelbuild/bazel/issues/23139
90+
local_defines = [
91+
"BT_TEST_PARENT_INCLUDE_CHILD_XML_FILE=" +
92+
"\\\"../$(rlocationpath tests/trees/parent_include_child.xml)\\\"",
93+
],
94+
deps = [
95+
":behaviortree_cpp",
96+
"@googletest//:gtest",
97+
],
98+
)
99+
100+
# Use the vendored version of wildcards because it has an important bug fix.
101+
# See: https://github.com/zemasoft/wildcards/issues/28
102+
# Be aware that this might cause issues if you depend on both behaviortree_cpp and a different
103+
# version of wildcards.
104+
cc_library(
105+
name = "wildcards",
106+
hdrs = ["3rdparty/wildcards/wildcards.hpp"],
107+
includes = ["3rdparty"],
108+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../MODULE.bazel
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
diff --git a/tests/gtest_factory.cpp b/tests/gtest_factory.cpp
2+
index 321d24e..af97613 100644
3+
--- a/tests/gtest_factory.cpp
4+
+++ b/tests/gtest_factory.cpp
5+
@@ -268,6 +268,14 @@ TEST(BehaviorTreeFactory, SubTreeWithRemapping)
6+
7+
std::string FilePath(const std::filesystem::path& relative_path)
8+
{
9+
+ // NOTE: Bazel doesn't support getting the execpath of a directory, so use a file instead.
10+
+ // BT_TEST_PARENT_INCLUDE_CHILD_XML_FILE is expected to be the bazel runtime path to:
11+
+ // tests/trees/parent_include_child.xml
12+
+ const std::filesystem::path BT_TEST_FOLDER =
13+
+ std::filesystem::path{ BT_TEST_PARENT_INCLUDE_CHILD_XML_FILE }
14+
+ .parent_path()
15+
+ .parent_path();
16+
+
17+
// clang-format off
18+
static const std::filesystem::path search_paths[] = {
19+
BT_TEST_FOLDER,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/src/loggers/bt_sqlite_logger.cpp b/src/loggers/bt_sqlite_logger.cpp
2+
index 7dd736b..59a960d 100644
3+
--- a/src/loggers/bt_sqlite_logger.cpp
4+
+++ b/src/loggers/bt_sqlite_logger.cpp
5+
@@ -1,6 +1,6 @@
6+
#include "behaviortree_cpp/loggers/bt_sqlite_logger.h"
7+
#include "behaviortree_cpp/xml_parsing.h"
8+
-#include "cpp-sqlite/sqlite.hpp"
9+
+#include "sqlite.hpp"
10+
11+
namespace BT
12+
{
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
diff --git a/src/loggers/groot2_publisher.cpp b/src/loggers/groot2_publisher.cpp
2+
index 6146507..83bbe74 100644
3+
--- a/src/loggers/groot2_publisher.cpp
4+
+++ b/src/loggers/groot2_publisher.cpp
5+
@@ -1,8 +1,8 @@
6+
#include "behaviortree_cpp/loggers/groot2_publisher.h"
7+
#include "behaviortree_cpp/loggers/groot2_protocol.h"
8+
#include "behaviortree_cpp/xml_parsing.h"
9+
-#include "cppzmq/zmq.hpp"
10+
-#include "cppzmq/zmq_addon.hpp"
11+
+#include <zmq.hpp>
12+
+#include <zmq_addon.hpp>
13+
14+
namespace BT
15+
{
16+
diff --git a/tools/bt_recorder.cpp b/tools/bt_recorder.cpp
17+
index c652f9a..a1266de 100644
18+
--- a/tools/bt_recorder.cpp
19+
+++ b/tools/bt_recorder.cpp
20+
@@ -3,7 +3,7 @@
21+
#include <fstream>
22+
#include <signal.h>
23+
#include <fstream>
24+
-#include "cppzmq/zmq.hpp"
25+
+#include <zmq.hpp>
26+
#include "behaviortree_cpp/flatbuffers/BT_logger_generated.h"
27+
28+
// http://zguide.zeromq.org/cpp:interrupt
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/src/controls/manual_node.cpp b/src/controls/manual_node.cpp
2+
index 18af989..82e7e44 100644
3+
--- a/src/controls/manual_node.cpp
4+
+++ b/src/controls/manual_node.cpp
5+
@@ -13,7 +13,7 @@
6+
7+
#include "behaviortree_cpp/controls/manual_node.h"
8+
#include "behaviortree_cpp/action_node.h"
9+
-#include <ncurses.h>
10+
+#include <curses.h>
11+
12+
namespace BT
13+
{
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/src/action_node.cpp b/src/action_node.cpp
2+
index 61dff35..2bf78f9 100644
3+
--- a/src/action_node.cpp
4+
+++ b/src/action_node.cpp
5+
@@ -12,7 +12,7 @@
6+
*/
7+
8+
#define MINICORO_IMPL
9+
-#include "minicoro/minicoro.h"
10+
+#include "minicoro.h"
11+
#include "behaviortree_cpp/action_node.h"
12+
13+
using namespace BT;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/src/loggers/bt_minitrace_logger.cpp b/src/loggers/bt_minitrace_logger.cpp
2+
index 69d6d0b..478e227 100644
3+
--- a/src/loggers/bt_minitrace_logger.cpp
4+
+++ b/src/loggers/bt_minitrace_logger.cpp
5+
@@ -1,8 +1,7 @@
6+
7+
#include "behaviortree_cpp/loggers/bt_minitrace_logger.h"
8+
9+
-#define MTR_ENABLED true
10+
-#include "minitrace/minitrace.h"
11+
+#include "minitrace.h"
12+
13+
namespace BT
14+
{
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/src/xml_parsing.cpp b/src/xml_parsing.cpp
2+
index 8b9ce95..2542260 100644
3+
--- a/src/xml_parsing.cpp
4+
+++ b/src/xml_parsing.cpp
5+
@@ -33,7 +33,7 @@
6+
7+
#include <map>
8+
#include "behaviortree_cpp/xml_parsing.h"
9+
-#include "tinyxml2/tinyxml2.h"
10+
+#include "tinyxml2.h"
11+
#include <filesystem>
12+
13+
#ifdef USING_ROS2

0 commit comments

Comments
 (0)