Meson Project Support

Hi all,

For a while now, I have worked on supporting the Meson build system in colcon and bloom. The colcon-meson extension was available for some time now, but the bloom support was only merged recently, and I think now is a good time to announce this to gain some broader usage.

For a long time, the “ROS build and distribution system” (i.e. catkin, colcon, bloom, ament macros, …) only supported CMake projects. Meson is a relative new build system and there are multiple reasons why projects use Meson. Some claim improved performance over the default CMake/Make combination (A simple comparison) and some just prefer the Python-like syntax over CMake. I found Meson to perform better for frequent rebuilds of projects where many targets do not change. I also spent a fair amount of time figuring out the correct import/export of CMake targets and their properties and dependencies, and found this to be much easier in Meson.

I added Meson support to colcon and bloom in order to develop and use third-party Meson projects directly in a colcon workspace without the need for a CMake wrapper around the Meson project. Note that the support only covers “plain” Meson projects (build type meson) and does not include ament macros, i.e. there is no ament_meson support yet.

colcon

The colcon extension (colcon-meson) is available on PyPI (pip install colcon-meson) and as Debian/RPM package (sudo apt install python3-colcon-meson / sudo dnf install python3-colcon-meson). Once installed, you can check out a Meson project, e.g. libcamera, in your workspace and colcon list should then identify this as

libcamera	src/libcamera	(meson)

This also works with a package.xml (identified as type ros.meson) and you can provide additional arguments to Meson via --meson-args in the same way as you would via --cmake-args for CMake packages. From thereon, you can use this like any other package in the colcon workspace, including .meta files:

names:
  libcamera:
    meson-args:
    - --warnlevel=2
    - --werror
    - --buildtype=debug
    - --auto-features=disabled
    - -Dcam=enabled

bloom

Meson support is now part of the bloom upstream repo. Hence, you only have to install a recently new bloom version:

pip install git+https://github.com/ros-infrastructure/bloom.git

and can then use the standard bloom CLI commands to generate (bloom-generate) and release (bloom-release) Debian or RPM packages. To have bloom select the correct package templates, you have to switch the build type to meson:

<package format="3">
  <buildtool_depend>meson</buildtool_depend>
  <export>
    <build_type>meson</build_type>
  </export>
</package>

I am frequently using colcon-meson to build libcamera in my workspace and I have used the bloom support a few times to release libcamera to the ROS repos (ros-jazzy-libcamera, ros-rolling-libcamera). With this, I am quite confident in its basic functionality to handle pure Meson projects.

As already mentioned, this does not include support for ament_meson or anything that would replicate the functionality of the ament CMake macros in Meson. I would like to see a wider adaption of Meson in ROS and hope this sparked your interest in Meson and maybe motivated you to start working on ament_meson :slight_smile:

15 Likes

This is a really exciting development!

Thank you @christian for your patience as this contribution sat ready. The change has been merged as mentioned and is now released in bloom 0.13.0 available from the ROS Ubuntu / Debian repositories and PyPI with EPEL for RHEL soon to follow I’m sure.

1 Like