From e8a3ee034293cbb0baf422a97272383e9ab26337 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 3 Mar 2026 15:19:49 +1100 Subject: [PATCH] esp32/esp32_common.cmake: Add missing C flags to user C module sources. On the esp32 port when adding a user C module, the source code for the user C module was being compiled without certain C flags. Notably the optimisation flag was missing. This commit fixes that by explicitly adding the missing C flags to the compilation of user C modules. The missing flags were the following, which are now included when building user C modules (found by inspecting the generated CMake files when building with ulab): -ffunction-sections -fdata-sections -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=unused-but-set-variable -Wno-error=deprecated-declarations -Wextra -Wno-error=extra -Wno-unused-parameter -Wno-sign-compare -Wno-enum-conversion -gdwarf-4 -ggdb -mdisable-hardware-atomics -O2 -fmacro-prefix-map=micropython/ports/esp32=. -fmacro-prefix-map=espressif/esp-idf=/IDF -fstrict-volatile-bitfields -fno-jump-tables -fno-tree-switch-conversion See related issue #18880. Work done in collaboration with @andrewleech. Signed-off-by: Damien George --- ports/esp32/esp32_common.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/esp32/esp32_common.cmake b/ports/esp32/esp32_common.cmake index 86ea1aaf4..b71fc2437 100644 --- a/ports/esp32/esp32_common.cmake +++ b/ports/esp32/esp32_common.cmake @@ -277,6 +277,11 @@ target_compile_options(${MICROPY_TARGET} PUBLIC -Wno-missing-field-initializers ) +# User C modules don't pick up certain compile options set by the IDF, most +# importantly the optimisation level. So set them here. +idf_build_get_property(idf_compile_options COMPILE_OPTIONS) +target_compile_options(usermod INTERFACE ${idf_compile_options}) + # Additional include directories needed for private NimBLE headers. target_include_directories(${MICROPY_TARGET} PUBLIC ${IDF_PATH}/components/bt/host/nimble/nimble