Strip excluded cargo targets in sdist - #2964
Merged
Merged
Conversation
messense
force-pushed
the
sdist-targets-excludes
branch
from
February 5, 2026 12:14
f913f49 to
c8927be
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #2955 where maturin fails to strip excluded cargo build targets from source distributions, causing build failures. Since Cargo 1.80, Cargo consistently strips excluded build targets, but maturin was not doing this, resulting in Cargo.toml files referencing source files that don't exist in the sdist.
Changes:
- Implements automatic stripping of cargo targets (lib, bin, example, test, bench) whose source files are excluded from the sdist
- Adds comprehensive test coverage for the new functionality with both included and excluded examples and benchmarks
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/source_distribution.rs | Adds rewrite_cargo_toml_targets function to strip targets with excluded source files; integrates this into sdist generation workflow |
| src/module_writer/virtual_writer.rs | Changes visibility of exclude method to pub(crate) to support exclusion checks during file filtering |
| tests/run.rs | Updates test expectations to verify that excluded targets are stripped from Cargo.toml while included targets are retained |
| test-crates/hello-world/Cargo.toml | Adds test bench and example target declarations for testing the stripping functionality |
| test-crates/hello-world/pyproject.toml | Configures maturin to exclude specific bench and example files |
| test-crates/hello-world/benches/*.rs | Adds test benchmark files (both included and excluded variants) |
| test-crates/hello-world/examples/*.rs | Adds test example files (both included and excluded variants) |
| test-crates/pyo3-mixed-workspace/.gitignore | Adds standard Rust target/ directory to gitignore |
| test-crates/pyo3-mixed-src/.gitignore | Adds standard Rust target/ directory to gitignore |
messense
force-pushed
the
sdist-targets-excludes
branch
from
February 5, 2026 12:32
c8927be to
56a745a
Compare
messense
force-pushed
the
sdist-targets-excludes
branch
from
February 5, 2026 23:55
9b0f2c3 to
34ab8d6
Compare
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.
Closes #2955