unix: keep the micropython patch applied so a submodule checkout can't break the build - #728
Open
hitechhayekian wants to merge 1 commit into
Open
unix: keep the micropython patch applied so a submodule checkout can't break the build#728hitechhayekian wants to merge 1 commit into
hitechhayekian wants to merge 1 commit into
Conversation
…t break the build macos-mpy.patch and ubuntu24_mpy.patch are applied by hand into the external/micropython working tree and never committed anywhere, so any `git submodule update`, checkout, or clean of that tree silently reverts them. The next build then fails hundreds of lines into the compile with -Werror diagnostics against py/objfun.c and py/bc.h -- upstream files nobody touched and which are not broken -- and nothing in the output mentions the patch or the README step that came undone. Add an idempotent `mpy-patch` target that reverse-checks before applying, and make `all` and `tools` depend on it, so a build re-applies the patch when it has gone missing and does nothing when it is already there. `setup` inherits it through its existing `$(MAKE) tools`, which keeps the ordering right: its `git submodule update --init` runs first, and the patch is re-asserted afterwards. If neither direction applies -- local edits, or a half-applied patch -- it stops with a clear message rather than guessing. MPY_PATCH is only defaulted on Darwin, so Linux behaviour is unchanged; Ubuntu 24.04 keeps its single documented step, now idempotent, via `make -C unix mpy-patch MPY_PATCH=ubuntu24_mpy.patch`. Follow-up to Coldcard#712. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
scgbckbone
reviewed
Aug 15, 2026
scgbckbone
left a comment
Collaborator
There was a problem hiding this comment.
I want to remove those patch files for long time... what do you think about #731 ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for contributing to COLDCARD source code, please be as descriptive as possible.
By submitting this work you agree to the Individual Contributor License Agreement (CLA)
Summary
macos-mpy.patchandubuntu24_mpy.patchare applied by hand into theexternal/micropythonworking tree and are never committed anywhere. Anything that checks that submodule out drops them
silently — and the next build then fails hundreds of lines into the compile, on
-Werrordiagnostics that point at untouched upstream code in
py/. Nothing in that output mentions thepatch, the submodule, or the README step that was undone.
This PR makes the patch self-asserting.
unix/Makefilegains an idempotentmpy-patchtargetthat
allandtoolsdepend on, so a build re-applies the patch when it has gone missing anddoes nothing when it is already there.
Follow-up to #712, which is where the current clang-21 suppressions in
macos-mpy.patchcamefrom. Nothing here changes firmware behaviour on device: the diff is one make target plus the
README lines that describe it.
stm32/is untouched.Environment where this was reproduced and fixed
The failure
The patch exists only as an uncommitted modification to two files in the submodule:
git submodule update, agit checkoutin that tree,git submodule foreach git checkout ., orre-syncing submodules after a branch change in the parent all revert it without comment. From
there
cd unix && make setupdies like this:12 errors in that one file, from variables declared by
MP_BC_PRELUDE_SIZE_DECODE,MP_BC_PRELUDE_SIG_DECODEandDECODE_CODESTATE_SIZE— macros that deliberately decode everyprelude field while each caller reads only some. That is exactly the benign-by-design class #712
catalogued and suppressed; the suppression just isn't there any more.
What makes this cost real time is that the evidence points the wrong way. The errors name
py/objfun.candpy/bc.h, which are upstream files nobody edited and which are not broken. Thebuild has already emitted a few hundred lines of
CC ...by that point, so the failure looks likeit belongs to the code being compiled rather than to a setup step that silently came undone.
What the fix does
mpy-patchreverse-checks before applying, so it is a no-op when the patch is already in placeand it never double-applies:
allandtoolsnow depend on it.setuppicks it up through its existing$(MAKE) tools,which matters for ordering:
setuprunsgit submodule update --initinsideports/unixfirst,and the patch is re-asserted after that, not before.
Three things worth a look during review:
a half-applied patch — it does not guess. It prints what it could not do and stops with a
non-zero status, instead of proceeding into the confusing compile failure above.
MPY_PATCHis only defaulted forDarwin, so onLinux the target is an empty recipe and nothing is auto-applied. Ubuntu 24.04 users get the same
single manual step they have now, just idempotent, via the documented
make -C unix mpy-patch MPY_PATCH=ubuntu24_mpy.patch. I have no Ubuntu 24.04 host to testauto-application on, and the README notes the patch is only wanted on 24.04, so guessing the
distro from the Makefile seemed worse than leaving it explicit. Adding
MPY_PATCH_Linux = ubuntu24_mpy.patchis the one-line change if you would rather it be automatic.make setupstill re-applies on macOS even if you never invokempy-patchyourself, so anexisting clone that has lost the patch heals on the next build with no new instructions.
The README changes just replace the manual
pushd/git apply/popdblock with the target. ThemacOS ordering is unchanged and still correct: the patch touches
mpy-cross/Makefiletoo, so ithas to land before
make -C external/micropython/mpy-cross.Testing
All on the environment above.
Idempotency — from a clean submodule, three runs in a row:
Fails closed on an unexpected tree — reverted the patch, then deleted the
CWARNline itanchors on:
Self-heal — with everything already built, reverted the patch and ran a plain
make:And the non-Darwin path, where
MPY_PATCHis empty, is a clean no-op rather than an error:Full build from a clean, unpatched submodule, following the README as changed here:
All five steps completed;
error:appears 0 times in the full build log. The resultingcoldcard-mpyis a working arm64 binary, and the vanillaunix/micropythonthatmake setupproduces still runs:
Notes
unix/Makefilehas no.PHONYdeclarations today and I did not add one, to keep the diff tothe change itself. There is no file named
mpy-patch, so the target behaves.make— theifneqaround the recipe and
$(shell uname -s)both work there.testing/was not run as a suite, same reason as macOS fixes pip install and unix simulator build on current toolchains #712:python-secp256k1wants a locallycompiled native
libsecp256k1, which is out of scope here.