Skip to content

Conversation

@dmachinewhisperer
Copy link

Summary

This commit introduces a new CMake option MICROPY_COMPONENT_BUILD that allows excluding main.c from the build when MicroPython is integrated as an ESP-IDF component in an external project.

When MicroPython is used as a component, the host application typically provides its own app_main() and mp_task() functions, leading to multiple definition errors at link time.

The option defaults to OFF, preserving existing behavior for all
standard MicroPython builds.

Example usage in an external ESP-IDF project:
set(MICROPY_COMPONENT_BUILD ON)

Testing

I compiled the esp32 port for all supported targets out and in tree and the builds completed cleanly.

@github-actions
Copy link

github-actions bot commented Jan 16, 2026

Code size report:

Reference:  tests/float/complex1.py: Fix CPython 3.14 deprecation. [b14d129]
Comparison: esp32: Allow excluding main.c for component builds. [merge of 18ba043]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

This commit introduces a new CMake option MICROPY_COMPONENT_BUILD that
allows excluding main.c from the build when MicroPython is integrated
as an ESP-IDF component in an external project.

When MicroPython is used as a component, the host application typically
provides its own app_main() and mp_task() functions, leading to multiple
definition errors at link time.

This option allows out-of-tree builds to completely exclude main.c when
the component integration pattern is used, where the host application
manages MicroPython initialization directly.

The option defaults to OFF, preserving existing behavior for all
standard MicroPython builds.

Example usage in an external project:
  set(MICROPY_COMPONENT_BUILD ON)

Signed-off-by: Asogwa Emmanuel <asogwaemmanuel36@gmail.com>
@dmachinewhisperer dmachinewhisperer force-pushed the esp32-component-exclude-main-c branch from c78f700 to 18ba043 Compare January 16, 2026 15:19
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