Key cffi build-script cache on PYO3_BASE_PYTHON when available#14984
Draft
alex wants to merge 1 commit into
Draft
Key cffi build-script cache on PYO3_BASE_PYTHON when available#14984alex wants to merge 1 commit into
alex wants to merge 1 commit into
Conversation
PEP 517 build isolation creates venvs at random paths and points PYO3_PYTHON at them, so a `rerun-if-env-changed=PYO3_PYTHON` makes the build script re-run on every invocation and defeats caching (see PyO3/pyo3#6113). When PYO3_BASE_PYTHON (the stable underlying interpreter) is present, key the rerun on that instead. A venv cannot change the implementation, version, ABI, or headers of its base interpreter, which is all this script derives -- so the base path is a sound cache key. We still invoke PYO3_PYTHON to locate the binary, since the build venv is where cffi is installed. When PYO3_BASE_PYTHON is absent we fall back to keying on PYO3_PYTHON so manual interpreter switches still trigger a rebuild. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Member
Author
|
(Shouldn't land until we depend on a pyo3 release with this) |
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.
Under PEP 517 build isolation, frontends (pip/uv/build) create venvs at random paths and point
PYO3_PYTHONat them. Becausecryptography-cffi'sbuild.rsdeclarescargo:rerun-if-env-changed=PYO3_PYTHON, that path churn makes the build script re-run on every invocation, defeating build caching. This is the same problem tracked upstream in PyO3/pyo3#6113, which proposes a stablePYO3_BASE_PYTHON(≈sys._base_executable).This change mirrors the proposed "prefer BASE if present" behavior for this crate's build script: when
PYO3_BASE_PYTHONis set, key the rerun on it; otherwise fall back toPYO3_PYTHON.Why keying on the base interpreter is sound here: a venv cannot change the implementation (CPython/PyPy), version, ABI (free-threaded vs. not), or C headers of its base — and those are the only interpreter-derived inputs this script has. We still invoke
PYO3_PYTHONto locate the binary, sincebuild_openssl.pyneeds cffi, which lives in the build venv rather than the base interpreter. The fallback preserves correct rebuild behavior for manual interpreter switches (e.g. settingPYO3_PYTHONin a dev checkout) whenPYO3_BASE_PYTHONis absent.Note: this is forward-looking — it's harmless until a frontend actually sets
PYO3_BASE_PYTHON, at which point caching improves.🤖 Generated with Claude Code