Clean up BindingGenerator interface#2881
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the BindingGenerator trait interface to remove temp_dir and interpreter parameters from the trait method signature. These dependencies are now managed within the generator structs themselves, improving encapsulation and simplifying the trait interface. The changes also introduce a BindingType enum for PyO3 to enable early validation of interpreter requirements.
Key Changes
- Removed
temp_dirandinterpreterparameters from theBindingGenerator::generate_bindings()trait method - Added lifetime parameters to
Pyo3BindingGeneratorandCffiBindingGeneratorto store interpreter references - Introduced
BindingTypeenum in PyO3 generator to distinguish between abi3 and non-abi3 builds with early error checking - Updated all generator constructors to accept and validate their required dependencies upfront
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/binding_generator/mod.rs | Removed temp_dir and interpreter parameters from the BindingGenerator trait and generate_binding function signature |
| src/binding_generator/pyo3_binding.rs | Added lifetime parameter, introduced BindingType enum, moved tempdir into struct, added early interpreter validation in constructor |
| src/binding_generator/cffi_binding.rs | Added lifetime parameter, moved interpreter and tempdir into struct, updated constructor to require interpreter, removed redundant tempdir.close() call |
| src/binding_generator/uniffi_binding.rs | Removed unused temp_dir and interpreter parameters from generate_bindings method |
| src/binding_generator/bin_binding.rs | Removed unused temp_dir and interpreter parameters from generate_bindings method |
| src/build_context.rs | Updated all binding generator instantiations to use new constructors with proper error handling, simplified generate_binding calls |
4c481b9 to
7383e59
Compare
7383e59 to
d9117b1
Compare
messense
approved these changes
Dec 3, 2025
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.
The last PR about the
BindingGeneratortrait! (at least for now 😅 )Now that all the bindings have been migrated, it seems fairly clear that the temp dir and python interpreter only matter for some bindings and shouldn't be a part of the trait interface itself. This PR hoists those parameters into the generator struct if necessary and adjusts the code to match.
It also creates a
BindingTypeenum for PyO3 so that we can error out early if the python interpreter is required but missing, rather than panicking later on.