You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update (2026-11-17): Mitsudome-san and I agreed on the recommended option of each design decision. For D6, there is no bridge, also not as a dated exception. The work is tracked in this issue:
I propose that Autoware library packages export CMake targets, and that every package links its dependencies with target_link_libraries() and those targets. This replaces ament_target_dependencies(), which ROS 2 Lyrical removed. It is also the direction that upstream ROS takes, and a measurement on Autoware shows faster builds.
The proposal has five phases. This discussion is about the design decisions at the end, before any implementation PR.
Why
Lyrical removed ament_target_dependencies
ROS 2 Kilted deprecated ament_target_dependencies(), and Lyrical removed it. A package that calls it stops at configure time with Unknown CMake command "ament_target_dependencies".
The Kilted release notes say to replace each call with target_link_libraries() and modern CMake targets, as the deprecation warning prints it. That advice assumes that every dependency exports targets.
Our library packages export no targets
Most Autoware library packages use ament_auto_package() or autoware_ament_auto_package(). Both export the libraries as file paths with ament_export_libraries(), never as CMake targets. When a consumer calls find_package(), the ament export template flattens each dependency into file paths and appends them. It removes duplicates only inside one dependency, so the shared parts of the graph (the rclcpp closure, the message packages) repeat at every level.
Measured on Jazzy, after find_package():
Package
Entries in <pkg>_LIBRARIES
Unique
autoware_route_handler
5581
315
autoware_object_recognition_utils
4965
364
autoware_test_utils
4885
363
ament_target_dependencies() hid this, because it removed duplicates in every call. Upstream's replacement for ament_auto users, ament_auto_depend_on_packages(), does the same.
A one-to-one replacement makes link lines long and fragile
I first replaced every call one to one, with target_link_libraries() plus target_include_directories() from the variables:
In autoware_universe, the same rule made the link line of one test (test_label_based_euclidean_cluster) 2378 arguments long, against 969 on main. That link ran for more than 20 minutes, and the whole package built in about 43 seconds before. I have not found the exact trigger inside ld. The safe conclusion is that link lines built from flattened lists are long and their size depends on how the lists meet.
Targets do not have this problem. CMake walks the target graph and emits each library once. On Jazzy, a small executable linked to six ROS packages through ${<pkg>_TARGETS} got 143 library items, 142 of them unique. A small executable linked through three Autoware _LIBRARIES lists got 5294 items, 406 of them unique.
Targets make the build faster
An Autoware user measured a prototype of this idea on Humble in 2023:
The upstream change for ament_auto_package() from that work is still open, because the export is stricter and upstream worried about breaking ament_auto users:
autoware_cmake: autoware_ament_auto_package() exports a CMake target for each library of the package, in the same way as the open upstream change above (see D1 to D3). After that, every ament_auto package that depends on it links the targets on all distributions, without a change in its own CMakeLists.txt.
Producers: 105 workspace packages build a library with ament_auto_add_library() that another package uses. 37 of them use autoware_ament_auto_package() already. The other 68 use ament_auto_package() and move to the wrapper. On Humble and Jazzy both macros install headers to include, so the move changes nothing else.
Consumers: each ament_target_dependencies() call becomes target_link_libraries() with targets (see D4 and D5). Calls that only repeat what ament_auto already links are deleted: 7 in core, 17 in universe. One PR per repository.
Cleanup: when nothing reads <pkg>_LIBRARIES of Autoware packages anymore, the wrapper stops exporting the variables. This removes the configure cost of the flattened lists.
Upstream: help to finish the upstream change for Rolling, with Autoware's results, and keep the wrapper equal to it (see D7).
Dependencies outside Autoware
The current calls in core and universe name 73 packages. I probed what each one exports on Jazzy:
agnocast and transport_drivers do not use autoware_cmake. Their calls need PRs in their own repositories.
Known problems of the stricter export
A prototype must find and fix these before phase 1 lands:
install(EXPORT) stops when a public include folder points into the source or build tree. ament_auto_add_library() adds such a path, and many packages add target_include_directories(... PUBLIC include). The wrapper must wrap them in $<BUILD_INTERFACE:...>.
install(EXPORT) stops when a library links a local target that is not in the export set, for example the <pkg>_param target of generate_parameter_library or a CUDA library.
ament_auto passes only dependencies that are both build and run dependencies to ament_export_dependencies(). If the target of a <build_depend>-only dependency lands in the exported link interface, consumers fail with "target was not found". The fix is <depend> in package.xml.
The exported targets hold absolute paths of the few outside packages that export file lists. This works in a colcon workspace and in the Debian packages.
Design decisions
Each decision lists the options. The recommended option comes first and has a ⭐.
D1. Where the targets get exported
⭐ Option A (recommended): in autoware_ament_auto_package() in autoware_cmake.
Pros: no package changes until it opts in, also packages outside Autoware that use autoware_cmake, for example in the Autoware Index. Each package fixes its own export problems in its own PR. The same flag name keeps the path to upstream open.
Cons: one more word in 105 calls. A later change makes the export the default and removes the flag.
Option B: export by default, with an opt-out flag.
Pros: one change in autoware_cmake turns on 37 packages. Fewer changed lines in the end.
Cons: every user of the wrapper changes at once, also outside Autoware. Until every export problem in every repository is fixed, the autoware_cmake change cannot land, and a failure is harder to trace to one package.
D3. The classic variables during the transition
⭐ Option A (recommended): export both the targets and the classic variables until phase 4.
Pros: code that reads <pkg>_LIBRARIES keeps working, inside and outside Autoware. ament_target_dependencies() and ament_auto use the targets as soon as they exist, so the link lines get short at once.
Cons: the configure cost of the flattened lists stays until phase 4.
Cons: <pkg>_LIBRARIES no longer holds the package's own library, so every direct reader fails to link. The consumers must change first, but they cannot use targets before the targets exist.
D4. How a consumer names a dependency
⭐ Option A (recommended): ${<pkg>_TARGETS}.
Pros: one rule for every ROS package, also message packages. It is the form that upstream's deprecation warning prints for message packages. Nobody needs to know the target names.
Cons: if a package is not found or exports no targets, the variable is empty and nothing gets linked, without an error. The old function stopped with an error. It links every library of the package.
Option B: explicit names such as autoware_utils::autoware_utils.
Pros: CMake stops when the target does not exist. It links only what the code uses.
Cons: you must know each target name. Message packages have long generated names. A package with several libraries needs several names.
Pros: one line for every kind of package, and it stops when a package is not found.
Cons: it is in Kilted and later only, so Humble and Jazzy need a copy in autoware_cmake. It keeps the flattened lists alive for packages without targets.
Option B stays permitted where a package exports several libraries and the code needs only one.
D5. The scope keyword
⭐ Option A (recommended for this migration): the plain form without PUBLIC or PRIVATE, as the old calls had.
Cons: every dependency stays public, so consumers see more than they need.
Option B: PUBLIC and PRIVATE keywords.
Pros: the correct modern scope and smaller link interfaces.
Cons: every call on the target must use keywords, also the calls inside ament macros. It changes what downstream packages see. Each package needs its own review, so it is a separate step after this migration.
D6. Lyrical before the migration finishes
⭐ Option A (recommended): no bridge. Lyrical waits for phases 1 to 3.
Pros: no removed API comes back, and no temporary code to delete later.
Cons: Autoware does not build on Lyrical until phases 1 to 3 land in each repository.
Option B: a temporary copy of the Jazzy ament_target_dependencies() in autoware_cmake, active only where the command does not exist, deleted after phase 3.
Pros: Lyrical builds at once, with the same behavior and speed as Jazzy. The Lyrical work and this migration run in parallel.
Cons: Autoware brings back a function that upstream removed, and the copy can stay longer than planned.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
I propose that Autoware library packages export CMake targets, and that every package links its dependencies with
target_link_libraries()and those targets. This replacesament_target_dependencies(), which ROS 2 Lyrical removed. It is also the direction that upstream ROS takes, and a measurement on Autoware shows faster builds.The proposal has five phases. This discussion is about the design decisions at the end, before any implementation PR.
Why
Lyrical removed ament_target_dependencies
ROS 2 Kilted deprecated
ament_target_dependencies(), and Lyrical removed it. A package that calls it stops at configure time withUnknown CMake command "ament_target_dependencies".The upstream history and advice:
target_link_libraries()with imported targets does the same job in standard CMake.The Kilted release notes say to replace each call with
target_link_libraries()and modern CMake targets, as the deprecation warning prints it. That advice assumes that every dependency exports targets.Our library packages export no targets
Most Autoware library packages use
ament_auto_package()orautoware_ament_auto_package(). Both export the libraries as file paths withament_export_libraries(), never as CMake targets. When a consumer callsfind_package(), the ament export template flattens each dependency into file paths and appends them. It removes duplicates only inside one dependency, so the shared parts of the graph (therclcppclosure, the message packages) repeat at every level.Measured on Jazzy, after
find_package():<pkg>_LIBRARIESautoware_route_handlerautoware_object_recognition_utilsautoware_test_utilsament_target_dependencies()hid this, because it removed duplicates in every call. Upstream's replacement forament_autousers,ament_auto_depend_on_packages(), does the same.A one-to-one replacement makes link lines long and fragile
I first replaced every call one to one, with
target_link_libraries()plustarget_include_directories()from the variables:In autoware_universe, the same rule made the link line of one test (
test_label_based_euclidean_cluster) 2378 arguments long, against 969 onmain. That link ran for more than 20 minutes, and the whole package built in about 43 seconds before. I have not found the exact trigger insideld. The safe conclusion is that link lines built from flattened lists are long and their size depends on how the lists meet.Targets do not have this problem. CMake walks the target graph and emits each library once. On Jazzy, a small executable linked to six ROS packages through
${<pkg>_TARGETS}got 143 library items, 142 of them unique. A small executable linked through three Autoware_LIBRARIESlists got 5294 items, 406 of them unique.Targets make the build faster
An Autoware user measured a prototype of this idea on Humble in 2023:
ament_automacros are too slow? ament/ament_cmake#442behavior_path_plannerThe upstream change for
ament_auto_package()from that work is still open, because the export is stricter and upstream worried about breakingament_autousers:Before and after
A test that uses two Autoware packages, today on Jazzy:
A one-to-one replacement with the variables (the first attempt):
After this proposal, when both packages export targets:
Proposal
autoware_cmake:autoware_ament_auto_package()exports a CMake target for each library of the package, in the same way as the open upstream change above (see D1 to D3). After that, everyament_autopackage that depends on it links the targets on all distributions, without a change in its ownCMakeLists.txt.ament_auto_add_library()that another package uses. 37 of them useautoware_ament_auto_package()already. The other 68 useament_auto_package()and move to the wrapper. On Humble and Jazzy both macros install headers toinclude, so the move changes nothing else.ament_target_dependencies()call becomestarget_link_libraries()with targets (see D4 and D5). Calls that only repeat whatament_autoalready links are deleted: 7 in core, 17 in universe. One PR per repository.<pkg>_LIBRARIESof Autoware packages anymore, the wrapper stops exporting the variables. This removes the configure cost of the flattened lists.Dependencies outside Autoware
The current calls in core and universe name 73 packages. I probed what each one exports on Jazzy:
rclcpp,tf2_ros,pluginlib,cv_bridge,pcl_ros,rviz_common,diagnostic_updater,agnocastlib, all message packages${<pkg>_TARGETS}, no other changeEigen3,Python3,fmt,glog,yaml-cppfmt::fmt) where the code needs itOpenCV(55 targets), Lanelet2 (2 targets each),point_cloud_msg_wrapperament_autopackagesautoware_test_utils,autoware_utils,autoware_lanelet2_extension,cuda_blackboard,managed_transform_bufferpcl_conversions,grid_map_rospcl_conversionsexports targets on Lyrical already. Only Humble and Jazzy give the file list.grid_map_rosexports file lists on Lyrical too. A target export can join the grid_map work in Offer to help maintain the ROS 2 branches ANYbotics/grid_map#554.autoware_cmake. Their calls need PRs in their own repositories.Known problems of the stricter export
A prototype must find and fix these before phase 1 lands:
install(EXPORT)stops when a public include folder points into the source or build tree.ament_auto_add_library()adds such a path, and many packages addtarget_include_directories(... PUBLIC include). The wrapper must wrap them in$<BUILD_INTERFACE:...>.install(EXPORT)stops when a library links a local target that is not in the export set, for example the<pkg>_paramtarget ofgenerate_parameter_libraryor a CUDA library.ament_autopasses only dependencies that are both build and run dependencies toament_export_dependencies(). If the target of a<build_depend>-only dependency lands in the exported link interface, consumers fail with "target was not found". The fix is<depend>inpackage.xml.Design decisions
Each decision lists the options. The recommended option comes first and has a ⭐.
D1. Where the targets get exported
autoware_ament_auto_package()inautoware_cmake.ament_auto_package()must move to the wrapper.install(EXPORT)andament_export_targets()by hand.ament_autoto plain CMake.CMakeLists.txtfiles, far beyond the Lyrical work.D2. Default behavior of the wrapper
autoware_ament_auto_package(EXPORT_LIBRARY_TARGETS), the same name as in feat: add option to export libraries as cmake targets ament/ament_cmake#455.autoware_cmake, for example in the Autoware Index. Each package fixes its own export problems in its own PR. The same flag name keeps the path to upstream open.autoware_cmaketurns on 37 packages. Fewer changed lines in the end.autoware_cmakechange cannot land, and a failure is harder to trace to one package.D3. The classic variables during the transition
<pkg>_LIBRARIESkeeps working, inside and outside Autoware.ament_target_dependencies()andament_autouse the targets as soon as they exist, so the link lines get short at once.<pkg>_LIBRARIESno longer holds the package's own library, so every direct reader fails to link. The consumers must change first, but they cannot use targets before the targets exist.D4. How a consumer names a dependency
${<pkg>_TARGETS}.autoware_utils::autoware_utils.ament_auto_depend_on_packages()(Add ament_auto_depend_on_packages to replace ament_target_dependencies ament/ament_cmake#571).autoware_cmake. It keeps the flattened lists alive for packages without targets.Option B stays permitted where a package exports several libraries and the code needs only one.
D5. The scope keyword
PUBLICorPRIVATE, as the old calls had.ament_add_gtest(),ament_auto_add_library()), and CMake does not permit a mix of the plain form and keywords on one target ([kilted] Deprecating ament_target_dependencies with ament_add_gtest_executable ament/ament_cmake#580).PUBLICandPRIVATEkeywords.D6. Lyrical before the migration finishes
ament_target_dependencies()inautoware_cmake, active only where the command does not exist, deleted after phase 3.autoware_cmake.If the Lyrical job must pass before phase 3 can finish, I recommend Option B as a dated exception.
D7. Upstream
ament_autouser in ROS benefits, and the wrapper can forward to upstream later.ament_autousers keep the problem.Measurement
A prototype measures the build before and after phase 1, and again after phase 4:
colcon buildof core and universe on Jazzy, on one machine, with ccache off and-DBUILD_TESTING=OFF.autoware_behavior_path_plannerandautoware_route_handler.Not in this proposal
PUBLICandPRIVATEscopes for every dependency (D5 Option B).ament_auto_find_build_dependencies()itself.Related
AI usage
I wrote this with Claude Code (Claude Opus 5.5), from my direction. The agent also ran the probes and measurements in it.
All reactions