Gate C++ Standard By ROS Distro#1477
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the native addon build configuration to select the C++ language standard based on the detected ROS 2 distro version (instead of the Node.js major version), and documents the expected toolchain requirements for source builds.
Changes:
- Remove
node_major_versionfrombinding.gypand gate-std=c++17vs-std=c++20usingros_version(<= 2505vs> 2505) on both Linux and Windows. - Add a “C++ Toolchain Requirements” section to
docs/BUILDING.mddescribing the expected C++ standard by ROS distro.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| docs/BUILDING.md | Documents expected C++ standard for building from source. |
| binding.gyp | Switches C++ standard selection from Node-major gating to ROS-version gating (Linux/Windows). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - Post-Kilted distros, including Lyrical and newer Rolling snapshots, build with C++20. | ||
|
|
||
| If no prebuilt binary is available for your target, make sure your local compiler matches the required C++ standard before running `npm install`. |
There was a problem hiding this comment.
The docs state that Lyrical builds with C++20, but the repository currently has no ROS distro mapping for "lyrical" (search for "lyrical" yields no results, and lib/distro.js only defines up to Kilted + Rolling). As-is, node scripts/ros_distro.js will treat ROS_DISTRO=lyrical as unknown and node-gyp will fail before this toolchain guidance can apply. Either add Lyrical to the distro detection/version mapping as part of this PR, or remove/soften the Lyrical mention until that support lands.
| - Post-Kilted distros, including Lyrical and newer Rolling snapshots, build with C++20. | |
| If no prebuilt binary is available for your target, make sure your local compiler matches the required C++ standard before running `npm install`. | |
| - Rolling may require C++20 depending on the snapshot and ROS 2 toolchain in use. | |
| If no prebuilt binary is available for your target, make sure your local compiler matches the required C++ standard before running `npm install`. For distros or snapshots newer than the ones explicitly listed above, verify the toolchain requirement in the corresponding ROS 2 documentation first. |
| # Post-Kilted ROS distros require C++20. | ||
| 'ros_version > 2505', { | ||
| 'cflags_cc': [ | ||
| '-std=c++20' | ||
| ] | ||
| } | ||
| ], | ||
| [ | ||
| 'node_major_version < 23', { | ||
| 'ros_version <= 2505', { | ||
| 'cflags_cc': [ |
There was a problem hiding this comment.
This C++ standard gate relies on ros_version coming from node scripts/ros_distro.js, which will exit with an error for unknown ROS_DISTRO values. Since lib/distro.js does not currently include a Lyrical ID, builds on Lyrical will fail (even though the PR description/docs call it out). Consider adding a Lyrical entry (likely 2605) to the distro mapping alongside this change so the ros_version > 2505 condition can actually be reached on that distro.
| The native addon follows the ROS 2 distro toolchain requirement: | ||
|
|
||
| - Humble, Jazzy, and Kilted build with C++17. | ||
| - Post-Kilted distros, including Lyrical and newer Rolling snapshots, build with C++20. | ||
|
|
||
| If no prebuilt binary is available for your target, make sure your local compiler matches the required C++ standard before running `npm install`. | ||
|
|
There was a problem hiding this comment.
This section states the addon "follows the ROS 2 distro toolchain requirement" in general, but the build config only gates the C++ standard for Linux and Windows; macOS is still hard-coded to c++17 in binding.gyp regardless of ros_version. To avoid misleading source-builders, clarify that the C++17/C++20 split applies to the Linux/Windows build paths (or update the macOS build settings to match).
| The native addon follows the ROS 2 distro toolchain requirement: | |
| - Humble, Jazzy, and Kilted build with C++17. | |
| - Post-Kilted distros, including Lyrical and newer Rolling snapshots, build with C++20. | |
| If no prebuilt binary is available for your target, make sure your local compiler matches the required C++ standard before running `npm install`. | |
| The native addon follows the ROS 2 distro toolchain requirement on Linux and Windows source-build paths: | |
| - Humble, Jazzy, and Kilted build with C++17. | |
| - Post-Kilted distros, including Lyrical and newer Rolling snapshots, build with C++20. | |
| On macOS, the current source-build configuration is fixed to C++17. | |
| If no prebuilt binary is available for your target, make sure your local compiler matches the required C++ standard for your platform before running `npm install`. |
build: switch native addon C++ standard selection from Node.js-major gating to ROS-distro gating
node_major_versionfrombinding.gypros_version <= 2505ros_version > 2505docs(build): document source-build C++ toolchain requirements
C++ Toolchain Requirementssection todocs/BUILDING.mdReference:
Fix: #1458