Repository navigation
Add USE_VENDORED_JSON option to use the system nlohmann_json (fixes #959) - #1235
Merged
Merged
Conversation
) BT.CPP bundles nlohmann/json 3.11.3 and its public headers include it unconditionally. A user that also includes a system nlohmann/json gets two versions behind the same include guard: whichever comes first wins, and the result is mismatched types or link errors (#959). With -DUSE_VENDORED_JSON=OFF the library uses find_package(nlohmann_json 3.10): - the public headers include <nlohmann/json.hpp> when BTCPP_SYSTEM_JSON is defined. The library exports that definition together with the nlohmann_json target (CMake config and ament), so its users see the same version it was built with; - the bundled header is not installed: a user that bypasses the CMake target (plain include dirs, Makefiles, Bazel) fails to compile, instead of silently mixing two versions; - the tests get nlohmann::json from the BT.CPP headers, like any user, instead of including the bundled copy directly. The default (ON) is unchanged: it needs no new definition and the headers preprocess to the same code, so the API and ABI are the same. nlohmann::json is part of the public API, so an OFF build has a different ABI than the default one: everything linking it must use the same nlohmann_json. A new CI job builds and tests OFF on Ubuntu 22.04 with apt's nlohmann_json 3.10.5, the oldest supported version. Supersedes #1080. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
'cmake --build --parallel' without a number runs an unbounded 'make -j' with the default generator: the runner ran out of memory and was shut down. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #959. Supersedes the draft #1080, reworked so that the default build doesn't change at all.
Problem
BT.CPP bundles nlohmann/json 3.11.3, and its public headers include it unconditionally. A user that also includes a system nlohmann/json ends up with two versions behind the same include guard. Whichever comes first wins, and the result is mismatched types or link errors (#959).
Change
The new option
-DUSE_VENDORED_JSON=OFF(defaultON) builds againstfind_package(nlohmann_json 3.10):blackboard.h,bt_factory.h,json_export.h,loggers/groot2_protocol.h) include<nlohmann/json.hpp>whenBTCPP_SYSTEM_JSONis defined.BTCPP_SYSTEM_JSONandnlohmann_json::nlohmann_jsonas PUBLIC, through both the CMake config (find_dependency) and ament (ament_export_dependencies). Users of the target therefore see the same version the library was built with.contrib/json.hppdirectly now getnlohmann::jsonfrom the BT.CPP headers, like any user would.system-jsonjob builds and tests OFF on Ubuntu 22.04 with apt's nlohmann_json 3.10.5, the oldest supported version.Differences from #1080
#1080 defined
BTCPP_VENDORED_JSONin the default build and fell back to<nlohmann/json.hpp>when the macro was missing. Any user that doesn't link the CMake target, for example through the plain variables exported for ROS, Makefiles or Bazel, would have silently switched to the system nlohmann_json while the library was still built with the bundled one. That is the #959 bug again, hitting people who never touched the option.This PR flips the polarity: only OFF defines a macro, and the default path includes the bundled header exactly as today. It also drops the stray
FIXME.md, fixes the 2 test includes, adds the ament export, and adds the CI job.Compatibility
bt_factory.h+json_export.h+groot2_protocol.hpreprocess to byte-identical output.nlohmann::jsonappears in public signatures (e.g.ExportBlackboardToJSON), so an OFF build has a different ABI. Everything linking it must be built against the same nlohmann_json. Binary packages (ROS debs, conda, vcpkg) keep the bundled copy.Testing
ninja -t deps)find_package+BT::behaviortree_cpp, ON and OFF installs-DBTCPP_SYSTEM_JSONfrom the targetg++ -I<prefix>/include(no CMake)fatal error: behaviortree_cpp/contrib/json.hpp: No such file or directorybehaviortree_cpp::behaviortree_cppnlohmann_jsonlisted in the exported dependencies; builds and runs🤖 Generated with Claude Code