Skip to content

fix(py): rebuild the bindings when their version or Rust changes - #1481

Merged
dekobon merged 1 commit into
mainfrom
fix/uv-cache-keys-bindings
Sep 18, 2026
Merged

dekobon merged 1 commit into
mainfrom
fix/uv-cache-keys-bindings

Conversation

@dekobon

@dekobon dekobon commented Sep 18, 2026

Copy link
Copy Markdown
Owner

make worktree-setup runs uv sync, and on a clean main it replaced a
current 2.2.1 install of the Python bindings with a cached 2.1.1 build
.

Cause

The bindings' version is dynamic: maturin reads it from the crate's
Cargo.toml, which inherits it from the workspace root
(version.workspace = true). The extension also compiles the root and ast
crates, one directory up. uv's default cache key watches only
pyproject.toml / setup.* inside the project directory, so neither a
version bump nor a Rust change ever invalidated its cached build.

Fix

[tool.uv].cache-keys in big-code-analysis-py/pyproject.toml now lists
what the build actually reads: the manifests, the root Cargo.lock, and
the Rust sources. It follows the template uv init --build-backend maturin
generates, pointed at this workspace member's parent directory. Setting the
key replaces uv's default, so pyproject.toml is listed again.

The comment beside dynamic = ["version"] pointed at a
[tool.maturin].version key that doesn't exist; it now says where the
version really comes from.

Verified

Check Result
uv sync on main (reproduction) 2.2.1 → 2.1.1
uv sync with the fix rebuilt → 2.2.1
second sync, nothing changed no-op, 0 s — no rebuild on every run
touch ../src/lib.rs rebuilt (Built big-code-analysis, extension mtime advanced)
touch ../big-code-analysis-ast/src/lib.rs rebuilt
same touch with the fix stashed no rebuild — the keys are the cause
uv lock --check unchanged; --locked still holds
make pre-commit BCA_GATE: pass

Impact

Contributor environment only; nothing shipped changes. The effect was
smaller than "stale code": the compiled extension that happened to be in
the source tree was current, and only the installed package metadata
reported 2.1.1. make pre-commit and CI were never affected, because
py-test rebuilds with maturin develop before testing. But a venv synced
by worktree-setup could not be trusted to match the tree, and a Rust-only
change would never have been rebuilt by uv at all.

Not covered: the vendored tree-sitter-* grammar crates. A grammar
regeneration changes C sources those crates compile, which these keys do
not watch; uv sync --reinstall-package big-code-analysis rebuilds when
that matters.

`make worktree-setup` runs `uv sync`, and on a clean `main` it replaced
a current 2.2.1 install of the bindings with a cached 2.1.1 build.

The version is dynamic: maturin reads it from the crate's `Cargo.toml`,
which inherits it from the workspace root. The extension also compiles
the root and ast crates, one directory up. uv's default cache key
watches only `pyproject.toml` and `setup.*`, so neither a version bump
nor a Rust change ever invalidated the cached build.

`[tool.uv].cache-keys` now lists what the build actually reads: the
manifests, the lockfile and the Rust sources, following the template uv
itself generates for a maturin project but pointed at this workspace
member's parent directory. Setting the key replaces the default, so
`pyproject.toml` is listed again.

Verified on this checkout:

- on `main`, `uv sync` downgraded 2.2.1 to 2.1.1; with the fix it
  rebuilds to 2.2.1
- a second sync with nothing changed is a no-op, so the keys do not
  force a rebuild on every run
- touching `../src/lib.rs` or `../big-code-analysis-ast/src/lib.rs`
  rebuilds (`Built big-code-analysis`, extension mtime advances), so the
  parent-directory paths are honoured
- with the fix stashed, the same touch does not rebuild, so the keys
  are what cause it

`uv lock --check` is unaffected. `make pre-commit` never saw the stale
build, because `py-test` runs `maturin develop` before testing.

Also corrects the comment beside `dynamic = ["version"]`, which pointed
at a `[tool.maturin].version` key that does not exist.
@dekobon
dekobon merged commit a4060d7 into main Sep 18, 2026
58 checks passed
@dekobon
dekobon deleted the fix/uv-cache-keys-bindings branch September 18, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant