Skip to content

uUR: build on MicroPython 1.27 while keeping pre-1.19 (MaixPy) support#3

Merged
odudex merged 1 commit into
odudex:mainfrom
kdmukAI-bot:feat/micropython-1.27-support
Jul 6, 2026
Merged

uUR: build on MicroPython 1.27 while keeping pre-1.19 (MaixPy) support#3
odudex merged 1 commit into
odudex:mainfrom
kdmukAI-bot:feat/micropython-1.27-support

Conversation

@kdmukAI-bot

Copy link
Copy Markdown
Contributor

The uUR binding uses the pre-v1.19 MicroPython C API, so it does not compile on
MicroPython >= 1.19 (e.g. 1.27). This makes it build on both the modern and the
pre-1.19 (MaixPy-era, used by Krux) API in a single file.

MicroPython's v1.19 "type slots" refactor changed three things the binding uses:
type definitions (flat struct -> MP_DEFINE_CONST_OBJ_TYPE), finaliser
allocation (m_new_obj_with_finaliser -> mp_obj_malloc_with_finaliser), and
MP_REGISTER_MODULE arity (3 args -> 2).

uUR.c:

  • MP_ERROR_TEXT: #ifndef fallback to the raw string on builds that predate it.
  • Finaliser: define mp_obj_malloc_with_finaliser in terms of the legacy
    m_new_obj_with_finaliser when absent, so the call sites use one spelling.
  • Type definitions and MP_REGISTER_MODULE: #if defined(MP_DEFINE_CONST_OBJ_TYPE)
    selects modern vs legacy; the legacy branch is the existing code verbatim.
  • The unused result / expected_part_count / processed_parts_count method
    objects (these values are exposed as attributes) compile only on the legacy
    path; newer toolchains reject them under -Werror=unused-const-variable.

CMakeLists.txt (ESP-IDF component):

  • Add src/types/bip39.c, which uUR.c references but was missing from SRCS.
  • REQUIRES mbedtls only. mbedtls_compat is absent on ESP-IDF 5.5.x, and
    tests/esp-idf-smoke already requires only mbedtls.

The legacy (< v1.19) path is unchanged from the current code, so existing
consumers are unaffected.

Tested: builds on MicroPython 1.27 with ESP-IDF 5.5.x (ESP32-P4); uUR.URDecoder
decodes a multi-part crypto-psbt UR to the expected CBOR on-device. Not built
against a pre-v1.19 MicroPython — cUR's CI does not build uUR.c today (it is
clang-format checked only; the pc and esp-idf jobs build the C library). A
job compiling uUR.c as a USER_C_MODULE against a modern and a pre-v1.19
MicroPython would cover both paths.

The uUR binding uses the pre-v1.19 MicroPython C API, so it does not compile on
MicroPython >= 1.19 (e.g. 1.27). Support both the modern and the pre-1.19
(MaixPy-era, used by Krux) API in a single file.

MicroPython's v1.19 "type slots" refactor changed three things the binding uses:
type definitions (flat struct -> MP_DEFINE_CONST_OBJ_TYPE), finaliser allocation
(m_new_obj_with_finaliser -> mp_obj_malloc_with_finaliser), and MP_REGISTER_MODULE
arity (3 args -> 2).

uUR.c:
- MP_ERROR_TEXT: #ifndef fallback to the raw string on builds that predate it.
- Finaliser: define mp_obj_malloc_with_finaliser in terms of the legacy
  m_new_obj_with_finaliser when absent, so the call sites use one spelling.
- Type definitions and MP_REGISTER_MODULE: #if defined(MP_DEFINE_CONST_OBJ_TYPE)
  selects modern vs legacy; the legacy branch is the existing code verbatim.
- The unused result / expected_part_count / processed_parts_count method objects
  (these values are exposed as attributes) compile only on the legacy path;
  newer toolchains reject them under -Werror=unused-const-variable.

CMakeLists.txt (ESP-IDF component):
- Add src/types/bip39.c, which uUR.c references but was missing from SRCS.
- REQUIRES mbedtls only; mbedtls_compat is absent on ESP-IDF 5.5.x, and
  tests/esp-idf-smoke already requires only mbedtls.

The legacy (< v1.19) path is unchanged from the current code. Verified building
on MicroPython 1.27 / ESP-IDF 5.5.x (ESP32-P4); uUR.URDecoder decodes a
multi-part crypto-psbt UR to the expected CBOR on-device.

Co-Authored-By: kdmukai <934746+kdmukai@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@odudex odudex merged commit 4ecccea into odudex:main Jul 6, 2026
2 of 3 checks passed
@kdmukAI-bot kdmukAI-bot deleted the feat/micropython-1.27-support branch July 7, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants