How to configure AMENT_PREFIX_PATH for cross compilation

asked 2021-12-27 10:18:43 -0500

allsey87 gravatar image

I am trying to cross compile ROS2 nodes using Emscripten and a custom RMW (to enable communication with other nodes via Javascript). However, when building rmw_implementation, my custom RMW layer cannot be found. I believe the reason for this is either the ament index is not being installed/copied into the correct location or AMENT_PREFIX_PATH has not been set correctly. By hacking the CMake, I can see that the index is being searched for under the following paths:

/home/developer/workspace/build/rmw_implementation/ament_cmake_index/share/ament_index/resource_index
/home/developer/workspace/install/rmw_implementation/share/ament_index/resource_index
/home/developer/workspace/install/rosidl_cli/share/ament_index/resource_index
/home/developer/workspace/install/ament_package/share/ament_index/resource_index
/home/developer/workspace/install/ament_index_python/share/ament_index/resource_index

However, currently the only location where the index has been installed is:

/home/developer/emsdk/upstream/emscripten/cache/sysroot/usr/share/ament_index/resource_index

Although I can confirm that setting the environment variable AMENT_PREFIX_PATH to /home/developer/emsdk/upstream/emscripten/cache/sysroot/usr works as far as getting this step to compile goes, it feels like a bit of a hack. Is there a cleaner way to have AMENT_PREFIX_PATH honor either CMAKE_STAGING_PREFIX, CMAKE_INSTALL_PREFIX, or CMAKE_FIND_ROOT_PATH? Alternatively, is there a reason why the index is not available in either of these two directories?

/home/developer/workspace/build/rmw_implementation/ament_cmake_index/share/ament_index/resource_index
/home/developer/workspace/install/rmw_implementation/share/ament_index/resource_index

The following mixin shows how I am enabling cross compilation with Emscripten:

 {
    "build": {
        "emscripten": {
            "cmake-args": [
                "-DCMAKE_TOOLCHAIN_FILE=/home/developer/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake",
                "-DCMAKE_STAGING_PREFIX=/home/developer/emsdk/upstream/emscripten/cache/sysroot/usr",
                "-DBUILD_SHARED_LIBS=OFF",
                "-DBUILD_TESTING=OFF",
                "--no-warn-unused-cli"
            ],
        }
    }
}
edit retag flag offensive close merge delete

Comments

Note that CMAKE_INSTALL_PREFIX is actually set to /home/developer/workspace/install/rmw_implementation, however by setting CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT to TRUE from my mixin, the Emscripten toolchain sets CMAKE_INSTALL_PREFIX to /home/developer/emsdk/upstream/emscripten/cache/sysroot, which is almost what I want except that it is missing the usr from the end...

allsey87 gravatar image allsey87  ( 2021-12-27 10:35:49 -0500 )edit

Dropping the usr from CMAKE_STAGING_PREFIX in my mixin seems to solve the problem, but this all still feels like a bit of a hack to me...

allsey87 gravatar image allsey87  ( 2021-12-27 10:38:03 -0500 )edit