From e0d9510769d595af27c34fab03fc49d6e10c126f Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Wed, 3 Jul 2024 16:18:44 +0100 Subject: [PATCH] Move nano specs hack into our module cmake files. We've been maintaining a downstream patch to disable C++ exception handling, which gives us some headroom before our builds get too big and overwrite themselves at runtime. Forgetting to apply this patch is a constant source of debugging frustration. It turns out it can just be added to our USER_C_MODULES cmake files instead, where it will implicitly be included when building against our modules. --- .github/workflows/micropython.yml | 6 ------ ci/micropython.sh | 6 ------ micropython/micropython_nano_specs.patch | 21 ------------------- .../modules/micropython-cosmic_unicorn.cmake | 3 +++ .../micropython-disable-exceptions.cmake | 9 ++++++++ micropython/modules/micropython-enviro.cmake | 5 ++++- .../micropython-galactic_unicorn.cmake | 3 +++ .../modules/micropython-inky_frame.cmake | 3 +++ micropython/modules/micropython-pico.cmake | 3 +++ .../modules/micropython-pico_usb.cmake | 3 +++ .../modules/micropython-picolipo_16mb.cmake | 3 +++ .../modules/micropython-picolipo_4mb.cmake | 3 +++ micropython/modules/micropython-picow.cmake | 3 +++ .../modules/micropython-stellar_unicorn.cmake | 3 +++ .../modules/micropython-tiny2040_8mb.cmake | 3 +++ .../modules/micropython-tufty2040.cmake | 5 ++++- 16 files changed, 47 insertions(+), 35 deletions(-) delete mode 100644 micropython/micropython_nano_specs.patch create mode 100644 micropython/modules/micropython-disable-exceptions.cmake diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index 070d5fb5..24ed01e3 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -95,12 +95,6 @@ jobs: source $BUILD_TOOLS micropython_build_mpy_cross - - name: "HACK: CMakeLists.txt Disable C++ Exceptions Patch" - shell: bash - run: | - source $BUILD_TOOLS - hack_patch_micropython_disable_exceptions - - name: "HACK: Pico SDK Patch" shell: bash run: | diff --git a/ci/micropython.sh b/ci/micropython.sh index 787e2929..5df10461 100644 --- a/ci/micropython.sh +++ b/ci/micropython.sh @@ -44,12 +44,6 @@ function micropython_version { echo "MICROPY_GIT_HASH=$MICROPYTHON_VERSION-$TAG_OR_SHA" >> $GITHUB_ENV } -function hack_patch_micropython_disable_exceptions { - cd micropython - git apply $PIMORONI_PICO_DIR/micropython/micropython_nano_specs.patch - cd ../ -} - function hack_patch_pico_sdk { # pico-sdk-patch.sh will apply the patch if it exists cd micropython diff --git a/micropython/micropython_nano_specs.patch b/micropython/micropython_nano_specs.patch deleted file mode 100644 index 5ae938b3..00000000 --- a/micropython/micropython_nano_specs.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt -index fcc435b7b..efabcb3a3 100644 ---- a/ports/rp2/CMakeLists.txt -+++ b/ports/rp2/CMakeLists.txt -@@ -464,6 +464,16 @@ set_source_files_properties( - COMPILE_OPTIONS "-O2" - ) - -+# 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 $<$: -+ -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 - ${PICO_SDK_PATH}/src/rp2_common/pico_float/float_math.c diff --git a/micropython/modules/micropython-cosmic_unicorn.cmake b/micropython/modules/micropython-cosmic_unicorn.cmake index ec4d72ea..c14af9dd 100644 --- a/micropython/modules/micropython-cosmic_unicorn.cmake +++ b/micropython/modules/micropython-cosmic_unicorn.cmake @@ -39,3 +39,6 @@ include(modules_py/modules_py) # C++ Magic Memory include(cppmem/micropython) + +# Disable build-busting C++ exceptions +include(micropython-disable-exceptions) diff --git a/micropython/modules/micropython-disable-exceptions.cmake b/micropython/modules/micropython-disable-exceptions.cmake new file mode 100644 index 00000000..e8b1082c --- /dev/null +++ b/micropython/modules/micropython-disable-exceptions.cmake @@ -0,0 +1,9 @@ +# 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 $<$: + -fno-exceptions + -fno-unwind-tables + -fno-rtti + -fno-use-cxa-atexit +>) +target_link_options(usermod INTERFACE -specs=nano.specs) diff --git a/micropython/modules/micropython-enviro.cmake b/micropython/modules/micropython-enviro.cmake index cd5f00c6..d305caf7 100644 --- a/micropython/modules/micropython-enviro.cmake +++ b/micropython/modules/micropython-enviro.cmake @@ -47,4 +47,7 @@ include(motor/micropython) include(modules_py/modules_py) # C++ Magic Memory -include(cppmem/micropython) \ No newline at end of file +include(cppmem/micropython) + +# Disable build-busting C++ exceptions +include(micropython-disable-exceptions) \ No newline at end of file diff --git a/micropython/modules/micropython-galactic_unicorn.cmake b/micropython/modules/micropython-galactic_unicorn.cmake index 6f0a8368..15bbfcfa 100644 --- a/micropython/modules/micropython-galactic_unicorn.cmake +++ b/micropython/modules/micropython-galactic_unicorn.cmake @@ -39,3 +39,6 @@ include(modules_py/modules_py) # C++ Magic Memory include(cppmem/micropython) + +# Disable build-busting C++ exceptions +include(micropython-disable-exceptions) diff --git a/micropython/modules/micropython-inky_frame.cmake b/micropython/modules/micropython-inky_frame.cmake index c78424a9..6cd21038 100644 --- a/micropython/modules/micropython-inky_frame.cmake +++ b/micropython/modules/micropython-inky_frame.cmake @@ -50,3 +50,6 @@ copy_module(inky_frame.py) # C++ Magic Memory include(cppmem/micropython) + +# Disable build-busting C++ exceptions +include(micropython-disable-exceptions) diff --git a/micropython/modules/micropython-pico.cmake b/micropython/modules/micropython-pico.cmake index 60fad7c8..bae9f9c5 100644 --- a/micropython/modules/micropython-pico.cmake +++ b/micropython/modules/micropython-pico.cmake @@ -12,3 +12,6 @@ include(pico_wireless/micropython) # C++ Magic Memory include(cppmem/micropython) + +# Disable build-busting C++ exceptions +include(micropython-disable-exceptions) \ No newline at end of file diff --git a/micropython/modules/micropython-pico_usb.cmake b/micropython/modules/micropython-pico_usb.cmake index 60fad7c8..011b5498 100644 --- a/micropython/modules/micropython-pico_usb.cmake +++ b/micropython/modules/micropython-pico_usb.cmake @@ -12,3 +12,6 @@ include(pico_wireless/micropython) # C++ Magic Memory include(cppmem/micropython) + +# Disable build-busting C++ exceptions +include(micropython-disable-exceptions) diff --git a/micropython/modules/micropython-picolipo_16mb.cmake b/micropython/modules/micropython-picolipo_16mb.cmake index 94ed6a2b..8b6acbf7 100644 --- a/micropython/modules/micropython-picolipo_16mb.cmake +++ b/micropython/modules/micropython-picolipo_16mb.cmake @@ -14,3 +14,6 @@ enable_ulab() # C++ Magic Memory include(cppmem/micropython) + +# Disable build-busting C++ exceptions +include(micropython-disable-exceptions) diff --git a/micropython/modules/micropython-picolipo_4mb.cmake b/micropython/modules/micropython-picolipo_4mb.cmake index 94ed6a2b..8b6acbf7 100644 --- a/micropython/modules/micropython-picolipo_4mb.cmake +++ b/micropython/modules/micropython-picolipo_4mb.cmake @@ -14,3 +14,6 @@ enable_ulab() # C++ Magic Memory include(cppmem/micropython) + +# Disable build-busting C++ exceptions +include(micropython-disable-exceptions) diff --git a/micropython/modules/micropython-picow.cmake b/micropython/modules/micropython-picow.cmake index bb5b677f..d4cb4fb9 100644 --- a/micropython/modules/micropython-picow.cmake +++ b/micropython/modules/micropython-picow.cmake @@ -11,3 +11,6 @@ include(micropython-common) # C++ Magic Memory include(cppmem/micropython) + +# Disable build-busting C++ exceptions +include(micropython-disable-exceptions) diff --git a/micropython/modules/micropython-stellar_unicorn.cmake b/micropython/modules/micropython-stellar_unicorn.cmake index 913063db..d44fb45d 100644 --- a/micropython/modules/micropython-stellar_unicorn.cmake +++ b/micropython/modules/micropython-stellar_unicorn.cmake @@ -39,3 +39,6 @@ include(modules_py/modules_py) # C++ Magic Memory include(cppmem/micropython) + +# Disable build-busting C++ exceptions +include(micropython-disable-exceptions) diff --git a/micropython/modules/micropython-tiny2040_8mb.cmake b/micropython/modules/micropython-tiny2040_8mb.cmake index bb5b677f..d4cb4fb9 100644 --- a/micropython/modules/micropython-tiny2040_8mb.cmake +++ b/micropython/modules/micropython-tiny2040_8mb.cmake @@ -11,3 +11,6 @@ include(micropython-common) # C++ Magic Memory include(cppmem/micropython) + +# Disable build-busting C++ exceptions +include(micropython-disable-exceptions) diff --git a/micropython/modules/micropython-tufty2040.cmake b/micropython/modules/micropython-tufty2040.cmake index 11f28bc0..50243796 100644 --- a/micropython/modules/micropython-tufty2040.cmake +++ b/micropython/modules/micropython-tufty2040.cmake @@ -44,4 +44,7 @@ enable_ulab() include(modules_py/modules_py) # C++ Magic Memory -include(cppmem/micropython) \ No newline at end of file +include(cppmem/micropython) + +# Disable build-busting C++ exceptions +include(micropython-disable-exceptions) \ No newline at end of file