Robotics - ROS2 Concon Mixins

Posted by Rico's Nerd Cluster on November 30, 2024

Introduction

Colcon Mixins can be used to apply a group of arguments under onw name. Example:

1
colcon build --mixin debug clang

This might apply a group of flags related to debug builds, such as:

1
--cmake-args -DCMAKE_BUILD_TYPE=Debug
  • Note: mixins are applied in the order listed. If two mixins set the same option, the later one can override the earlier one.

To download:

1
sudo apt install python3-colcon-mixin

How To Use Mixins

  1. Define yaml file for mixins:

    • File structure:

      1
      2
      3
      4
      
        my_mixins/
        ├── index.yaml
        ├── debug.yaml
        └── clang.yaml
      
    • index.yaml

      1
      2
      3
      
        build:
        debug: debug.yaml
        clang: clang.yaml
      
    • debug.yaml:

      1
      2
      3
      
        arguments:
            cmake-args:
                - -DCMAKE_BUILD_TYPE=Debug
      
    • clang.yaml

      1
      2
      3
      4
      
        arguments:
            cmake-args:
                - -DCMAKE_C_COMPILER=clang
                - -DCMAKE_CXX_COMPILER=clang++
      
  2. Register the mixins:

1
2
colcon mixin add my_mixins /path/to/my_mixins/index.yaml
colcon mixin update
  1. To check:
1
colcon mixin show
  1. Use mixins:
1
colcon build --mixin debug clang