From b4b36a27489dc4086b6aa04957adaa46b2740675 Mon Sep 17 00:00:00 2001 From: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> Date: Sun, 17 May 2026 18:00:06 -0400 Subject: [PATCH] fix(nuttx): unblock multi-board and protected builds (#27360) * fix(ci): wipe NuttX submodule state between boards in build_all_runner NuttX .o and lib*.a live in the shared submodule trees under platforms/nuttx/NuttX/{nuttx,apps}, not in per-board build//. NuttX's recursive make doesn't treat PX4's per-board defconfig changes as a reason to recompile, so consecutive board builds in one workspace were linking stale objects from an earlier board (e.g. stm32_spi.o from fmu-v2 linked into fmu-v4pro, which doesn't enable SPI4). Run git clean -dXf on both NuttX submodules between iterations to drop gitignored build state. This mirrors what make clean already does for submodules and preserves the incremental-build wins for single-board use. * fix(cmake): isolate kernel mm/libc objects with BINDIR=kbin mm and libs/libc compile the same sources for both the kernel and user passes in protected builds. Without separate output dirs the kernel objects clobber bin/*.o and the user-mode libmm.a/libc.a end up pulling in kernel-only symbols (nxsem_wait, g_current_regs, nx_read, nx_write, g_mmheap, ...) at link time. Matches NuttX's own tools/LibTargets.mk. --- Tools/ci/build_all_runner.sh | 9 +++++++++ platforms/nuttx/NuttX/CMakeLists.txt | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Tools/ci/build_all_runner.sh b/Tools/ci/build_all_runner.sh index a47d42dd87..132b634ebd 100755 --- a/Tools/ci/build_all_runner.sh +++ b/Tools/ci/build_all_runner.sh @@ -3,6 +3,14 @@ # Please only modify if you know what you are doing set -e +# NuttX .o/.a live in the shared submodule trees, not per-board build dirs. +# Wipe them between boards so stale objects from a prior board's defconfig +# don't get linked into the next board's elf. +clean_nuttx_state() { + git -C platforms/nuttx/NuttX/nuttx clean -dXf -q + git -C platforms/nuttx/NuttX/apps clean -dXf -q +} + targets=$1 for target in ${targets//,/ } do @@ -14,4 +22,5 @@ do build_time="$(($diff /60/60))h $(($diff /60))m $(($diff % 60))s elapsed" echo -e "\033[0;32mBuild Time: [$build_time]" echo "::endgroup::" + clean_nuttx_state done diff --git a/platforms/nuttx/NuttX/CMakeLists.txt b/platforms/nuttx/NuttX/CMakeLists.txt index 3a700ce9ff..30182a722c 100644 --- a/platforms/nuttx/NuttX/CMakeLists.txt +++ b/platforms/nuttx/NuttX/CMakeLists.txt @@ -181,8 +181,15 @@ function(add_nuttx_dir nuttx_lib nuttx_lib_dir kernel extra target) ${CMAKE_CURRENT_SOURCE_DIR}/nuttx/${nuttx_lib_dir}/*.h ) + # Route kernel pass for mm/libc to kbin/; user pass uses bin/ for the + # same sources and would otherwise overwrite the kernel objects. + set(bindir_arg) + if(${kernel} STREQUAL y AND (${nuttx_lib_dir} STREQUAL mm OR ${nuttx_lib_dir} STREQUAL libs/libc)) + set(bindir_arg BINDIR=kbin) + endif() + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/nuttx/${nuttx_lib_dir}/lib${nuttx_lib}.a - COMMAND make -C ${nuttx_lib_dir} --no-print-directory --silent ${nuttx_lib_target} TOPDIR="${NUTTX_DIR}" KERNEL=${kernel} EXTRAFLAGS=${extra} + COMMAND make -C ${nuttx_lib_dir} --no-print-directory --silent ${nuttx_lib_target} TOPDIR="${NUTTX_DIR}" KERNEL=${kernel} EXTRAFLAGS=${extra} ${bindir_arg} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NUTTX_DIR}/${nuttx_lib_dir}/lib${nuttx_lib}.a ${CMAKE_CURRENT_BINARY_DIR}/nuttx/${nuttx_lib_dir}/lib${nuttx_lib}.a DEPENDS ${nuttx_lib_files}