Fix hnswlib SIGILL in stubtest by building without -march=native - #16244
Open
ekanshul wants to merge 1 commit into
Open
Fix hnswlib SIGILL in stubtest by building without -march=native#16244ekanshul wants to merge 1 commit into
-march=native#16244ekanshul wants to merge 1 commit into
Conversation
hnswlib is source-only and compiles with -march=native by default. CI restores pip's wheel cache across runners with different CPUs, so a wheel built on one host can hit an illegal instruction on the next. That is the SIGILL (exit -4) with empty output from python#16100. Add a general `install-environment` key to [tool.stubtest] that sets environment variables for the pip install step, and use it to pass hnswlib's own HNSWLIB_NO_NATIVE opt-out. This lets the darwin-only workaround from python#16125 be dropped so hnswlib is tested on Linux again. Fixes python#16100 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
JelleZijlstra
approved these changes
Aug 19, 2026
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.
Fixes #16100. Reverts the darwin-only workaround from #16125 so hnswlib is tested on Linux again.
What was happening
hnswlib is source-only and its
setup.pyadds-march=nativeon unix. CI restores pip's wheel cache across runners, keyed only onrequirements-tests.txtandstubs/**/METADATA.toml. So a wheel compiled on oneubuntu-latesthost gets restored onto another with a different CPU, and the first unsupported vector instruction is a SIGILL. That accounts for every symptom in the issue: exit-4, empty output (it dies on import before stubtest prints anything), passing locally (you build and run on one machine), and passing on darwin (uniform hardware).I did not want to rest this on the build flags alone, so I pulled the logs for the three consecutive daily runs around the first failure. Same runner image (
ubuntu-24.04 20260720.247.2) on all three, so the only variable is the physical host:A clean source build of hnswlib takes about 25 s (I timed 25 s locally on Apple Silicon too), so 07-27 compiled fresh. 5.82 s and 8.89 s are far too fast for a compile: both runs used a cached wheel built on some earlier host. On 07-28 that host's instruction set did not match; on 07-29 it did. Same cached artifact, different CPU, different result.
The fix
hnswlib provides an
HNSWLIB_NO_NATIVEopt-out insetup.py.stubtest_third_party.pyranpip installwithout anenv=, and there was no per-distribution way to set one, so this adds a general[tool.stubtest] install-environmentkey (a table of environment variables applied to the pip install step), documents it in CONTRIBUTING.md, and uses it for hnswlib. I made it general rather than special-casing hnswlib since any source-only package with CPU-specific flags has the same exposure.Because
stubs/**/METADATA.tomlis in the cache key, changing hnswlib's METADATA.toml also rotates the cache, so no stale native wheel can be restored after this merges.Verification
pip -vwith and without the variable: without it,-march=nativeappears in the actualc++compile commands; with it, the flag is gone.tests/stubtest_third_party.py hnswlibend to end through the patched code:hnswlib... (44.51 s) success, a full source build.subprocess.runto confirm the env actually reaches pip:HNSWLIB_NO_NATIVE=1is present for hnswlib and absent for an unrelated distribution (six).read_stubtest_settings("hnswlib")parses to{"HNSWLIB_NO_NATIVE": "1"}andci_platformsfalls back to the default["linux"].check_typeshed_structure.py,typecheck_typeshed.py(mypy--strictontests/andscripts/, linux 3.13), black, flake8, and ruff check all pass.