ros-realtime/ros-realtime-rpi4-image

Cross compiling ros2 packages

Teusner opened this issue · 2 comments

If I want to cross-compile a ros2 package from sources available on GitHub in a custom image, I suppose I need to add a phase2-host script.

In this script I first clone all the repositories to be cross-compiled in the process using vcs (from the vcs-tools package), and then it seems a little bit fuzzy when I want to automatically install ros2 dependencies using rosdep as the script is executed as root ...

Here is the part of the script which is causing me troubles :

vcs import < repos.yaml
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro humble -r -y
colcon build --cmake-force-configure --cmake-args -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE

I get the following warn:

+ rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
Warning: running 'rosdep update' as root is not recommended.
  You should run 'sudo rosdep fix-permissions' and invoke 'rosdep update' again without sudo.
[...]

And then nothing is installed as on my system everything is already setup ( I have already rosdep install everything needed on my system as I already have compiled the code somewhere else ...)

+ rosdep install --from-paths src --ignore-src --rosdistro humble -r -y
#All required rosdeps installed successfully

But then, when colcon is trying to build the workspace, I get:

+ colcon build --cmake-force-configure --cmake-args -DCMAKE_TOOLCHAIN_FILE=[...]/data/toolchain.cmake
[...]
--- stderr: my_pkg                                                                                               
CMake Error at CMakeLists.txt:14 (find_package):
  By not providing "Findament_cmake.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "ament_cmake", but CMake did not find one.

  Could not find a package configuration file provided by "ament_cmake" with
  any of the following names:

    ament_cmakeConfig.cmake
    ament_cmake-config.cmake
[...]

I think packages (ament_cmake, and others ...) are installed user space and not accessible root space (but maybe I'm wrong) and so the compile process which is launched as root is not able to find the required packages.

How can I get this working ?

That script is executing commands on the host. As far as I understand, rosdep is installing apt packages which should be installed on the target. I.e. the rosdep command should be running on the target instead of host. you can do that if you rearrange your git clone command in the 4 scripts where we run host and target commands twice in series (sorry for the vague instructions as I'm on mobile and on vacation. Please reply if you have more problems, I'll get back in a few days when I can review this in more detail).

That said, I personally find the rosdep system to be somewhat problematic in design. Typically I get around this issue by having the list of packages I need for the development and runtime of the application and directly apt get install those without the usage of rosdep and vcstools inadequately solves the dependency management problem. This significantly simplifies a lot of deployment systems.

Ok, understood, I will use the phase1-target script to install exec_depend packages, and rosdep doesn't seems suitable with this tool. I will close this issue, thanks for explanations