Skip to content

[Jazzy] Fix building with Apple clang (macOS): backports and Jazzy-only fixes - #6815

Merged
jwallace42 merged 14 commits into
ros-navigation:jazzyfrom
idesign0:jazzy-macos-backports
Nov 18, 2026
Merged

jwallace42 merged 14 commits into
ros-navigation:jazzyfrom
idesign0:jazzy-macos-backports

Conversation

@idesign0

@idesign0 idesign0 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Basic Info

Info Please fill out this column
Ticket(s) this addresses Backports of #5679, #5729, #6017, #6803, #4974, #5016, #5782, #6816
Primary OS tested on MacOS (27, arm64, Apple clang 21)
Robotic platform tested on N/A (build + lifecycle configure of the nav2 servers)
Does this PR contain AI generated software? #5679, #5729 and #6017 are my changes; #6803, #6816 and the Jazzy-only commits were written with Claude Code; #4974 / #5016 are cherry-picked unchanged. Everything was checked with the builds below
Was this PR description generated by AI software? Yes (Claude Code), reviewed by me

Description of contribution in a few bullet points

Makes nav2 Jazzy build with Apple clang on macOS under nav2_package()'s -Werror. One commit per fix.

Backports of PRs merged on main / humble (as suggested by @jwallace42 on #5679, #5729, #6017 and #6803):

Commit Original What it fixes
Use Mach thread policy for soft real-time priority on macOS #5679, node_utils part only nav2_util: sched_setscheduler / SCHED_FIFO don't exist on macOS; on __APPLE__ uses Mach THREAD_TIME_CONSTRAINT_POLICY, same code as main
Add template keyword for dependent calls on macOS #5729 bt_action_server_impl.hpp subtree blackboard setters and route_operation_client.hpp; Jazzy's cancel_timeout setter (#5903) is kept
Fix Apple Clang template ambiguity in MPPI #6017 (humble) xt::cumsum(..., {1}) in optimizer.cpp (-Wbraced-scalar-init); adapted to Jazzy's files
Fix clang -Werror errors in nav2_system_tests and nav2_rviz_plugins #6803 missing override in controller_error_plugins.hpp, stoi() result in nav2_panel.cpp
nav2_rviz_plugins: Remove slots without implementation / Don't use non-existent slot #4974, #5016 (unchanged) libnav2_rviz_plugins.dylib fails to link on macOS (declared but undefined slots)
Mark virtual overrides with override #5782 -Winconsistent-missing-override in costmap_filter.hpp, keepout_filter.hpp, plugin_container_layer.hpp, route_tool.hpp. Jazzy keeps override (not final) on CostmapFilter::isClearable() so out-of-tree filters still build
nav2_mppi_controller: GCC-only flags only for GCC, match AppleClang #6816 (open on main) STREQUAL "Clang" misses AppleClang, so it got -fconcepts; Jazzy also passes -finline-limit to every compiler, now GCC only. GCC's flags are unchanged

Jazzy-only fixes (the code they touch was rewritten or already fixed on main, so there is nothing to fix there):

Commit Error on Jazzy Why not on main
Circle: keep Polygon::updatePolygon overloads visible circle.hpp: 'Circle::updatePolygon' hides overloaded virtual function [-Woverloaded-virtual] renamed to updatePolygonFromRadius in #6136
mppi: only probe x86 SIMD flags on x86 clang++: error: argument unused during compilation: '-msse4.2' on arm64 MPPI rewritten with Eigen (#4621)
mppi: guard GCC-only diagnostic pragmas from clang unknown warning group '-Wstringop-overflow' / -Wmaybe-uninitialized same
mppi: drop std::move on xtensor expression temporaries moving a temporary object prevents copy elision [-Wpessimizing-move] same
route, smac_planner: use the nlohmann_json / nanoflann targets 'nlohmann/json.hpp' file not found, 'nanoflann.hpp' file not found (headers not in a default include dir) main uses the targets already
smac_planner: drop unused #include <omp.h> 'omp.h' file not found not on main

No behaviour change: these are annotations, include paths, compiler-specific flags and pragmas. For the Jazzy-only commits, the compiled object code was compared before and after with identical flags and is byte-identical.

Description of documentation updates required from your changes

  • None

Description of how this change was tested

  • macOS 27 (arm64, Apple clang 21), built as an overlay on a ROS 2 Jazzy install, with nav2_package()'s -Werror and no extra flags or workarounds: all 45 nav2 packages build (upstream jazzy fails in nav2_util, nav2_behavior_tree, nav2_bt_navigator, nav2_costmap_2d, nav2_collision_monitor, nav2_mppi_controller, nav2_route, nav2_smac_planner, nav2_rviz_plugins and nav2_system_tests).
  • From that build, planner, controller (MPPI), behavior, bt_navigator, smoother, waypoint_follower, velocity_smoother, collision_monitor and route servers start and configure through lifecycle with nav2_bringup's nav2_params.yaml, all plugins load, no errors.
  • Each backport was also checked before/after on its own against upstream jazzy, e.g. node_utils.cpp:97:7: error: use of undeclared identifier 'sched_setscheduler' and bt_action_server_impl.hpp:268:19: error: use 'template' keyword to treat 'set' as a dependent template name.
  • Linux/GCC: relying on CI.

Future work that may be required in bullet points

  • None

For Maintainers:

  • Check that any new parameters added are updated in docs.nav2.org
  • Check that any significant change is added to the migration guide
  • Check that any new features OR changes to existing behaviors are reflected in the tuning guide
  • Check that any new functions have Doxygen added
  • Check that any new features have test coverage
  • Check that any new plugins is added to the plugins page
  • If BT Node, Additionally: add to BT's XML index of nodes for groot, BT package's readme table, and BT library lists
  • Should this be backported to current distributions? If so, tag with backport-*.

🤖 Generated with Claude Code

idesign0 and others added 6 commits November 17, 2026 20:44
…os-navigation#5679)

Partial backport of ros-navigation#5679 to jazzy: only the nav2_util node_utils change.
sched_setscheduler() and SCHED_FIFO do not exist on macOS, so nav2_util
fails to compile there. On __APPLE__, setSoftRealTimePriority() now uses
the Mach thread precedence policy; other platforms are unchanged. The
std::chrono cast part of ros-navigation#5679 targets main and is not needed on jazzy.

Compile-tested on macOS 27 (arm64, Apple clang 21) as an overlay on a
ROS 2 Jazzy install: nav2_util builds with nav2_package()'s -Werror.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>
…ation#5729)

Backport of ros-navigation#5729 to jazzy. Apple clang rejects calls to member templates
of a dependent type without the `template` keyword, so nav2_behavior_tree
(bt_action_server_impl.hpp, subtree blackboard setters) and nav2_route
(route_operation_client.hpp, create_client) fail to compile there.
jazzy already has the route_server.hpp part via ros-navigation#6016. jazzy also sets
cancel_timeout on the subtree blackboard (ros-navigation#5903); it is kept, with the
same keyword.

Compile-tested on macOS 27 (arm64, Apple clang 21) as an overlay on a
ROS 2 Jazzy install: nav2_behavior_tree and nav2_bt_navigator build with
nav2_package()'s -Werror.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>
)

Backport of ros-navigation#6017 (merged into humble) to jazzy, whose MPPI still uses
xtensor. On Apple clang the xt::cumsum(..., {1}) calls in optimizer.cpp
resolve through a braced scalar (-Wbraced-scalar-init, an error under
nav2_package()'s -Werror). As in ros-navigation#6017, these use the cumsum helpers in
tools/apple_utils.hpp on __APPLE__; the non-Apple path is unchanged in
result. The humble commit does not apply cleanly to jazzy, so this is
the same change adapted to jazzy's files.

Compile-tested on macOS 27 (arm64, Apple clang 21) as an overlay on a
ROS 2 Jazzy install, both sides with the same local CMakeLists workaround
for the separate AppleClang flag issue: upstream jazzy reports
optimizer.cpp:380/396/398 "braces around scalar initializer"; with this
change those are gone and the remaining errors (-Wpessimizing-move in
four critics, a separate issue) are identical on both sides.

Signed-off-by: Dhruv Patel <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…os-navigation#6803)

Backport of ros-navigation#6803 to jazzy.

* nav2_system_tests: mark the UnknownErrorController overrides (cleanup,
  activate, deactivate, setPlan, computeVelocityCommands, setSpeedLimit)
  with override (-Winconsistent-missing-override).
* nav2_rviz_plugins: discard the stoi() result explicitly
  (-Wunused-result; libc++ marks std::stoi [[nodiscard]]).

Adapted to jazzy: setPlan instead of newPathReceived, and
computeVelocityCommands takes the GoalChecker.

Compile-tested on macOS 27 (arm64, Apple clang 21) as an overlay on a
ROS 2 Jazzy install, with nav2_package()'s -Werror:
nav2_system_tests fails on upstream jazzy with 6 missing-override errors
and builds with this change; nav2_rviz_plugins' nav2_panel.cpp
-Wunused-result error is gone.

(cherry picked from commit 6272fad)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>
…n#4974)

Without this change, when compiled for Jazzy with Nix using gcc14 and
qt-5.15, loading the plugins to rviz fails with the following error:

    [rviz2]: PluginlibFactory: The plugin for class
    'nav2_rviz_plugins/Navigation 2' failed to load. Error: Failed to
    load library /nix/store/...-ros-env/lib/libnav2_rviz_plugins.so.
    Make sure that you are calling the PLUGINLIB_EXPORT_CLASS macro in
    the library code, and that names are consistent between this macro
    and your XML. Error string: Could not load library dlopen error:
    /nix/store/...-ros-env/lib/libnav2_rviz_plugins.so: undefined
    symbol: _ZN17nav2_rviz_plugins12DockingPanel9onStartupEv, at
    /build/rcutils-release-release-jazzy-rcutils-6.7.2-1/src/shared_library.c:99

The dynamic linker complains about undefined symbol, which corresponds
to a Qt slot, which is declared, but has no implementation. I'm not
sure what is the root cause of this behavior, but removing the slot
definitions fixes the problem and the plugins can be loaded.

Signed-off-by: Michal Sojka <[email protected]>
(cherry picked from commit e6f500e)
Signed-off-by: Dhruv Patel <[email protected]>
The definition of the slot was removed in commit
e6f500e ("nav2_rviz_plugins: Remove slots without
implementation (ros-navigation#4974)", 2025-03-10), because it had no
implementation. But we forgot to remove the reference to this slot,
because the compiler cannot detect it.

We remove the reference now. Without this, rviz shows warnings like:

    QObject::connect: No such slot nav2_rviz_plugins::CostmapCostTool::updateAutoDeactivate()
    QObject::connect:  (sender name:   'Single click')

Signed-off-by: Michal Sojka <[email protected]>
(cherry picked from commit 46dbd07)
Signed-off-by: Dhruv Patel <[email protected]>
@mergify

mergify Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

@idesign0, all pull requests must be targeted towards the main development branch.
Once merged into main, it is possible to backport to @jazzy, but it must be in main
to have these changes reflected into new distributions.

@jwallace42
jwallace42 self-requested a review November 17, 2026 19:52
@idesign0
idesign0 marked this pull request as ready for review November 17, 2026 19:59
idesign0 and others added 8 commits November 17, 2026 21:04
Clang reports -Winconsistent-missing-override (an error under
nav2_package()'s -Werror) in costmap_filter.hpp, keepout_filter.hpp,
plugin_container_layer.hpp and route_tool.hpp, where some overrides are
marked and others are not. Same headers as ros-navigation#5782 on main; jazzy keeps
`override` instead of `final` on CostmapFilter::isClearable() so
out-of-tree filters that override it still build, and keepout_filter
uses jazzy's Pose2D signature. The map_server and planner_server parts of
ros-navigation#5782 are not needed on jazzy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>
…irtual)

  circle.hpp:102:8: error: 'nav2_collision_monitor::Circle::updatePolygon' hides
  overloaded virtual function [-Werror,-Woverloaded-virtual]

Circle::updatePolygon(double) hid Polygon::updatePolygon(const Velocity &) (public,
virtual) and Polygon::updatePolygon(PolygonStamped::ConstSharedPtr) (protected).
A using-declaration in Circle's protected section brings them back into Circle's
scope. Circle overrides neither, so virtual dispatch is unchanged; the one call inside
Circle, updatePolygon(msg->data) with a float, still selects updatePolygon(double)
(Velocity is an aggregate and a shared_ptr is not constructible from a float), and
calls through Polygon pointers are unaffected.

Tested on macOS 27 (arm64), Apple clang 21, CMake 4.4.2: all 45 packages of this
branch build as an overlay on ros2-jazzy 26.11.16.7 with nav2_package()'s -Werror active
and no extra compiler flags. Every translation unit of nav2_costmap_2d,
nav2_collision_monitor, nav2_mppi_controller, nav2_route, nav2_rviz_plugins,
nav2_smac_planner and the nav2_system_tests controller plugins (138) was compiled from
the previous commit and from this series with identical flags (the originals with
-Wno-error, both with the source root mapped to one path): `otool -tV` output is
byte-identical for all 138. planner/controller/behavior/bt_navigator/smoother/
waypoint_follower/velocity_smoother/collision_monitor/route_server configure through
lifecycle with nav2_bringup's nav2_params.yaml.
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Dhruv Patel <[email protected]>
  clang++: error: argument unused during compilation: '-msse4.2'
  [-Werror,-Wunused-command-line-argument]

On arm64, check_cxx_compiler_flag("-msse4.2") passes (clang only warns that the flag
is unused) while -mno-avx512f, -mavx2 and -mfma are rejected, so -msse4.2 alone was
added -- with no effect on arm64 code, and fatal under -Werror. The checks and
add_compile_options now run only when CMAKE_SYSTEM_PROCESSOR is x86; on x86 they are
exactly as before.

Tested on macOS 27 (arm64), Apple clang 21, CMake 4.4.2: all 45 packages of this
branch build as an overlay on ros2-jazzy 26.11.16.7 with nav2_package()'s -Werror active
and no extra compiler flags. Every translation unit of nav2_costmap_2d,
nav2_collision_monitor, nav2_mppi_controller, nav2_route, nav2_rviz_plugins,
nav2_smac_planner and the nav2_system_tests controller plugins (138) was compiled from
the previous commit and from this series with identical flags (the originals with
-Wno-error, both with the source root mapped to one path): `otool -tV` output is
byte-identical for all 138. planner/controller/behavior/bt_navigator/smoother/
waypoint_follower/velocity_smoother/collision_monitor/route_server configure through
lifecycle with nav2_bringup's nav2_params.yaml.
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Dhruv Patel <[email protected]>
…-option)

  tools/utils.hpp: error: unknown warning group '-Wstringop-overflow', ignored
  [-Werror,-Wunknown-warning-option]
  (and '-Wmaybe-uninitialized'; same in critic_data.hpp, critic_manager.hpp,
  models/*.hpp, motion_models.hpp, optimizer.hpp, tools/noise_generator.hpp,
  tools/trajectory_visualizer.hpp)

-Wstringop-overflow and -Wmaybe-uninitialized exist only in GCC; clang ignores the
pragma and warns. Each such pragma line is wrapped in
#if defined(__GNUC__) && !defined(__clang__). GCC sees the same pragmas as before;
clang never acted on them. -Warray-bounds (known to both) is left as is.
(test/utils_test.cpp carries the same pragma and gets the same guard; tests were not
built here.)

Tested on macOS 27 (arm64), Apple clang 21, CMake 4.4.2: all 45 packages of this
branch build as an overlay on ros2-jazzy 26.11.16.7 with nav2_package()'s -Werror active
and no extra compiler flags. Every translation unit of nav2_costmap_2d,
nav2_collision_monitor, nav2_mppi_controller, nav2_route, nav2_rviz_plugins,
nav2_smac_planner and the nav2_system_tests controller plugins (138) was compiled from
the previous commit and from this series with identical flags (the originals with
-Wno-error, both with the source root mapped to one path): `otool -tV` output is
byte-identical for all 138. planner/controller/behavior/bt_navigator/smoother/
waypoint_follower/velocity_smoother/collision_monitor/route_server configure through
lifecycle with nav2_bringup's nav2_params.yaml.
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Dhruv Patel <[email protected]>
…-move)

  constraint_critic.cpp: error: moving a temporary object prevents copy elision
  [-Werror,-Wpessimizing-move]   (6x; velocity_deadband_critic.cpp 4x,
  prefer_forward_critic.cpp 2x, path_follow_critic.cpp 2x)

std::move(expr) on a prvalue only adds a move. Each std::move(X) becomes (X) --
parentheses kept, so grouping is unchanged: e.g. std::move(a + b + c) * dt stays
(a + b + c) * dt, not a + b + c * dt -- and where the call was already wrapped,
(std::move(X)) becomes (X). Machine code of all four critics is byte-identical to before
(see below).

Tested on macOS 27 (arm64), Apple clang 21, CMake 4.4.2: all 45 packages of this
branch build as an overlay on ros2-jazzy 26.11.16.7 with nav2_package()'s -Werror active
and no extra compiler flags. Every translation unit of nav2_costmap_2d,
nav2_collision_monitor, nav2_mppi_controller, nav2_route, nav2_rviz_plugins,
nav2_smac_planner and the nav2_system_tests controller plugins (138) was compiled from
the previous commit and from this series with identical flags (the originals with
-Wno-error, both with the source root mapped to one path): `otool -tV` output is
byte-identical for all 138. planner/controller/behavior/bt_navigator/smoother/
waypoint_follower/velocity_smoother/collision_monitor/route_server configure through
lifecycle with nav2_bringup's nav2_params.yaml.
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Dhruv Patel <[email protected]>
…eir headers

  nav2_route/include/nav2_route/graph_loader.hpp:22:10: fatal error:
  'nlohmann/json.hpp' file not found
  nav2_route/include/nav2_route/node_spatial_tree.hpp:21:10: fatal error:
  'nanoflann.hpp' file not found
  nav2_smac_planner/include/nav2_smac_planner/node_lattice.hpp:30:10: fatal error:
  'nlohmann/json.hpp' file not found

nav2_route names nlohmann_json in ament_target_dependencies(), which only forwards
<pkg>_INCLUDE_DIRS/<pkg>_TARGETS -- nlohmann_json's config defines neither -- and it
find_package()s nanoflann without using it; nav2_smac_planner includes json.hpp
without finding the package. Both only build where the headers sit in a default
include dir (/usr/include on Ubuntu). Link nlohmann_json::nlohmann_json (and
nanoflann::nanoflann for nav2_route), header-only INTERFACE targets that add their
include dir, and export the dependencies their installed headers need so consumers
(nav2_rviz_plugins) can resolve those targets. Both are already <depend>s in
package.xml. No generated code changes (nav2_route and nav2_smac_planner objects are
byte-identical, below).

Tested on macOS 27 (arm64), Apple clang 21, CMake 4.4.2: all 45 packages of this
branch build as an overlay on ros2-jazzy 26.11.16.7 with nav2_package()'s -Werror active
and no extra compiler flags. Every translation unit of nav2_costmap_2d,
nav2_collision_monitor, nav2_mppi_controller, nav2_route, nav2_rviz_plugins,
nav2_smac_planner and the nav2_system_tests controller plugins (138) was compiled from
the previous commit and from this series with identical flags (the originals with
-Wno-error, both with the source root mapped to one path): `otool -tV` output is
byte-identical for all 138. planner/controller/behavior/bt_navigator/smoother/
waypoint_follower/velocity_smoother/collision_monitor/route_server configure through
lifecycle with nav2_bringup's nav2_params.yaml.
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Dhruv Patel <[email protected]>
  nav2_smac_planner/src/a_star.cpp:16:10: fatal error: 'omp.h' file not found

a_star.cpp uses no OpenMP (no #pragma omp, no omp_* call) and the package neither
finds nor links OpenMP, so the include is unused; it only compiles where omp.h is a
default header (GCC). Removed; a_star.cpp's object code is byte-identical.

Tested on macOS 27 (arm64), Apple clang 21, CMake 4.4.2: all 45 packages of this
branch build as an overlay on ros2-jazzy 26.11.16.7 with nav2_package()'s -Werror active
and no extra compiler flags. Every translation unit of nav2_costmap_2d,
nav2_collision_monitor, nav2_mppi_controller, nav2_route, nav2_rviz_plugins,
nav2_smac_planner and the nav2_system_tests controller plugins (138) was compiled from
the previous commit and from this series with identical flags (the originals with
-Wno-error, both with the source root mapped to one path): `otool -tV` output is
byte-identical for all 138. planner/controller/behavior/bt_navigator/smoother/
waypoint_follower/velocity_smoother/collision_monitor/route_server configure through
lifecycle with nav2_bringup's nav2_params.yaml.
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Dhruv Patel <[email protected]>
Two compiler checks in the CMakeLists break Apple clang:
* -finline-limit is passed to every compiler; clang rejects it
  (-Wignored-optimization-argument, an error under -Werror). It is now
  added only for GCC; the other optimization flags are unchanged for all.
* The C++20 branch checks CMAKE_CXX_COMPILER_ID STREQUAL "Clang", but
  Apple's compiler reports "AppleClang", so it gets -fconcepts
  (clang++: error: unknown argument: '-fconcepts'). Use MATCHES "Clang",
  as in ros-navigation#6816 on main.

GCC gets exactly the same flags as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>
@idesign0 idesign0 changed the title [Jazzy] Backport macOS / Apple clang build fixes (#5679, #5729, #6017, #6803, #4974, #5016) [Jazzy] Fix building with Apple clang (macOS): backports and Jazzy-only fixes Nov 17, 2026
@idesign0

Copy link
Copy Markdown
Contributor Author

@jwallace42 sorry for the changes after your approval: I added the remaining Jazzy-only clang fixes (and the #5782 / #6816 backports) so nav2 fully builds on macOS. With these, all 45 packages build with -Werror. Details per commit are in the description.

@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

@jwallace42
jwallace42 merged commit c704655 into ros-navigation:jazzy Nov 18, 2026
12 of 13 checks passed
idesign0 added a commit to idesign0/id_navigation2 that referenced this pull request Nov 30, 2026
…avigation#6815

Nine of the fork's commits landed upstream through ros-navigation#6815 (ours) and are reverted in
the previous commits. The three remaining conflicts were the same fixes in their
reviewed upstream form, so upstream's text is taken:
- bt_action_server_impl.hpp: cancel_timeout on subtree blackboards (formatting only)
- nav2_mppi_controller/CMakeLists.txt: GNU/Clang optimisation and SIMD-flag gating
  (upstream gates on Clang, ours additionally on Darwin)
- nav2_panel.cpp: stoi() result discarded (comment only)
Our empty definitions of CostmapCostTool::updateAutoDeactivate() and
DockingPanel::onStartup() are dropped too: upstream no longer declares either slot,
so keeping them would no longer compile.

What remains of the fork on top of upstream jazzy: <depend>ceres-solver</depend> in
nav2_constrained_smoother/package.xml (764f4c1).

Not compile-tested locally: every C++/CMake file now equals upstream jazzy c704655, which
carries our compile-tested ros-navigation#6815; the one remaining change is a package.xml
dependency entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants