mip: Support optional per-entry native code compatibility tags. - #1144
Open
o-murphy wants to merge 1 commit into
Open
mip: Support optional per-entry native code compatibility tags.#1144o-murphy wants to merge 1 commit into
o-murphy wants to merge 1 commit into
Conversation
o-murphy
force-pushed
the
feat/mip-natmod-support
branch
4 times, most recently
from
July 28, 2026 08:01
58e0a34 to
fcddea1
Compare
o-murphy
force-pushed
the
feat/mip-natmod-support
branch
from
July 28, 2026 08:08
fcddea1 to
5381e44
Compare
o-murphy
marked this pull request as ready for review
July 28, 2026 08:13
o-murphy
force-pushed
the
feat/mip-natmod-support
branch
from
July 28, 2026 08:22
5381e44 to
b11c452
Compare
Related to micropython#1140 / micropython#19478 / micropython#19479: those add URL-templating for single-file natmod installs, but don't help when a single manifest needs to serve different files per architecture. Adds an optional third element to hashes/urls entries: a raw sys.implementation._mpy-shaped integer. Entries without it install unconditionally (backward compatible); entries with it only install if _mpy_tag_ok() matches - exact match on version/sub-version/arch, subset match on arch-flags (a variant that doesn't require an extension must still install on hardware that supports it). Signed-off-by: o-murphy <thehelixpg@gmail.com>
o-murphy
force-pushed
the
feat/mip-natmod-support
branch
from
July 28, 2026 11:27
b11c452 to
815d15e
Compare
Author
|
Follow UP |
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.
Summary
Related to #1140 / #19478 / #19479 / #19532: those add
{MPY_ARCH}/{MPY_VERSION}URL-templating for single-file natmod installs, but don’t help when a package’spackage.jsonneeds to serve different files per architecture from one manifest (e.g. a natmod.mpyalongside a pure-Python wrapper, or multiple prebuilt arch variants of the same natmod).This adds an optional third element to entries in
hashes/urls: a rawsys.implementation._mpy-shaped integer. If present, the entry is only installed when it matches the running device; entries without it install unconditionally (fully backward compatible - see Testing).Match semantics (
_mpy_tag_ok): bits 0-15 (version/sub-version/arch) must match exactly; bits 16+ (optional arch-flags, e.g. RV32Zba/Zcmpextensions) are treated as required ⊆ available, not equality - a variant that doesn’t need an extension must still install on hardware that happens to support it. This addresses the concern raised at micropython/micropython#19479 (comment) that naive exact-int-equality doesn’t work for arch flags.{ "urls": [ ["mymodule.py", "mymodule.py"], ["mymodule.mpy", "mymodule_mpy5.mpy", 5], ["mymodule.mpy", "mymodule_mpy6.mpy", 6], ["mymodule.mpy", "https://.../armv7m_6.3.mpy", 1543], ["mymodule.mpy", "https://.../rv32imc_6.3.mpy", 2822] ] }No schema version bump needed - this is length-checked (
len(entry) > 2), not a new required field, so every manifest published today keeps working unchanged on both old and newmip.Testing
_mpy_tag_okstandalone (base exact-match, flags-subset in both directions, differing-base rejection,None/absent-_mpyhandling) - not yet run against real hardware or the unix port end-to-end viamip.install().package.jsonfetched and installed on a real board. I’d want to verify this on at least unix port + one arch (e.g. rp2/armv6m or esp32/xtensawin) before this is mergeable - will follow up with results, or happy to have a reviewer with hardware on hand try it against a throwaway manifest.Trade-offs and Alternatives
arch/mpy_versionstring fields (more human-readable manifest, but requires keeping an arch-name table in sync withmpyfiles.rston both publisher andmipsides) vs. this raw-int approach (opaque in the manifest, but the check is ~4 lines and has nothing to keep in sync - the value is whatever the device already reports).mpremoteinstead (per @agatti’s suggestion in that thread) was also considered - that helps the “publish once” case but doesn’t cover packages resolved through the on-devicemip.install()API directly (nompremote/PC in the loop at all), which this does.hashes/urlsloops change from fixed tuple-unpacking to indexed access (needed regardless of encoding, to support any optional trailing field without breaking 2-element entries).Generative AI
I used generative AI tools when creating this PR, but a human has checked the
code and is responsible for the code and the description above.