From 6cf51a3b6716145706487d4e45c620b97127a8d9 Mon Sep 17 00:00:00 2001 From: Matt Spencer Date: Sat, 18 Jul 2026 10:23:36 +0000 Subject: [PATCH] Fix livox driver build Also add caching to the apt-get installs --- .devcontainer/jazzy/Dockerfile.jazzy | 24 ++++++++++++++---------- Dockerfile | 22 ++++++++++++++++------ patches/livox_ros_driver2.patch | 27 +++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 16 deletions(-) diff --git a/.devcontainer/jazzy/Dockerfile.jazzy b/.devcontainer/jazzy/Dockerfile.jazzy index 6a7827e..d5734ee 100644 --- a/.devcontainer/jazzy/Dockerfile.jazzy +++ b/.devcontainer/jazzy/Dockerfile.jazzy @@ -19,13 +19,15 @@ RUN groupadd --gid $USER_GID $USERNAME \ && rm -rf /var/lib/apt/lists/* # Make sure the base image is completely up to date -RUN apt-get update \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-cache-${TARGETARCH} \ + apt-get update \ && apt-get upgrade -y \ && rm -rf /var/lib/apt/lists/* # C++ development tools -RUN apt-get update \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-cache-${TARGETARCH} \ + apt-get update \ && apt-get install -y --no-install-recommends \ build-essential \ cmake \ @@ -37,7 +39,8 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* # Python development tools -RUN apt-get update \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-cache-${TARGETARCH} \ + apt-get update \ && apt-get install -y --no-install-recommends \ python3-pip \ python3-dev \ @@ -52,17 +55,18 @@ RUN apt-get update \ # NOTE: There should be a check in your CI that this file is up to date. # Something like: # ./scripts/freeze-rosdep.sh && git diff --exit-code rosdep-packages.txt -COPY rosdep-packages.txt /tmp/rosdep-packages.txt +# COPY rosdep-packages.txt /tmp/rosdep-packages.txt # The --mount=type=cache option caches the apt packages with buildkit # The id-apt-cache-${TARGETARCH} option allows for separate caches for different architectures # this enables parallel builds for different architectures without cache conflicts -RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-cache-${TARGETARCH} \ - rm -f /etc/apt/apt.conf.d/docker-clean \ - && apt-get update \ - && xargs -r -a /tmp/rosdep-packages.txt apt-get install -y --no-install-recommends \ - && rm -rf /var/lib/apt/lists/* +# RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-cache-${TARGETARCH} \ +# rm -f /etc/apt/apt.conf.d/docker-clean \ +# && apt-get update \ +# && xargs -r -a /tmp/rosdep-packages.txt apt-get install -y --no-install-recommends \ +# && rm -rf /var/lib/apt/lists/* -RUN apt-get update \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-cache-${TARGETARCH} \ + apt-get update \ && apt-get install -y --no-install-recommends \ ros-${ROS_DISTRO}-rmw-cyclonedds-cpp \ && rm -rf /var/lib/apt/lists/* diff --git a/Dockerfile b/Dockerfile index 74233e8..661bc5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,19 +18,31 @@ RUN ./patches/apply_patches.sh # NOTE: There should be a check in your CI that this file is up to date. # Something like: # ./scripts/freeze-rosdep.sh && git diff --exit-code rosdep-packages.txt -COPY rosdep-packages.txt /tmp/rosdep-packages.txt +# COPY rosdep-packages.txt /tmp/rosdep-packages.txt # The --mount=type=cache option caches the apt packages with buildkit # The id-apt-cache-${TARGETARCH} option allows for separate caches for different architectures # this enables parallel builds for different architectures without cache conflicts +# RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-cache-${TARGETARCH} \ +# rm -f /etc/apt/apt.conf.d/docker-clean \ +# && apt-get update \ +# && xargs -r -a /tmp/rosdep-packages.txt apt-get install -y --no-install-recommends \ +# && rm -rf /var/lib/apt/lists/* + +# Make sure the base image is completely up to date +# ros:jazzy ships /etc/apt/apt.conf.d/docker-clean which purges downloaded .debs; +# remove it so the --mount=type=cache on /var/cache/apt actually retains archives. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-cache-${TARGETARCH} \ rm -f /etc/apt/apt.conf.d/docker-clean \ && apt-get update \ - && xargs -r -a /tmp/rosdep-packages.txt apt-get install -y --no-install-recommends \ + && apt-get upgrade -y \ && rm -rf /var/lib/apt/lists/* + # Install dependencies with rosdep # This will catch anything that wasn't installed via .deb's from the frozen rosdep manifest. -RUN apt-get update && \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-cache-${TARGETARCH} \ + rm -f /etc/apt/apt.conf.d/docker-clean && \ + apt-get update && \ rosdep update && \ rosdep install --from-paths src --ignore-src -r -y && \ rm -rf /var/lib/apt/lists/* @@ -38,9 +50,7 @@ RUN apt-get update && \ # Build the workspace with symlink install # livox_sdk is now an ament_cmake package built by colcon (no manual /usr/local install needed). RUN . /opt/ros/jazzy/setup.sh && \ - colcon build --symlink-install \ - --cmake-args -DROS_EDITION=ROS2 -DDISTRO_ROS=jazzy - + colcon build --symlink-install # Source the overlay on container startup RUN echo "source /opt/ros/jazzy/setup.bash" >> /root/.bashrc && \ echo "source /ros2_ws/install/setup.bash" >> /root/.bashrc diff --git a/patches/livox_ros_driver2.patch b/patches/livox_ros_driver2.patch index 39e0e99..d35c2d5 100644 --- a/patches/livox_ros_driver2.patch +++ b/patches/livox_ros_driver2.patch @@ -1,3 +1,30 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 7344d08..3d531a9 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1,3 +1,9 @@ ++# Default to the ROS2 build unless ROS1 is explicitly requested, so the else() ++# (ROS2) branch below is taken when ROS_EDITION is unset or set to "ROS2". ++if(NOT ROS_EDITION) ++ set(ROS_EDITION "ROS2") ++endif() ++ + # judge which cmake codes to use + if(ROS_EDITION STREQUAL "ROS1") + +@@ -191,6 +197,12 @@ else(ROS_EDITION STREQUAL "ROS2") + cmake_minimum_required(VERSION 3.14) + project(livox_ros_driver2) + ++ # Fall back to the sourced ROS distro when -DDISTRO_ROS was not passed, so a ++ # plain `colcon build` behaves the same as the flagged Dockerfile build. ++ if(NOT DISTRO_ROS) ++ set(DISTRO_ROS "$ENV{ROS_DISTRO}") ++ endif() ++ + # Default to C99 + if(NOT CMAKE_C_STANDARD) + set(CMAKE_C_STANDARD 99) diff --git a/launch b/launch new file mode 120000 index 0000000..163fb01