Migrate uniffi bindings to new BindingGenerator trait#2878
Merged
Migrate uniffi bindings to new BindingGenerator trait#2878
BindingGenerator trait#2878Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR successfully migrates UniFFI bindings to use the new BindingGenerator trait pattern, improving code consistency and maintainability across all binding types (PyO3, CFFI, UniFFI, WASM). The migration introduces an ArchiveSource enum to elegantly handle both in-memory generated content and file-based sources, which is particularly important for UniFFI that generates multiple Python binding files on the filesystem.
Key changes:
- Introduces
ArchiveSourceenum withGeneratedandFilevariants to handle different source types - Replaces the specialized
write_uniffi_modulefunction with a newUniFfiBindingGeneratorimplementing theBindingGeneratortrait - Updates PyO3 and CFFI generators to use the new
ArchiveSourcepattern for consistency
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/archive_source.rs | New module defining ArchiveSource enum and associated data structures for handling both generated and file-based archive content |
| src/lib.rs | Adds the new archive_source module to the crate |
| src/binding_generator/mod.rs | Updates generate_binding to handle ArchiveSource enum in both editable and non-editable installation paths, replacing direct byte array usage |
| src/binding_generator/uniffi_binding.rs | Replaces the old write_uniffi_module function with UniFfiBindingGenerator struct implementing the BindingGenerator trait, removes unused imports |
| src/binding_generator/pyo3_binding.rs | Updates to use ArchiveSource::Generated wrapper for consistency with the new pattern |
| src/binding_generator/cffi_binding.rs | Updates to use ArchiveSource::Generated wrapper for consistency with the new pattern |
| src/build_context.rs | Migrates from calling write_uniffi_module to using generate_binding with UniFfiBindingGenerator, removes the old function from imports |
df20aa3 to
a41c516
Compare
a41c516 to
f8e5f0b
Compare
messense
approved these changes
Dec 1, 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.
Unlike the other binding modes, uniffi actually generates files on the filesystem that need to be included in the archive, not just in-memory strings. I didn't want to read all those files into memory so my solution was to add an
ArchiveSourceenum. That's the first commit in this PR. The second commit actually adds the new generator impl.