Skip to content

feat: type the bindings input with a single-source-of-truth enum#3273

Merged
messense merged 1 commit into
PyO3:mainfrom
messense:refactor/a4-typed-bindings
Jul 22, 2026
Merged

feat: type the bindings input with a single-source-of-truth enum#3273
messense merged 1 commit into
PyO3:mainfrom
messense:refactor/a4-typed-bindings

Conversation

@messense

Copy link
Copy Markdown
Member

Replace the raw Option<String> bindings input on the CLI (--bindings), maturin develop, and [tool.maturin] bindings with a dedicated Bindings enum (pyo3, pyo3-ffi, cffi, uniffi, bin). Every accepted spelling lives in one place (Bindings::as_str); FromStr, Display, serde, clap ValueEnum and schemars all delegate to it, so the accepted spellings can never drift apart.

find_bridge/find_bridge_with_deps now take Option<Bindings> and convert to BridgeModel at the point the string used to be consumed. BridgeModel is deliberately not reused as the input type: auto-detection and resolved PyO3 metadata are semantic states, not input spellings.

Behavior is backward compatible: the serialized values and CLI possible-values diagnostic are byte-identical to before, and TOML now rejects unknown values with serde's variant-naming error instead of the old downstream "unknown binding type". Auto-detection (bindings omitted) is unchanged.

Regenerated maturin.schema.json: ToolMaturin.bindings becomes a $ref to a new Bindings string-enum def, documented in the house style (a oneOf of per-variant const values, each with a one-line description).

Replace the raw `Option<String>` bindings input on the CLI (`--bindings`),
`maturin develop`, and `[tool.maturin] bindings` with a dedicated `Bindings`
enum (pyo3, pyo3-ffi, cffi, uniffi, bin). Every accepted spelling lives in one
place (`Bindings::as_str`); `FromStr`, `Display`, serde, clap `ValueEnum` and
schemars all delegate to it, so the accepted spellings can never drift apart.

`find_bridge`/`find_bridge_with_deps` now take `Option<Bindings>` and convert
to `BridgeModel` at the point the string used to be consumed. `BridgeModel` is
deliberately not reused as the input type: auto-detection and resolved PyO3
metadata are semantic states, not input spellings.

Behavior is backward compatible: the serialized values and CLI possible-values
diagnostic are byte-identical to before, and TOML now rejects unknown values
with serde's variant-naming error instead of the old downstream
"unknown binding type". Auto-detection (bindings omitted) is unchanged.

Regenerated maturin.schema.json: ToolMaturin.bindings becomes a `$ref` to a new
`Bindings` string-enum def, documented in the house style (a `oneOf` of
per-variant `const` values, each with a one-line description).
@messense
messense force-pushed the refactor/a4-typed-bindings branch from 563fbff to 7d6cabc Compare July 22, 2026 10:56
@messense
messense merged commit 8410a9b into PyO3:main Jul 22, 2026
45 checks passed
@messense
messense deleted the refactor/a4-typed-bindings branch July 22, 2026 12:55
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