fix(setup): patch python-olm bundled libolm for macOS Apple clang - #31354
fix(setup): patch python-olm bundled libolm for macOS Apple clang#31354ayushere wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a macOS-specific pre-install step to patch and build python-olm from sdist before installing mautrix[encryption], working around an Apple clang compile failure in the bundled libolm headers.
Changes:
- Introduces
_python_olm_macos_install()to download, patch, and installpython-olmon macOS. - Hooks the pre-install into
ensure("platform.matrix")and surfaces failures viaFeatureUnavailable. - Adds logging around the patching/install process.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| with tarfile.open(tarball, "r:gz") as tf: | ||
| tf.extractall(tmpdir) |
| Returns ``None`` when this path is not needed (non-macOS, or python-olm | ||
| already installed). Returns an ``_InstallResult`` otherwise so callers | ||
| can surface failures. | ||
| """ | ||
| if sys.platform != "darwin": | ||
| return None | ||
| if _is_satisfied("python-olm"): | ||
| return None | ||
|
|
||
| import tarfile | ||
| import tempfile | ||
| import urllib.request | ||
|
|
||
| # Pin matches what mautrix[encryption]==0.21.0 resolves to. | ||
| OLM_VERSION = "3.2.16" |
| f"macOS pre-install of python-olm failed: {snippet or 'no output'}. " | ||
| "Try: brew install libolm, then re-run.", |
| patched = src.replace( | ||
| "T * const other_pos = other._data", | ||
| "T * other_pos = other._data", | ||
| ) | ||
| if patched != src: | ||
| with open(list_hh, "w") as fh: | ||
| fh.write(patched) | ||
| logger.debug("macOS: patched libolm list.hh const-pointer bug") | ||
| else: | ||
| logger.warning( | ||
| "macOS: python-olm patch target not found in list.hh — " | ||
| "upstream may have fixed the bug; proceeding without patch" |
5fcd3ba to
9424a64
Compare
|
Re: This test failure is pre-existing and unrelated to this PR. It fails on Copilot comments addressed:
|
On macOS, `mautrix[encryption]` pulls in python-olm 3.2.16, which
bundles libolm source containing a C++ const-pointer bug in
`libolm/include/olm/list.hh`:
T * const other_pos = other._data;
// ...
++other_pos; // error: cannot assign to const-qualified variable
Apple clang (Xcode 15+) rejects this as a hard compile error even
without -Werror, so `platform.matrix` lazy-install always fails on
macOS with:
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
Fix: when `ensure("platform.matrix")` runs on darwin, pre-install
python-olm from a patched copy of the sdist (one-line removal of the
spurious `const` qualifier) before the main pip install runs.
mautrix[encryption] then finds python-olm already satisfied and skips
the broken bundled-source build.
The patch is idempotent — if the target line is absent (upstream fixed
it), we log a warning and proceed without patching.
Relates to: NousResearch#27795 (adds libolm-dev for Docker, same root cause)
Relates to: NousResearch#14139 (replaces python-olm with fresholm long-term)
9424a64 to
bd40847
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for isolating the python-olm compiler failure and for adding extraction-path validation.
Problems
- Current documentation intentionally directs macOS E2EE through Linux proxy mode (
website/docs/user-guide/messaging/matrix.md:744-765). A native macOS path needs a maintainer decision and matching support/docs update before it can be adopted. - The new subprocess at
tools/lazy_deps.py:428bypasses current lazy-install behavior: durable-target routing and constraints (tools/lazy_deps.py:640-655) plus the credential-scrubbed installer environment (tools/lazy_deps.py:657-670). This can fail on immutable-image deployments and diverges from the established security boundary. - The PR changes no tests; existing Matrix lazy-dependency tests cover Windows only (
tests/tools/test_lazy_deps.py:335-377). The linked #39816 also documents a CMake 4 failure that this separate subprocess would not inherit from a helper-level fix.
Suggested changes
- Confirm the native-macOS support direction, then route any patched-source build through the shared installer and add hermetic darwin regression coverage.
Automated hermes-sweeper review.
|
|
||
| src_dir = os.path.join(tmpdir, f"python-olm-{OLM_VERSION}") | ||
| pip_cmd = [sys.executable, "-m", "pip"] | ||
| r = subprocess.run( |
There was a problem hiding this comment.
This bypasses the lazy installer’s current durable-target/constraint path and its credential-scrubbed subprocess environment (tools/lazy_deps.py:640-670 on main). Please route the patched-source build through the shared install mechanism (or extend it with a source-build input) so immutable deployments and the established subprocess boundary continue to work.
Problem
On macOS with Apple clang (Xcode 15+),
ensure("platform.matrix")always fails during themautrix[encryption]install:mautrix[encryption]pulls inpython-olm 3.2.16, which bundles its own libolm source. That source has a C++ bug inlibolm/include/olm/list.hh— a local pointer variable is declaredT * const other_posthen immediately incremented (++other_pos). Incrementing a const pointer is a hard compile error, not a warning, so-Wno-errorcannot suppress it.The same root cause was addressed for Docker in #27795 (
apt-get install libolm-dev), but macOS users hit it every time Matrix E2EE lazy-install runs.Fix
When
ensure("platform.matrix")runs ondarwin, pre-installpython-olmfrom a patched copy of the PyPI sdist before the main pip install. The patch is a single-line removal of the spuriousconstqualifier:Once
python-olmis installed,mautrix[encryption]'s dep-resolution sees it satisfied and pip skips the bundled-source build entirely — no double build, no churn on subsequent runs.The patch function is idempotent: if the target line is absent (upstream fixed the bug), it logs a warning and continues without patching.
Related
libolm-dev)python-olmwithfresholmasyncpg/aiosqlitein Matrix E2EEType of Change
Changes Made
tools/lazy_deps.py— added_python_olm_macos_install()that downloads the sdist, patcheslist.hh, and installs viapip --no-build-isolation; hooked intoensure()forplatform.matrixon darwin.Test