Update ModuleWriter logic to use ArchiveSource enum#2882
Merged
Conversation
e-nomem
commented
Dec 1, 2025
| #[derive(Debug, Clone)] | ||
| pub(crate) struct GeneratedSourceData { | ||
| pub(crate) data: Vec<u8>, | ||
| pub(crate) path: Option<PathBuf>, |
Contributor
Author
There was a problem hiding this comment.
It feels odd to have a path on a generated source but, without it, the tests for rewriting path dependencies during sdist creation fail because we try to add the Cargo.toml again after rewriting it.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the ModuleWriter trait to use the ArchiveSource enum for a cleaner API design. This is part 1 of 2 PRs that will enable a future VirtualWriter implementation for reproducible builds by sorting files before writing them to archives.
Key changes:
- Splits
ModuleWriterintoModuleWriterInternal(withadd_entry) andModuleWriter(with convenience methods) - Updates
GeneratedSourceDatato include an optionalpathfield for source tracking - Refactors all writer implementations (Wheel, SDist, Path) to handle
ArchiveSourceenum directly instead ofReadtrait
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/module_writer/mod.rs | Refactored trait structure with sealed pattern; added blanket impl for convenience methods |
| src/module_writer/wheel_writer.rs | Updated to implement ModuleWriterInternal with add_entry method handling ArchiveSource |
| src/module_writer/sdist_writer.rs | Updated to implement ModuleWriterInternal with add_entry method handling ArchiveSource |
| src/module_writer/path_writer.rs | Updated to implement ModuleWriterInternal; improved error messages with Debug formatting |
| src/module_writer/mock_writer.rs | New test mock writer implementing the refactored trait |
| src/archive_source.rs | Added path field to GeneratedSourceData and path() helper method |
| src/binding_generator/mod.rs | Simplified to use add_entry directly instead of matching on ArchiveSource |
| src/binding_generator/{uniffi,pyo3,cffi,bin}_binding.rs | Updated GeneratedSourceData construction to include path: None field |
| src/source_distribution.rs | Updated imports to use ModuleWriter trait directly |
| src/build_context.rs | Updated imports to use ModuleWriter instead of ModuleWriterExt |
| tests/common/mod.rs | Removed unused metadata module reference |
d2727f6 to
c2d11e8
Compare
messense
approved these changes
Dec 3, 2025
messense
pushed a commit
that referenced
this pull request
Dec 4, 2025
As I mentioned previously in #2882, this PR adds a `VirtualWriter` that wraps around the existing module writer structs and extracts the common file tracking and exclusion logic. In addition, it tracks all files before writing them at the end allowing us to write the files with a consistent order. After this PR, it should be possible to have mostly reproducible builds. For sdists this requires using the same version of maturin for reproducibility, and for wheels it requires using the same versions of maturin, the rust toolchain, and external libraries.
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.
This PR updates the
ModuleWritertrait to use theArchiveSourceenum that was added to support theBindingGeneratortrait.This is part 1 of 2 PRs, where the second one will add a
VirtualWriterstruct that will wrap aroundWheelWriterandSDistWriter. The virtual writer will store aHashMap<PathBuf, ArchiveSource>internally so, with this update, the virtual writer can eventually just callself.inner.add_entry(target, source).The primary purpose of this virtual writer is to ensure that the files are sorted by path before being written to the underlying archive and ensure that builds are reproducible. As a useful side effect, this will move the file exclusion and duplicate tracking to the virtual writer as well, providing a nice separation of concerns with the virtual writer deciding if a file should be present in the archive and the underlying writer actually doing the writing to the archive.
The intended end result for this set of patches can be viewed on my virtual-writer branch.