ESP32 micropython port build with relative path to external user C-modules was failed
Checks
-
I agree to follow the MicroPython Code of Conduct to ensure a safe and respectful space for everyone.
-
I've searched for existing issues matching this bug, and didn't find any.
Port, board and/or hardware
esp32 port, ESP32-boards of any kind, I guess
MicroPython version
MicroPython v1.22.2-dirty on 2024-04-18; Generic ESP32 module with ESP32
Reproduction
make USER_C_MODULES=../../examples/usercmodule/micropython.cmake
Expected behaviour
Make process failed with error message like a:
modules not found in the path <specified_path>
Observed behaviour
During the build, make changed current directory and relative path to micropython.cmake file turns out to be incorrect
Additional Information
Need expand relative path of USER_C_MODULES variable, to absolute path before passed it to the ./py/usermod.cmake as described below:
In the file ./ports/esp32/Makefile , line 41:
ifdef USER_C_MODULES
CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES}
endif
change it to a:
ifdef USER_C_MODULES
CMAKE_ARGS += -DUSER_C_MODULES=$(abspath ${USER_C_MODULES})
endif
Thnx!
esp32: register user C modules with IDF component manager and handle relative usermod paths
Summary
This change adds the possibility to define usermod specific IDF manifests and improves how user-provided C modules with relative paths are handled when building the ESP32 port:
- Register user module directories with the ESP-IDF Component Manager when the user module directory contains both idf_component.yml and CMakeLists.txt and append those directories to EXTRA_COMPONENT_DIRS so the IDF can locate them correctly.
- Convert configured USER_C_MODULES entries to absolute paths and replace the original variable with those absolute paths for later CMake stages. This makes relative module paths safe and reliable across the build.
Testing
Built MicroPython locally for BOARD=ESP32_GENERIC_S3 and BOARD_VARIANT=SPIRAM_OCT with a user module passed as absolute and relative path. The build contained the needed files.
The build completed successfully.
Trade-offs and Alternatives
The code size of the main CMakeLists.txt is 20 lines longer. On the other hand, you don't need to touch the micropython code to build with custom user modules with ESP components integrated.
Also, providing relative paths to the build changes behavior. This should be documented. On the other hand, this will prevent such issues like https://github.com/micropython/micropython/issues/14352.
(Maintainer edit: Closes #14352 )