Skip to content

apps/system/microros: add libmicroros.a colcon cross-build orchestration#3498

Open
arjav1528 wants to merge 9 commits into
apache:masterfrom
arjav1528:micro-ros-build-orch
Open

apps/system/microros: add libmicroros.a colcon cross-build orchestration#3498
arjav1528 wants to merge 9 commits into
apache:masterfrom
arjav1528:micro-ros-build-orch

Conversation

@arjav1528
Copy link
Copy Markdown
Contributor

@arjav1528 arjav1528 commented May 23, 2026

Summary

This PR implements an automated build pipeline that fetches all upstream micro-ROS jazzy packages, cross-compiles them with colcon and a NuttX CMake toolchain, and merges the resulting static libraries into a single libmicroros.a ready for linking into a NuttX image.

Impact

  • Users: Applications that enable CONFIG_SYSTEM_MICROROS automatically
    get libmicroros.a linked in and all micro-ROS headers available under
    system/microros/include/. No manual build steps are required.
  • Build: make context in the apps tree triggers the colcon build the first
    time; subsequent builds are incremental. Full build time on a 2-core machine
    is approximately 4–5 minutes. make distclean fully removes all downloaded
    sources.
  • Disk: The colcon build requires approximately 1.5 GB of temporary build
    space; only libmicroros.a (~13–80 MB depending on included message types)
    and the headers are retained after the build.
  • Dependencies: Host requires colcon-common-extensions, cmake ≥ 3.16,
    Python 3, and a C/C++ cross-compiler matching $(CROSSDEV).
  • Compatibility: No existing app or config is modified. The feature is
    entirely gated behind CONFIG_SYSTEM_MICROROS.

Testing

Host: Ubuntu 22.04 (EC2 t3.medium), gcc 13, cmake 3.28, colcon 0.3

Target: stm32f4discovery:nsh (ARM Cortex-M4, arm-none-eabi-gcc 14.2)
— library produced but not yet run on hardware due to availability issues.

Verified with make context end-to-end:

$ cd ~/nuttx-apps/system/microros && rm -f micro_ros_lib/toolchain.cmake \
    micro_ros_lib/colcon.meta libmicroros.a && rm -rf include && \
  make context APPDIR=~/nuttx-apps TOPDIR=~/nuttx CC=gcc CXX=g++ \
    CONFIG_MICROROS_DISTRO='"jazzy"' CONFIG_MICROROS_MAX_NODES=8 \
    CONFIG_MICROROS_MAX_PUBLISHERS=16 CONFIG_MICROROS_MAX_SUBSCRIPTIONS=16 \
    CONFIG_MICROROS_MAX_SERVICES=4 CONFIG_MICROROS_MAX_CLIENTS=4 \
    CONFIG_ARCH_ARM=y 2>&1 | tail -3
Summary: 72 packages finished [4min 27s]

$ ls -lh ~/nuttx-apps/system/microros/libmicroros.a
-rw-rw-r-- 1 ubuntu ubuntu 13M May 23 16:47 libmicroros.a

$ ar t ~/nuttx-apps/system/microros/libmicroros.a | wc -l
1492

$ ls ~/nuttx-apps/system/microros/include/ | wc -l
44

phase3.log

make clean verified removes libmicroros.a, include/, toolchain.cmake,
and colcon.meta.

arjav1528 added 2 commits May 23, 2026 05:00
Add micro_ros_lib/ subdirectory with a .keep sentinel so the directory
is tracked by git before any generated build artifacts appear.  All
colcon/fetch outputs land here and are gitignored by the parent .gitignore.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
Add a colcon.meta.in template that is substituted at build time with
Kconfig values.  Key settings:
  - Custom transport only (UCLIENT_PROFILE_CUSTOM_TRANSPORT=ON,
    UCLIENT_PROFILE_STREAM_FRAMING=ON) -- actual UDP/serial callbacks
    are wired in Phase 4.
  - RCL_MICROROS=ON (Jazzy/Kilted renamed flag replacing the old
    RCL_COMMAND_LINE_ENABLED/RCL_LOGGING_ENABLED pair).
  - RCUTILS_NO_FILESYSTEM=OFF -- NuttX provides POSIX filesystem.
  - Resource limits use @MAX_NODES@/@MAX_PUBLISHERS@ etc. placeholders
    substituted from CONFIG_MICROROS_MAX_* Kconfig values.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
