From 5f36f4c9435ccf88749e7da7c31d0581bbe4cdcc Mon Sep 17 00:00:00 2001 From: Antonio Cuadros <49162117+Acuadros95@users.noreply.github.com> Date: Thu, 9 Jun 2022 15:38:17 +0200 Subject: [PATCH] Build ROS2 from source on snap (#153) * Build ROS2 from source on snap * Update --- snap/hooks/configure | 2 +- snap/local/fastdds_no_shared_memory.xml | 19 +++++++ snap/local/micro-ros-agent-daemon | 2 +- snap/snapcraft.yaml | 70 ++++++++++++------------- 4 files changed, 56 insertions(+), 37 deletions(-) create mode 100644 snap/local/fastdds_no_shared_memory.xml diff --git a/snap/hooks/configure b/snap/hooks/configure index d51603c..d0729c7 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -101,4 +101,4 @@ case "$daemon" in echo "'$daemon' is not a valid boolean for daemon" >&2 return 1 ;; -esac \ No newline at end of file +esac diff --git a/snap/local/fastdds_no_shared_memory.xml b/snap/local/fastdds_no_shared_memory.xml new file mode 100644 index 0000000..a4f0105 --- /dev/null +++ b/snap/local/fastdds_no_shared_memory.xml @@ -0,0 +1,19 @@ + + + + + CustomUdpTransport + UDPv4 + + + + + + + CustomUdpTransport + + + false + + + diff --git a/snap/local/micro-ros-agent-daemon b/snap/local/micro-ros-agent-daemon index 1ec437e..32dc832 100755 --- a/snap/local/micro-ros-agent-daemon +++ b/snap/local/micro-ros-agent-daemon @@ -24,4 +24,4 @@ if [ -n "$p2p_port" ]; then set -- --p2p "$p2p_port" "$@" fi -exec "$SNAP/lib/micro_ros_agent/micro_ros_agent" "$transport" "$@" +exec "$SNAP/opt/ros/snap/lib/micro_ros_agent/micro_ros_agent" "$transport" "$@" diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 21a0138..4df4e57 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -71,16 +71,6 @@ description: | $ snap set micro-ros-agent device="device path" - If connecting the micro-ROS Agent using an IP based connection mode, - that is, `udp4`, `udp6`, `tcp4` or `tcp6`, care must be taken to - connect first the `micro-ros-agent-shm-netplug` plug. - This is due to the fact that ROS 2 Foxy is using Fast-DDS as the - default DDS middleware, and Fast-DDS comes with *shared memory transport*. - Thus, this plugin must be enabled, in order to gain access to the - `/dev/shm` folder from the snap image, prior to running it: - - $ sudo snap connect micro-ros-agent:micro-ros-agent-shm-netplug - When using the snap with a serial device, some steps need to be taken in order to establish a successful connection: @@ -120,49 +110,59 @@ architectures: - build-on: armhf - build-on: ppc64el +package-repositories: +- components: [main] + formats: [deb] + key-id: C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 + key-server: keyserver.ubuntu.com + suites: [focal] + type: apt + url: http://repo.ros2.org/ubuntu/main + parts: + ros2-foxy-extension: + build-packages: [ros-foxy-ros-core] + override-build: install -D -m 0755 launch ${SNAPCRAFT_PART_INSTALL}/snap/command-chain/ros2-launch + plugin: nil + source: $SNAPCRAFT_EXTENSIONS_DIR/ros2 uros-agent: plugin: colcon source: . - override-build: | - set +u - git clone https://github.com/eProsima/Micro-XRCE-DDS-Agent.git -b $ROS_DISTRO - git clone https://github.com/eProsima/Micro-CDR.git -b $ROS_DISTRO - git clone https://github.com/micro-ROS/micro_ros_msgs.git -b $ROS_DISTRO - git clone https://github.com/micro-ROS/rosidl_typesupport_microxrcedds.git -b $ROS_DISTRO - git clone https://github.com/micro-ROS/rmw-microxrcedds.git -b $ROS_DISTRO - git clone https://github.com/micro-ROS/micro-ROS-Agent.git -b $ROS_DISTRO - . /opt/ros/$ROS_DISTRO/setup.sh - colcon build --merge-install --install-base $SNAPCRAFT_PRIME --cmake-args "-DUAGENT_BUILD_EXECUTABLE=OFF -DUAGENT_USE_SYSTEM_FASTDDS=ON" --packages-up-to micro_ros_agent - set -u + colcon-cmake-args: + - -DMICROROSAGENT_SUPERBUILD=ON + - --cmake-force-configure + override-pull: | + snapcraftctl pull + + version="$(git describe --always --tags| sed -e 's/^v//;s/-/+git/;y/-/./')" + [ -n "$(echo $version | grep "+git")" ] && grade=devel || grade=stable + snapcraftctl set-version "$version" + snapcraftctl set-grade "$grade" + build-packages: [make, gcc, g++] stage-packages: [ros-foxy-ros2launch] + build-environment: + - ROS_VERSION: '2' + - ROS_DISTRO: foxy runner: plugin: dump source: snap/local/ organize: - '*': usr/bin/ - -plugs: - micro-ros-agent-shm-netplug: - interface: system-files - allow-auto-connection: true - write: - - /dev/shm + 'micro-ros-agent-daemon': usr/bin/ + 'fastdds_no_shared_memory.xml': usr/share/ apps: micro-ros-agent: - command: lib/micro_ros_agent/micro_ros_agent + command: opt/ros/snap/lib/micro_ros_agent/micro_ros_agent environment: - LD_LIBRARY_PATH: "$LD_LIBRARY_PATH:$SNAP/lib" - plugs: [network, network-bind, serial-port, micro-ros-agent-shm-netplug] - extensions: [ros2-foxy] + FASTRTPS_DEFAULT_PROFILES_FILE: ${SNAP}/usr/share/fastdds_no_shared_memory.xml + plugs: [network, network-bind, serial-port] daemon: command: usr/bin/micro-ros-agent-daemon environment: - LD_LIBRARY_PATH: "$LD_LIBRARY_PATH:$SNAP/lib" + FASTRTPS_DEFAULT_PROFILES_FILE: ${SNAP}/usr/share/fastdds_no_shared_memory.xml daemon: simple - plugs: [network, network-bind, serial-port, micro-ros-agent-shm-netplug] + plugs: [network, network-bind, serial-port]