ROS 2 Cross-compilation / Multi architecture development

I am developing ros2 based applications in x86 and deploy to Nvidia DriveAGX machines. And cmake(colcon) based cross compile is OK for you x86 PC development environment.

  1. in your PC, use a x86 docker container based on ubuntu(like 20.04 for ros2 foxy)
  2. add multiarch support in your ubuntu container, so that you can install aarch64 deb
  3. install aarch64 ros2 foxy in ubuntu container
    1. you need a aarch64 ubuntu sysroot (I didn’t do it cause Nvidia officially offer the base sysroot)
    2. bring ros2-foxy-aarch64 binary under sysroot(like /opt/ros/foxy)
    3. install some aarch64 thirdparty debs(like libspdlog-dev:arm64)
  4. setup your CMakelist, and Toolchain file, so that cmake can use cross-compile cctoolchain and find_package well with aarch64 deb thirdparties
  5. use colcon wrapper to call cmake with x86 and aarch64(with your toolchain file)

the upper steps is for crosscompile applications based on ros2-aarch6-foxy(already compiled), and should get pretty better performance than qemu based methods(I think 10x sppedup compile time)

and extra benefit is, you can run aarch64 ros2 nodes in your x86 ubuntu container, because you actually have a runtime environment for aarch64 executable, and the binary can run with qumu(in your x86 container)

the key point is cmake usage when cross compile with cpp and python, and find_package with sysroot.

if you want to build ros2 itself using cmake based crosscompile, you will do much more with dependency management. Really tough

In this case, I suggest to

  1. seek public binaries in popular docker images, like osrf or nvidia issac-ros
  2. use qumu based container to build ros2 natively, and distribute the binary

reference: How to install ros2 foxy/humble on Nvidia DRIVE OS 6.0.5 - DRIVE AGX Orin / DRIVE AGX Orin General - NVIDIA Developer Forums