Add toolchain.cmake.in and include_override/assert.h for the colcon
cross-build.  Key differences from the old robertobucher port:
  - Drop -DCLOCK_MONOTONIC=0: NuttX defines CLOCK_MONOTONIC=1 and
    the override broke nanosleep() on newer kernels.
  - CMAKE_SYSTEM_PROCESSOR is a placeholder substituted per-arch.
  - include_override/assert.h works around the rosidl NDEBUG issue
    (ros2/rosidl#739).

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
@arjav1528 arjav1528 force-pushed the micro-ros-build-orch branch from 9d364bc to 832bb10 Compare May 23, 2026 21:15
+++ b/rcutils/src/strcasecmp.c
@@ -17,6 +17,9 @@ extern "C"
#include <errno.h>
#include <string.h>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we align with Linux?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhhh, my bad
Changed the guard to #ifdef NuttX so the include is scoped to NuttX only coz Linux/glibc already exposes strcasecmp through <string.h>

@xiaoxiang781216
Copy link
Copy Markdown
Contributor

@arjav1528 please squash the intermediate patch

arjav1528 added 6 commits May 24, 2026 11:10
Replace the Directory.mk stub with a full Application.mk-based Makefile
that builds libmicroros.a from upstream micro-ROS sources via colcon.
Build pipeline (six steps, each a Make target):

  1. micro_ros_dev/install  -- clone + build ament/colcon host tools
  2. micro_ros_src/src      -- git clone all Jazzy micro-ROS packages
                               with --depth 1; apply DIR-typedef guard
                               patch; mark unused packages COLCON_IGNORE
  3. toolchain.cmake        -- sed-substitute CC/CXX/CFLAGS into template
  4. colcon.meta            -- sed-substitute Kconfig resource limits
  5. micro_ros_src/install  -- colcon cross-build (merge-install,
                               packages-ignore-regex=.*_cpp)
  6. libmicroros.a          -- ar-merge all install/lib/*.a into one
                               archive; copy include/ tree

clean:: removes generated files; distclean:: removes all fetched dirs.
Signed-off-by: Arjav Patel <arjav1528@gmail.com>
When CONFIG_SYSTEM_MICROROS=y, add the prebuilt libmicroros.a to LDLIBS
and the colcon-installed include/ tree to CFLAGS/CXXFLAGS so that any
application in nuttx-apps can include micro-ROS headers and link against
the library without extra flags.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
NuttX defines DIR as a struct type in dirent.h.  The rcutils filesystem
source has a bare typedef int DIR that triggers a redefinition error when
NuttX system headers are on the include path.  Guard it with #ifndef DIR
so the typedef is skipped when the type is already defined.

Applied automatically during the micro_ros_src/src fetch step with
  patch -p1 --forward --ignore-whitespace ... || true
so the build is idempotent if the upstream ever merges a fix.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
Mirror the Makefile build pipeline into CMakeLists.txt using
ExternalProject_Add so that CMake-based NuttX builds (cmake --build)
can also produce libmicroros.a.  The external project delegates to the
existing Makefile targets, then exposes the result via an IMPORTED
STATIC library target with correct INTERFACE_INCLUDE_DIRECTORIES.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
Add -D__NuttX__ to CMAKE_C_FLAGS_INIT and CMAKE_CXX_FLAGS_INIT in
toolchain.cmake.in so that all cross-compiled micro-ROS packages see the
NuttX target macro.  Without this, rcutils/src/process.c follows the
__linux__ branch and references program_invocation_name, a glibc-only
extension absent from the NuttX C library.

Pair with 0002-rcutils-process-nuttx-compat.patch which additionally
guards the linux branch with !defined(__NuttX__), ensuring the embedded
fallback path is taken on NuttX even if the host compiler defines any
linux-flavoured macros.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
POSIX specifies strcasecmp/strncasecmp in <strings.h>, not <string.h>.
On NuttX (and other strict POSIX environments) rcutils/src/strcasecmp.c
only includes <string.h>, causing an implicit-declaration error for
strcasecmp when cross-compiling.

Patch 0003 adds #include <strings.h> guarded by !_WIN32, matching the
existing Windows/POSIX split in the file.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
@arjav1528 arjav1528 force-pushed the micro-ros-build-orch branch from 832bb10 to 6d0d79e Compare May 24, 2026 05:41
@arjav1528 arjav1528 requested a review from xiaoxiang781216 May 24, 2026 05:54
@arjav1528
Copy link
Copy Markdown
Contributor Author

@arjav1528 please squash the intermediate patch

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants