CI: Hack: Patch MicroPython to remove exception handling.

Force "-specs=nano.specs" on MicroPython builds and disable various stack unwinding and exception handling features for C++ modules.
This commit is contained in:
Phil Howard 2023-05-04 12:03:08 +01:00
parent b30d9ca554
commit 7951ef9668
2 changed files with 32 additions and 6 deletions

View File

@ -19,9 +19,9 @@ jobs:
uses: actions/cache@v3
with:
path: ${{runner.workspace}}
key: workspace-micropython-${{env.MICROPYTHON_VERSION}}-pico
key: workspace-micropython-${{env.MICROPYTHON_VERSION}}-nano-specs
restore-keys: |
workspace-micropython-${{env.MICROPYTHON_VERSION}}-pico
workspace-micropython-${{env.MICROPYTHON_VERSION}}-nano-specs
# Check out MicroPython
- name: Checkout MicroPython
@ -129,18 +129,24 @@ jobs:
echo "MICROPY_GIT_TAG=$MICROPYTHON_VERSION, ${{matrix.name}} ${{github.event.release.tag_name || github.sha}}" >> $GITHUB_ENV
echo "MICROPY_GIT_HASH=$MICROPYTHON_VERSION-${{github.event.release.tag_name || github.sha}}" >> $GITHUB_ENV
- name: "HACK: Clean ports/rp2/modules" # We should move to using manifest.py to include our custom modules
- name: "HACK: Clean ports/rp2/modules and ports/rp2/CMakeLists.txt"
shell: bash
working-directory: micropython/ports/rp2
run: |
rm -rf modules
git checkout modules
- name: "HACK: Revert Pico SDK Patch" # Avoid an already-patched MicroPython tree breaking our build
- name: "HACK: Revert Patches" # Avoid an already-patched MicroPython tree breaking our build
shell: bash
working-directory: micropython/lib/pico-sdk
working-directory: micropython
run: |
git checkout .
git checkout lib/pico-sdk
git checkout ports/rp2/CMakeLists.txt
- name: "HACK: CMakeLists.txt Disable C++ Exceptions Patch"
shell: bash
working-directory: micropython
run: git apply $GITHUB_WORKSPACE/pimoroni-pico-${{ github.sha }}/micropython/micropython_nano_specs.patch
- name: "HACK: Pico SDK Patch"
if: matrix.patch == true

View File

@ -0,0 +1,20 @@
diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt
index 094031c6852a..5f268414c08f 100644
--- a/ports/rp2/CMakeLists.txt
+++ b/ports/rp2/CMakeLists.txt
@@ -374,6 +374,15 @@ target_compile_options(${MICROPY_TARGET} PRIVATE
target_link_options(${MICROPY_TARGET} PRIVATE
-Wl,--defsym=__micropy_c_heap_size__=${MICROPY_C_HEAP_SIZE}
)
+# Do not include stack unwinding & exception handling for C++ user modules
+target_compile_definitions(usermod INTERFACE PICO_CXX_ENABLE_EXCEPTIONS=0)
+target_compile_options(usermod INTERFACE $<$<COMPILE_LANGUAGE:CXX>:
+ -fno-exceptions
+ -fno-unwind-tables
+ -fno-rtti
+ -fno-use-cxa-atexit
+>)
+target_link_options(usermod INTERFACE -specs=nano.specs)
set_source_files_properties(
${PICO_SDK_PATH}/src/rp2_common/pico_double/double_math.c