Skip to content

Conversation

@e-nomem
Copy link
Contributor

@e-nomem e-nomem commented Nov 28, 2025

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 ArchiveSource enum. That's the first commit in this PR. The second commit actually adds the new generator impl.

@messense messense requested a review from Copilot November 29, 2025 02:38
Copilot finished reviewing on behalf of messense November 29, 2025 02:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ArchiveSource enum with Generated and File variants to handle different source types
  • Replaces the specialized write_uniffi_module function with a new UniFfiBindingGenerator implementing the BindingGenerator trait
  • Updates PyO3 and CFFI generators to use the new ArchiveSource pattern 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

@messense messense merged commit 10277bc into PyO3:main Dec 1, 2025
45 checks passed
@e-nomem e-nomem deleted the uniffi-bindings branch December 1, 2025 02:37
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.

2 participants