-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
py,tools: Add c_module() manifest function for user C modules #18229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Code size report: |
|
This is an aggressively sensible change, and as much as I'm bought into the spaghetti of CMake tooling I've built to handle C modules... doing it this way makes so, so much more sense. 👍 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18229 +/- ##
===========================================
- Coverage 98.39% 0 -98.40%
===========================================
Files 171 0 -171
Lines 22290 0 -22290
===========================================
- Hits 21933 0 -21933
+ Misses 357 0 -357 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add c_module() function to manifest files to specify user C modules
directly in manifests instead of via USER_C_MODULES make/cmake variable.
This provides better integration with the manifest system and allows
C modules to be specified alongside frozen Python modules in a single
configuration file.
The c_module() function accepts a path to a directory containing a
micropython.cmake file that defines the C module.
Example usage in manifest.py:
c_module("$(MPY_DIR)/examples/usercmodule/cexample")
Signed-off-by: Andrew Leech <[email protected]>
Update py.mk and py.cmake to extract c_module() paths from manifests during the build process. When MICROPY_FROZEN_MANIFEST is set, the build system now runs makemanifest.py with --list-c-modules to extract C module paths from the manifest, then includes them in the build alongside any modules specified via USER_C_MODULES. Update usermod.cmake to process manifest-specified C modules through the same code path as USER_C_MODULES, ensuring consistent handling. Signed-off-by: Andrew Leech <[email protected]>
Add documentation for the new c_module() function that allows specifying user C modules directly in manifest files. Includes usage examples and explanation of how it integrates with the manifest system. Signed-off-by: Andrew Leech <[email protected]>
Replace USER_C_MODULES makefile variable usage with c_module() calls in the coverage variant manifest. This demonstrates the new manifest approach and ensures the coverage build tests c_module() functionality. The build produces identical binaries to the USER_C_MODULES approach. Signed-off-by: Andrew Leech <[email protected]>
Replace USER_C_MODULES usage with c_module() calls in the ESP32 manifest_test.py. This tests the c_module() functionality on ESP32 during CI builds. Signed-off-by: Andrew Leech <[email protected]>
Fix CMakeLists.txt to restore MICROPY_USER_FROZEN_MANIFEST before including usermod.cmake. Previously, when FROZEN_MANIFEST was specified on the command line, it was saved but then overwritten by the board's mpconfigboard.cmake. The restoration didn't occur until after usermod.cmake was included, causing c_module() calls in manifest overrides to be silently ignored. Add manifest_test.py for CI testing that replicates RPI_PICO_W configuration plus c_module() calls. With the CMakeLists.txt fix, this produces identical binaries to having c_module() in the board manifest. Signed-off-by: Andrew Leech <[email protected]>
Add manifest_test.py with c_module() calls for testing during CI builds. This verifies c_module() functionality works correctly on the STM32 port. Signed-off-by: Andrew Leech <[email protected]>
Update CI scripts to test c_module() functionality: - Remove USER_C_MODULES from ESP32 and RP2 CI builds (now using c_module() in manifest_test.py) - Add ci_stm32_build_cmod function to test c_module() on STM32 - Update RP2 CI to use FROZEN_MANIFEST with manifest_test.py This ensures c_module() is tested across multiple ports during CI. Signed-off-by: Andrew Leech <[email protected]>
adb0ccf to
d90efde
Compare
Summary
This PR adds a
c_module()function to the manifest system, allowing projects to specify user C module directories directly in manifest.py files rather than requiringUSER_C_MODULESon the command line.Previously, including user C modules required setting
USER_C_MODULESon the make/cmake command line, which made it difficult for projects to have consistent builds without modifying Makefiles or requiring specific build commands. The newc_module()function allows C modules to be specified alongside frozen Python modules in the manifest, providing a single location for all firmware dependencies.Example usage:
The implementation adds early manifest processing during build configuration (before C compilation) in both Make (py/py.mk) and CMake (py/usermod.cmake) build systems. C module paths are extracted via
makemanifest.py --list-c-modulesand appended to the existingUSER_C_MODULESlist, maintaining full backward compatibility.Key features:
c_module()calls supported for multiple modules$(VAR)path substitution as other manifest functionsUSER_C_MODULEScontinues to work unchangedTesting
Binary equivalence testing:
Verified that binaries built with
c_module()are equivalent to those built withUSER_C_MODULES:ports/rp2/CMakeLists.txtwhere FROZEN_MANIFEST overrides were not restoring before usermod.cmake inclusion, causing c_module() calls to be silently ignoredBuild system testing:
Error handling:
CI coverage:
Trade-offs and Alternatives
No negative trade-offs identified:
Implementation notes:
py/manifest.mkpy/py.mk(early C module extraction) andpy/mkrules.mk(frozen content generation) include the same fileAlternative considered: Extending
USER_C_MODULESto support manifest file input was rejected as it would conflate two different specification methods and complicate the implementation.Behavioral difference:
USER_C_MODULESscans a directory and includes all modules withmicropython.mk/micropython.cmakefiles, whilec_module()requires explicit listing of each module directory. This is intentional -c_module()provides explicit control over which modules are included, preventing unintended module inclusion from directory scans.